Arduino Steering Wheel for Unity

by Sieminator in Circuits > Arduino

405 Views, 1 Favorites, 0 Comments

Arduino Steering Wheel for Unity

WhatsApp Image 2023-08-05 at 22.39.54 (1).jpeg

I used a arduino to create a steering wheel and a simple racing game to play with it. The game begins with a startsignal from the buzzer. It was made by sending data from the arduino to unity. The main reason to do this was to get to know arduino and unity better, as it was a school project.

I connected a wii steering wheel to a potentialmeter. the potmeter reads the value and is connected to an arduino, which prints it in the serial monitor. A unity script reads this value and uses it to control the car ingame.


Supplies

1x Arduino uno or nano

1x PCB

1x breadbord

1x buzzer

1x potentialmeter

1x 330 Ohm resistor

about 5 arduino wires

a large plank and some woodworking materials (eg a saw, hammer and nails)

some 3D printed parts listed in the file library

a steering wheel (preferably this one: https://www.wiigamesinfo.nl/wii-accessoires/nintendo-wii-wheel-stuur/)

Set Up Your Unity Game

documentatie.png
documentatie 4.png
documentatie 5.png

To actually use the steering wheel I set up a very rudimentary unity project. You can make something yourself or simply use my unity scripts that reads the serial monitor from Arduino. The scripts include comments to explain what the code does and how it works. I recommend using unity 2022.3 as older version came with a lot of trouble setting up the connection.

after installing the version of unity, you'll want to change some settings. Open unity and navigate to edit>project settings>player>configuration. There, change your API compatibility level to .NET framework.

Set Up Your Arduino Connection

WhatsApp Image 2023-08-05 at 22.39.39.jpeg
WhatsApp Image 2023-08-05 at 22.39.52.jpeg
WhatsApp Image 2023-08-05 at 22.39.39 (1).jpeg
WhatsApp Image 2023-08-05 at 22.39.54.jpeg
documentatie 2.png
documentatie 3.png
documentatie zoveel.png

Your arduino will sent a value of -100 to 100 to unity, but first you'll need to set up your arduino. In this steps supporting files I placed a picture with the code you'll want to use: https://support.arduino.cc/hc/en-us/articles/360014869820-Install-the-Arduino-Create-Agent. Once you installed the agent simply copy the code to it. Again, the code has comments explaining what it does.

that is your code complete code. For the hardware, install the potmeter to an 5v outlet, a ground, and te A0 pin to read. Then install the buzzer by connecting it to pin 8 and a ground. place a 330 Ohm resistor in its loop. See the images for clarification.

test this on a breadboard first, as it might not work first time. Troubleshooting in this part will be the biggest challenge, and will be a little different for everyone. First, check in your serial monitor if the potentiometer is giving the correct output (a value from -100 to 100). If you still have trouble after that there are some things you should check in each case:

different potentialmeters might return different kind of scales. Usually it is a value between 0 and 1023, like with me but you might have to change the map function in the Arduino code. Also, the potmeter can return a logarithmic scale instead of a linear one. I dealt with this problem by mapping the values manually. This manual map can still be found commented out in the unity script "movement". I recommend using a different potmeter or some different wires/resistors that return a linear scale. If that doesn't work you can use the manual made map or make your own, more detailed one.

the unity script "data reading" checks for a serial monitor available. Make sure its name is correct. for me it was "COM 5", but it might be different (COM 7 is common, or something completely different if you use an off brand Arduino). Check your arduinos' name in the create agent, as is shown on one of the images.

secondly, make sure the serial monitor tab is closed in the Arduino agent. unity will not be acces it otherwise. I do not know why this is and it makes it a little bit harder to troubleshoot, and took me quite a while to find out.

If you still have trouble with this step, I suggest looking at the tutorial I used: https://www.youtube.com/watch?v=5ElKFY3N1zs (there is a part two), or try to google the error yourself.

Create Your Casing

WhatsApp Image 2023-08-05 at 22.39.53.jpeg
WhatsApp Image 2023-08-05 at 22.39.39 (1).jpeg
WhatsApp Image 2023-08-05 at 22.39.54.jpeg
WhatsApp Image 2023-08-05 at 22.39.38.jpeg
WhatsApp Image 2023-08-05 at 22.39.53.jpeg

Next, make a case for your hardware. I used a single plank that I cut in multiple places, and nailed together. The shape can be different, but the slope provides the most comfort for using the steering wheel. then, make a hole for the axis that is 16mm in diameter. Pro tip: draw a cross on the front to determine the centre easily. You'll also want to drill a small hole for the cable of the Arduino to go trough. I used some yellow tape to make it look a bit better, but you can customize it any way you want.

also, 3D print the files:

potmeter holder: https://cad.onshape.com/documents/b1382197cd7785ee017d9681/w/082fb1e8fcef0a75c324d0ce/e/7aab5463e5a37f5bf9f7c3a9?renderMode=0&uiState=64cf0160e1f3777999ebd43e.

steering wheel connector:

https://cad.onshape.com/documents/ac07a17360e6d09b72726a8e/w/810e45ef00982bd2ca2e73ef/e/0af01a81d1c43f70b17425c8?renderMode=0&uiState=64cffa6352851678939a4207

an old draft of the steering wheel connector:

https://cad.onshape.com/documents/ce5241cb1d9f9f5fa3652977/w/3d2fd093d967adf12873a4a7/e/963ea7366cf2f92505d80171?renderMode=0&uiState=64cffadfae83a9223e173132

because of problems with the return values with the potmeter, I also made a quick draft of a rotary encoder, but it didn't end up being used. Here are the files anyway:

https://cad.onshape.com/documents/3f979a4d93519b3e37287bf6/w/61347c2f2d096c8a0dc2ec03/e/7bbdace9cb2bd8994e0c0e66?renderMode=0&uiState=64cffbfeae83a9223e1732b1

If you're using a different steering wheel then me, you'll need to connect it to the potmeter in another way, otherwise, you can easily click your wheel on or off the 3d print.

Place the Hardware

WhatsApp Image 2023-08-06 at 03.37.00.jpeg
WhatsApp Image 2023-08-06 at 03.37.01 (1).jpeg
WhatsApp Image 2023-08-06 at 03.37.01.jpeg
ittt herkansing foto 1.jpg
ittt herkansing foto 2.jpg

Then it is time to finalize your setup. Solder your wires and screw or glue your components in place. Solder your buzzer on a small PCB and glue it in place. Also, make sure there is enough space for the 3D print holder of the potmeter. I had to rotate it because I accidently didn't leave enough space for it.

Click the potentialmeter carefully into the 3D print holder, solder it and screw the 3d print to the case. watch the photo's for a reference. Once it is in place, you should calibrate it. Open the serial monitor in Arduino agent and plug your Arduino in. I recommend using a flat screwdriver to easily turn the potmeter. Make sure the value in the serial monitor is zero and then click on the 3D print with the steering wheel.

Now your steering wheel is complete and should work.

Play

First make sure your serial monitor is closed. Also, if you save your Arduino sketch and upload it to your Arduino you can close the Arduino agent. Before plugging it in, run you unity project first. To avoid latency, make sure your device is being charged while running unity, and if you run your unity project or Arduino code too long, it might get slower.

Now try to complete a lap!

Continue

documentatie zoveeledrfgtt.png

I had some more plans involving the project that didn't end up in the final result. I mainly wanted a stable bi-directional connection between unity and arduino. Like that I would have been able to make the buzzer go off while going trough the grass or something. I tried to set it up but it would not work for some reason. I included the script I tried to use.

Also, over time the connection might get worse, and generally isn't very stable and prone to latency. It got better after adding some optimisation code but still could use some more.

The unity game is very simple, but I'm convinced you could make a quite cool 3D racing game with this wheel.

So there is a lot extra to do but it is done for now. I learned how to communicate with different programs using serial monitors ports, and also got to work with some more hardware instead of my usual software based projects. Especially 3D modeling and printing is a lot of fun and a very useful skill to have.

I might continue with this project later, but for now I'm happy how this turned out!