Introduction: Sim Racing Button Box

A button box is a device used in Sim Racing that allows you to assign buttons, switches, and knobs to various car controls. Common button assignments are things like a start button, PTT, request pit, etc. Toggle switches work great for wipers, headlights, etc. Knobs can be used to adjust TC (Traction Control), Brake bias, and more.

Step 1: Step 1: Gather the Requirements

Arduino Pro Micro - You can get an official board; I've also had luck with the knock off versions.

ABS Project box - make sure it is deep enough to support the buttons and switches you choose.

Momentary Buttons - Buttons with a round mounting hole are easiest to work with. Look for buttons that have the color and size of your liking. Buttons should have n.o. (Normally Open) contacts. Note that this instructable doesn't address how to use lighted buttons.

Toggle Switches - You can choose between momentary and latching. Other choices are ST (Single Throw) or DT (Double Throw). Single throw means 2 postions, on/off, Double throw is 3 postion on/off/on. Don't worry about Single Pole (SP) or Double Pole (DP) types, both will work. If you end up with Double Throw switches you can just ignore the second set of terminals. These switches are often referred to with their features combined i.e. SPDT, DPDT, etc.

Rotary Encoders - Encoders allow us to control features that support increase and decrease adjustments. e.g. Traction Control. Some rotary controllers also have a built in momentary button by pressing down the encoder shaft.

Knobs - Knobs to fit the encoder shafts.

USB Micro to USB-A cable - This will be used to upload the arduino code to the board as well as to connect your Button Box to your PC.

Wire - I prefer teflon coated 24ga. solid wire.

Solder and Soldering Iron - A low watt iron with a small tip will work best. Connections will melt and fail if over-heated so an adjustable temperature or low wattage iron is better.

Drill and Drill bits - To make holes for your switches, buttons, etc. A small pilot bit and a step bit make a great combination. Access to Drill Press will make alignment errors less likely.

Optional: Vinyl wrap to add a carbon fiber or aluminum look to your button box.

Step 2: Step 2: Layout the Buttons, Switches, and Encoders

Buttons will be mounted on the lid of your project box. Double check that your button box is deep enough for your buttons.

I find it helpful to physically place the switches, buttons, and knobs on the lid to get feel for spacing and aesthetics.

Try to line everything up in a grid with even spacing between each component.

Be sure to leave enough space at the end of the rows, the switches and buttons have a base and need enough room to mount properly.

If you are wrapping the face in vinyl for a carbon or aluminum look, you can draw lines right on the face of the box with a pencil, they will be covered up later with the wrap.

Otherwise, draw lines on the underside of the lid, you want to have lines crossing at the center of each button/switch you will be installing.

Step 3: Step 3: Drill and Mount the Buttons, Switches and Encoders

Use a small drill bit (also known as a pilot bit) to start the hole for each component. The small bit allows you to be very precise and ensure everything is centered.

Tip: If you have access to a drill press, this step will be easier and quicker. If not, don't worry just take your time.

After the pilot holes have been made, switch to a step bit or the correct bit for the shaft of each component to be installed.

Tip: Be careful when using a step bit to not go too far. I like to use a sharpie and color the step of the bit I need to stop on.

This is also a good time to drill a hole in the back of the enclosure for the usb cable that will run between the Arduino and your PC. The hole will need to be large enough to get the usb micro end of the cable through. You can use a rubber grommet to trim the hole and a wire tie on the inside as a strain relief to prevent the cable from being pulled out.

If you will be vinyl wrapping your box lid, now is the time to do it.

Step 4: Step 4: Layout Your Matrix

The Arduino controller has a limited number of inputs and ouputs it can use to sense when buttons are pressed, switches change, etc. To accommodate a larger number of switches and buttons we will use a technique called a matrix.

A matrix works by using the intersection of an output and an input as the "address" of a switch or button.

Arduino outputs are assigned as columns and inputs as rows in the matrix and each button and switch position is assigned an address. It's easiest to use a spreadsheet program to do your layout, but paper will work too.

Using Arduino's A0,A1,A2, and A3 as "columns" in the matrix and 6,7,8,9,10 & 16 as "rows" we can accept up to 28 inputs (button presses, toggles positions, etc)!

To ease layout, each pin on your button switch or rotary will need a label to refer to it.

I've chosen "PBn" to represent a push button, "TGn" to represent a toggle, and "REn" for rotary encoders. The "n" in the name is replaced with a number to reference that specific component in the matrix.

Tip: It's helpful to write the name of each component on the underside of the lid next to it's location, e.g. PB1 , PB2, RE1, etc

In the matrix I refer to the pins as I view them visually mounted on the lid viewed from the underside of the lid. So for example a push button will have 2 terminals I refer to them as "H" (high) and "L" (low) , you can also use top and bottom, or whatever you like as long as you can easily remember your scheme.

For toggles I use high, center and low. as my toggles are DPDT. My rotary encoders also had push buttons so I have REn-PB high and low as well.

Each button or switch "input" will map to a column in your matrix. You can have multiple switch/button inputs on the same column, just not more than the number of rows you have.

Important! All toggle switch outputs must be mapped to the column of its' input. This is because you will be wiring the center of the toggle to say A0, then the output of the switch (high or low terminal) will go to a row pin e.g. 7 or 8.

Arduino Outputs (switch/button inputs) A0A1A2 TG1-HPB1-HPB2-H TG2-CTG4-CPB5-H TG3-CPB3-HPB6-H RE1-PB-HPB4-HPB7-H RE2-PB-HPB8-H RE3-PB-H Arduino Inputs (switch/button outputs)   6TG1-LPB1-LPB2-L 7TG2-HTG4-LPB5-L 8RE1-PB-LRE2-PB-LPB6-L 9TG3-HPB3-LPB7-L 10TG3-LPB4-LRE3-PB-L 16TG2-LTG4-HPB8-L

Step 5: Step 5: Wire the Matrix

Starting with the Arduino Outputs (switch & button inputs) link each electrical component in a matrix column and leave a short length of wire to connect to the Arduino output. I chose to use my teflon wire to link everything together and a colored piece of wire to go to the arduino as it makes it easier to find and trace later on.

After all the column component connections are complete, do the same for each row. Link all the components in the same row together taking care to ensure you are connecting the correct terminal i.e. high or low and leave length of wire to connect to the Arduino later.

Take your time and double check that you are connecting the correct terminal. This is where the component reference scribed on the panel next to the component and your easy to remember scheme for the terminal positions will pay off.

Step 6: Step 6: Wire the Encoders and the Arduino

Rotary encoders cannot be wired into a matrix. The input to each encoder (center pin) will be tied to Arduino ground and the encoder outputs will go directly to an Arduino input.

Link each encoder center pin together and leave a lead to connect to Arduino ground.

Solder the rotary encoder centers to Arduino ground and each rotary encoder "H" "L" to the corresponding Arduino pin.

Solder each each length of wire from the column and row matrix to the corresponding Arduino input or output.

Step 7: Step 7: Prepare the Sketch

Using the free Arduino IDE prepare the sketch (code) for the Arduino.

Upload the sketch to the Arduino

After the sketch loads, Connect your button box to your PC, a joystick device should appear.

Congratulations! You just built a button box!