Tutorial: Arduino and Push-wheel switches
Welcome back fellow arduidans!
In this article we go back to the past via the use of push-wheel/thumb-wheel switches with out Arduino systems. Here are some examples sourced from somewhere on eBay:
For the uninitiated, each switch is one vertical segment and they can be connected together to form various sizes. You can use the buttons to select from digits zero through to nine. There are alternatives available that have a wheel you can move with your thumb instead of the increase/decrease buttons. Before the days of fancy user interfaces these switches were quite popular methods for setting numerical data entry. However they are still available today, so let’s see how they work and how we can use them.
The switch’s value is made available via binary-coded decimal. Consider the rear of the switch:
We have common on the left, then contacts for 1, 2, 4 and 8. If you apply a small voltage (say 5V) to common, the value of the switch can be measured by adding the values of the contacts that are in the HIGH state. For example, if you select 3 – contacts 1 and 2 will be at the voltage at common. The values between zero and nine can be represented as such:
![]()
By now you should realise that it would be easy to read the value of a switch – and you’re right, it is. We can connect 5V to the common, the outputs to digital input pins of our Arduino boards, then use digitalRead() to determine the value of each output. In the sketch we use some basic mathematics to convert the BCD value to a decimal number. So let’s do that now.
From a hardware perspective, we need to take into account one more thing – the push-wheel switch behaves electrically like four normally-open push buttons. This means we need to use pull-down resistors in order to have a clear difference between high and low states. So the schematic for one switch would be (click image to enlarge):
Now it is a simple matter to connect the outputs labelled 1, 2, 4, and 8 to (for example) digital pins 8, 9, 10 and 11. Connect 5V to the switch ‘C’ point, and GND to … GND. Next, we need to have a sketch that can read the inputs and convert the BCD output to decimal. Consider the following sketch (download):
/*
Example 40.1 - display single thumbwheel switch data
Uses SAA1064 numerical display shield http://www.gravitech.us/7segmentshield.html
Uses serial monitor if you don't have the SAA1064 shield
*/
#include
#define q1 8
#define q2 9
#define q4 10
#define q8 11
void setup()
{
Serial.begin(9600);
Wire.begin(); // join i2c bus (address optional for master)
delay(500);
pinMode(q1, INPUT); // thumbwheel '1'
pinMode(q2, INPUT); // thumbwheel '2'
pinMode(q4, INPUT); // thumbwheel '4'
pinMode(q8, INPUT); // thumbwheel '8'
}
void dispSAA1064(int Count)
// sends integer 'Count' to Gravitech SAA1064 shield
{
const int lookup[10] = {
0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F };
int Thousands, Hundreds, Tens, Base;
Wire.beginTransmission(0x38);
Wire.send(0);
Wire.send(B01000111);
Wire.endTransmission();
Wire.beginTransmission(0x38);
Wire.send(1);
Thousands = Count/1000;
Hundreds = (Count-(Thousands*1000))/100;
Tens = (Count-((Thousands*1000)+(Hundreds*100)))/10;
Base = Count-((Thousands*1000)+(Hundreds*100)+(Tens*10));
Wire.send(lookup[Base]);
Wire.send(lookup[Tens]);
Wire.send(lookup[Hundreds]);
Wire.send(lookup[Thousands]);
Wire.endTransmission();
delay(10);
}
int readSwitch()
{
int total=0;
if (digitalRead(q1)==HIGH) { total+=1; }
if (digitalRead(q2)==HIGH) { total+=2; }
if (digitalRead(q4)==HIGH) { total+=4; }
if (digitalRead(q8)==HIGH) { total+=8; }
return total;
}
void loop()
{
dispSAA1064(readSwitch()); // sends switch value to display shield
Serial.println(readSwitch()); // sends switch value to serial monitor box
}The function readSwitch() is the key. It calculates the value of the switch by adding the numerical representation of each switch output and returns the total as its result. For this example we used a numerical display shield that is controlled by the NXPSAA1064. If you don’t have one, that’s ok – the results are also sent to the serial monitor. Now, let’s see it in action:
Ok it doesn’t look like much, but if you need numerical entry it saves a lot of physical space and offers a precise method of entry.
So there you have it. Would you actually use these in a project? For one digit – yes. For four? Maybe, probably not – perhaps it would be easier to use a 12-digit keypad. There’s an idea… But for now I hope you enjoyed reading this as much as I did writing it for you.
If you have any suggestions with regards to our next article, leave a comment below and we’ll look into it. Furthermore, don’t be shy in pointing out errors or places that could use improvement. Why not follow us on twitter and facebook to keep up with new articles, news and other items of interest.



