I spend more time planning my box than drilling, soldering and coding the firmware. Planning is important for many reasons, such as:
- Feasibility: Arduino has a limited amount of available pins (it can be expanded but let’s keep it simple here) so we have to decided what our box will do and how many controls it will have.
- Ergonomics: sounds trivial but placing two encoders 1mm from each other will make them very hard to use.
- Dimensions and sizes: the internal area of a box is not always rectangular, screws usually rest in dedicated bases; the walls of the box can be quite thick; the size of the base of buttons and switches (the part you interact with is the top of the iceberg, often the part not seen is much bigger that the switch lever/button itself) must be taken into account.
This is my very first sketch of something that later became something very, very different. I redrew it at least a dozen times:
As mentioned before, in this guide we will build a simple box, sporting momentary buttons and encoders hence we need none of the peculiar capabilities of the analog pins. Therefore, from this perspective, Leonardo provides us 18 pins.
In order to build the Control box we are going to use a technique called “button matrix” in its simplest implementation (no diodes, for instance). This means no more than one button can be pressed at the same time but we are not building a keyboard anyway.
A button matrix, as per its name, sees all the buttons displayed in a X*Y organization: every row and column are actually wires that connect each button. The board then periodically checks its inputs and, if a button is pressed, it identifies it by cross-checking which input is active and finally sends the correspondent output to the PC. It’s like checking the coordinates in the Battleship game, more or less.
The button matrix is usually squared. As you probably have already guessed, a 3×3 matrix controls up to 9 buttons, a 4×4→16 buttons, 5×5→25 and so on. A 2×2 matrix controls 4 buttons but in this case wiring the 4 buttons straight to the board is usually faster and easier.
We can now proceede to choose the components we want on our box. We will not use any latched (or non-momentary) switch at the moment in order to keep everything simple. A wide array of momentary buttons and switches and encoders is available on the market.
A momentary push-button (let’s call them just “buttons” for simplicity’s sake) is a device that triggers only when we interact with it and it reverts to its precedent state once we interrupt our action. They are probably the simplest form of switch.
I find the 3-way momentary buttons much more interesting, so much that I have placed 9 of them in my first project; they are, de facto, two buttons in one.
Buttons come in every sort of shape and colour. Avoid the smallest ones if you can: I have found that the wider the diameter, the more responsive and precise they are.
Encoders are very similar to the knobs of your oven, with the only difference that the former can spin indefinitely. They both move “in steps” in two directions (clock-wise and counter clock-wise) and every step is usually clearly defined by a mechanical soft stop. From our point of view, an encoder is a 3-in-one: it provides in fact 3 different functions, spin CW, spin CCW and a pushbutton. If we wanted to wire it straight to the Arduino board we would therefore need 3 input pins.
The pushbutton, from a logical perspective, is a standard, momentary pushbutton hence can be controlled through the button matrix and it’s complitely discretionary.
Back to the board!
Now that we know our actuators, we can decide how many of each we want in the control box. Following the reference video, we can opt for 4x encoders. These encoder require 2 pins each (spin CW and spin CCW), which brings the available pins down to 10. These 10 pin can be used to control a 5×5 buttons matrix, for a grand total of 25 momentary buttons.
Our sketch will now look like something like that:
There are two things left to do now:
- choose the type of button we want (standard, 3-way, etc.);
- decide if we want to use the encoders’ pushbuttons
Once these two points are defined we can start drawing our wiring diagram.