Introduction: Rotary Encoder Display Panel
While the Arduino is fun, inspirational and hopefully educational as things are built, ideas are explored and ultimately shared for the edification and amusement of all, an Arduino based project can equally be tedious and trying. The plethora of modules and kits of course bypass the angst associated with the gritty part of DIY circuitry and there are many clever do-dads shared in many ‘communities’ that help breadboard the brilliant, the clever and the amusing Arduino creations. The excitement can however wear a bit thin when the relevant code for the project involves one or more variable quantities whose introduction means iterations of uploads via the IDE or schemes for passing variants via the serial monitor window.
This Instructable is not presented to refute the value of good science that could obviate its premise but rather to present a Rotary Encoder Display Panel fabricated to insert variable values into a project’s sketch. In addition it was also an aspiration to have a do-dad that could avoid the undesirable frustration and frailty of the breadboard when the project includes ‘field exercises’ away from the lab bench.
Step 1: Material
- 1x - ribbon cable – 5 conductors, about 30cm
- 1x - various headers and sockets
- 1x - Perfboard about 3cm x 7cm
- 1x - capacitor of nominal value 1µf
- 1x - 10K resistor
- 1x - 560Ω resistor
- 1x - 150Ω resistor
- 1x - 5mm LED
- 1x - 12mm square tactile button
- 1x - 4 Bits Digit Tube LED Display Module Board
- 1x - Rotary Encoder Module (e.g. KY-040)
- 1x - "D" shaft knob for encoder (not shown)
- 1x - 2x5 header with 25cm ribbon cable (recycled PC HD cable)
- 1x - Heat Shrink various 1mm-2mm (optional)
- 1x - 10cm square vinyl floor sample (>2mm)
- 1x - Krazy glue
- Bench tools, as soldering iron, power drill, box cutter, etc.
Step 2: Plan/Preparation
The inspiration (if that’s a good description) of this fabrication is a project that required the previously mentioned variable quantities and an event that was itself independent of the variable quantities. The Arduino UNO is the associated microprocessor board and thus the logical connections are male pins.
After inspiration is the material realization. The available ‘stock’ of a KY-040 style rotary encoder module, a 4-bit LED display module and a 12mm tactile switch determined the basic components. It seemed prudent to put some form of hardware debounce on the 12mm switch.
A review of comments from the Internet gave rise to the conclusion that the application of the KY-040 style rotary encoder as a ‘useful tool’ rather than a precise instrument would be within the scope of this fabrication. The rotary switch was accept ‘as is’ when it appeared that 10K pull-ups are on the module.
The author’s preferred default state of an event switch is ‘active high’ as this seems to work directly with N-channel MOSFET and the like. The hardware debounce is mainly lifted from the Internet with a modification based of the first suitable radial resistor and capacitor pulled from the loose-ends drawer, here a 560Ω and 1μF values.
When cobbled together the chosen pieces present nine pin-outs and if resolved with a 2x5 header, the tenth pin gave occasion to include a garden variety LED. Alternately the pin could possibly be used for a second tactile switch.
Lastly, a substrate or enclosure; no box or enclosure was at hand so the choice fell to a 10cm square vinyl floor sample. Although not particularly rigid, the vinyl samples have been useful where electrical separation and attachment have been desirable attributes. Screws can be used to anchor PCB/modules that are seemingly of no standard dimensions and in turn the vinyl base can be easily customized to the dimensions of the box/enclosure. Also fast acting glue can be used in lieu of screws for the PCB/modules with some expectation that the bond can be broken if necessary.
Step 3: Panel Cut Out
The construction starts with the panel substrate (vinyl) and the hardware pieces available determine the layout and the specific dimensions of the cut outs. There is also considerable scope for personal taste and traits. Obviously the tools on hand and skill also establish the methods, in this case a simple box-cutter and cordless drill were employed.
The desired result is shown in the image. Assuming the panel back will be the patterned side of the floor, mark and cut or drill:
- 1x 20mm (.25”) hole -> rotary encoder shaft
- 1x 15mmx31mm rectangle -> 4-bit LED tube
- 4x 2mm holes -> to match tactile switch spacing (e.g. 6mm and 12mm)
- 1x 5mm hole -> two-lead LED (adjust hole to LED’s actual diameter)
- 1x 6mmx12mm - > double row male header (adjust size, oversize OK)
The right image shows the panels elements when fitted to the apertures created.
Step 4: Soldering the Bits
The LED tube module will not mount flush to the substrate with the default header and a header on the back of the module is needed. With this particular module however the header proved to be very difficult to desolder and instead it was snipped off. Without the drilled hole, the header on the back of the module is attached in a ‘surface mount’ fashion as shown. Initially the oblique angle was thought to be a clever way to reduce to module’s profile but became moot when it was thought to be ‘wise’ to add the daisy chain header while it could be easily soldered.
Next solder the debounce circuit, LED base and 2x5 header to pieces of perfboard. The LED and debounce circuits are built with the 7cm-15cm pigtails directly soldered to a perfboard pad or component lead. Because inexpensive perfboard, not a matrix board was used for the 2x5 header some extra copper in the form of .25mm solid wire ‘horns’ were attached at each pin. If a better form of prototype board is used or there is great confidence that subsequent soldering will not lift the copper pad, this practice need not be followed.
Step 5: Soldering the Cables
Two cables with 5 position female sockets are constructed from the 5-conductor ribbon cable. Shrink wrap was included for three reasons, mechanical strength, electrical isolation and identification. Keeping track of VCC/GND is pretty important and red/black shrink wrap gives a quick visual clue.
The third cable is a piece of PC drive cable salvaged by cutting the header to size then applying a dab of quick drying glue to hold the retaining strap. The free end of the cable is split into the pattern of pins desired. The connectors are grouped for connection to the Arduino UNO as shown :
- a pair of connectors for the 5V/GND pins of the Arduino UNO.
- a pair are connectors for the single LED and the button switch.
- a three pin connectors for the function/data pins of the LED Tube
- a three pin connectors for the function/data pins of the rotary encoder
There is not much to dictate the pin-outs for the cable but for this fabrication (and notes) pin #1 is taken to be the upper right of the header. This was assigned to VCC. Pin #2 is taken to be lower right and assigned to GND.
Pin 9 and 10 are at the left and are assigned to the single LED and button switch. Button 10 was selected for the LED thus 5V on the anode of the LED should be the only consequence of choosing the wrong orientation when plugging cable-to-header.
Step 6: Soldering, Test and Glue the Panel
Testing is a matter of personal choice but the modification (correction) of any connections becomes more difficult when the button switch, LED Tube and bits of perfboard are glued to the vinyl substrate. Even resorting to hot glue wouldn’t seem to improve the prospect for an easy re-work. A continuity and shorts check is probably sufficient effort for workmanship and can be combined with note taking to document the (effective) pin-outs.
Soldering the cables and connecting wire to the header is very straightforward but a bit fussy. Don’t start without a ‘plan’ of pin-outs desired. Starting somewhere in the middle and working outward is likely sensible.
The attachment of the tactile switch, while not elegant, was to first glue the switch in its final position on the face of the panel. Before the glue, the terminals of switch were straightened and inserted in the drilled holes. The terminals were extended by soldering extraneous pieces of lead wire and these extensions aligned with the debounce perfboard. The leads were flattened against the perfboard and soldered into a ‘rail’ for each side of the switch.
Next glue the LED and 2x5 header perfboards to the vinyl. Before gluing the LED tube the vinyl can be scored to ensure the pins and solder of the connectors allow the PCB to make good contact with the vinyl. The final act is to attach the rotary encoder with the requisite threaded shaft and add the shaft knob.
If employing quick drying glue for this fabrication the only ‘instruction’ is to be judicious in its application. It is better to apply very small amounts in spots than draw beads as would be done to attach foam insulation.
Step 7: Assembling the Panel
A last minute addition to this fabrication was some very quick carpentry to create a small stand. The face is sloped at an angle that would ensure the 10cm panel face would be fully backed and sit about 25mm from the bottom of the stand. The panel is attached with four #4 screws in each corner.
Step 8: Code
The code for this Instructable is only intended to verify each of the elements of the panel function and is drawn completely from the work of others as:
- Simple button code from Arduino IDE Example
- Keyes KY-040 Arduino Rotary Encoder User Manual "This is a simple sketch that shows how to count the encoder position and how to determine direction of rotation. It has no switch debounce, nor does it use interrupts." http://henrysbench.capnfatz.com/
- 4 Digit 7 Segment Serial LED Module - TM74HC595 from "Arduino Forum > Using Arduino > Programming Questions >" https://forum.arduino.cc/index.php?topic=316731.75
The code will take input from the two pushbutton switches and the rotary encoder. The rotary encoder values are shown on the LED tube and output to the serial port. The 12mm tactile button is active HIGH and will turn the single LED ON if pressed otherwise the state is OFF. The rotary pushbutton is active LOW and will reset (to zero) the rotary encoder counter.
The code is contained in two files in keeping with their source. The Arduino IDE should compile the files as a single sketch .
Step 9: Summary
The fabrication of the Rotary Encoder Display Panel met its goals and provides a relatively robust solution for input to the Arduino away from the lab bench. The particular rotary encoder (whether by manufacture or handling) and code sketch would at times ‘bounce’ but that has not been investigated since there is no impact on the desired use.
In afterthought there are only two items that come to mind that could improve the result. One addition would be to have a LED hardwired to the debounce circuit of the 12mm tactile button. While this seems redundant given the ‘tactile’ of the tactile button, feedback is sometimes welcome. Second addition could be a debounce circuit for the rotary pushbutton and with a little RTL a LED could be incorporated as well.
There is also a bit of mea culpa to express in association with the added carpentry. The panel layout did not readily accommodate the 25mm ‘lumber’ selected for the stand. Subsequently a notch was made to fit over the LED Tube PCB. There was no use found for the small pile of wood shavings and the panel face provides good cover for this faux pas (lack of planning).
We have a be nice policy.
Please be positive and constructive.