Theoretical 1 Wire Keypad (Simultaneous Buttons)
by Projects_by_Manners in Circuits > Electronics
539 Views, 2 Favorites, 0 Comments
Theoretical 1 Wire Keypad (Simultaneous Buttons)
![Keypad.jpg](/proxy/?url=https://content.instructables.com/F9O/RFEV/KVTJD0HA/F9ORFEVKVTJD0HA.jpg&filename=Keypad.jpg)
Firstly I would like to shout out to Cesosas for his instructable "Creating a 1-wire keyboard" which gave me the inspiration for this project, https://www.instructables.com/Creating-a-1-wire-K... If you are interested in this I recommend checking him out as well as he goes over the fundamentals of the circuitry well. While his design is good it cannot easily handle multiple buttons being pressed.
This design makes use of the 10 bit ADC in the ATmega328P which is the microprocessor in Arduino boards. By making each button output the voltage corresponding to one of these bits we can add them all then identify each button using bitwise logic on the ADC value.
There are also a few reasons, that ill go into later, that make this design impractical and difficult to implement in real life but it is a good exercise to understand how the ADC of an Arduino works.
Some topics this instructable will use are as follows
- Arduino ADCs
- Binary numbers
- Bitwise Logic
- Summing Amplifier
If you are not familiar with these that is ok but if you are keen to learn more it may be worth having a look online as this may make a bit more sense with some background knowledge. That being said I have tried to keep it easily understandable.
Premise
![binary-to-decimal.png](/proxy/?url=https://content.instructables.com/F9N/WDJH/KVTJCYSW/F9NWDJHKVTJCYSW.png&filename=binary-to-decimal.png)
![Button Vs Voltage.PNG](/proxy/?url=https://content.instructables.com/FJF/NPRQ/KVTJCYNT/FJFNPRQKVTJCYNT.png&filename=Button Vs Voltage.PNG)
![Proportions of Possible Total Voltage.png](/proxy/?url=https://content.instructables.com/FKJ/4V7L/KVTJCYSX/FKJ4V7LKVTJCYSX.png&filename=Proportions of Possible Total Voltage.png)
In Arduino to read an analogue voltage and ADC (analogue to digital converter) is used. We can consider this digital value as a series of 1s and 0s. In our Arduino, we have a 10 bit ADC. This basically means that the digital value we get out from our ADC will be comprised of 10 1s or 0s. In all binary numbers, each bit is double the previous bit. You can see this in the figure below with the 8-bit binary number in the table.
In our Arduino when we read 5V or just under 5V this produces the max binary value of all 1s (11 1111 1111) and when we read 0V this produces our min binary value of all 0s (00 0000 0000). Each bit of this number will correspond to a different voltage. The MSB (most significant bit) will be half of the max at 2.5V, then the next half at 1.25V and so on until the LSB (least significant bit) is 0.00488V.
How this design works is for each button on our keypad we can contribute a voltage to the analogue voltage which we sum up and read. We can choose these voltages such that one button contributes 2.5V, another 1.25V and so on until the last contributes 0.00488V. Now whenever a button is pressed we can identify the bit in the binary reading that corresponds to the voltage contributed by the pressing of the button.
By using this method we can make sure that all possible analogue voltages can only be generated by 1 combination of buttons pressed.
Designing the Buttons
![Button Layout.PNG](/proxy/?url=https://content.instructables.com/FUG/8QHM/KVS3VQIB/FUG8QHMKVS3VQIB.png&filename=Button Layout.PNG)
For this circuit, the first thing to design was the buttons. I wanted to make them such that when pressed they were at high and when not they were at low. I used a pullup resistor to do this. This is similar to what happens in the Arduino when you declare a pin as an output.
As we only have a 10 bit ADC we can only have 10 buttons that work with only using numbers but most keypads are 4x3. To do this design for one of those you would need a 12 bit or higher ADC.
You will also notice that instead of using 5V at the source I have used -5V. This is the first reason why this circuit is not very practical. This is needed to be -5V due to the next stage of the design which is the inverting summing amplifier. I'll go over why this is the case in the next step.
Adding the Voltages
![Inverting Summer Diagram.png](/proxy/?url=https://content.instructables.com/FOR/H398/KVTJCZ78/FORH398KVTJCZ78.png&filename=Inverting Summer Diagram.png)
![Inverting Summer Equation.png](/proxy/?url=https://content.instructables.com/F2Q/0CCB/KVTJCZ77/F2Q0CCBKVTJCZ77.png&filename=Inverting Summer Equation.png)
![Inverting Adder.PNG](/proxy/?url=https://content.instructables.com/FML/QOR0/KVS3VQIC/FMLQOR0KVS3VQIC.png&filename=Inverting Adder.PNG)
To add the voltages I used an inverting summer amplifier. This essentially works by creating virtual earth as seen in the first figure. If there is a difference in voltage between input and this virtual earth a current will flow. With opamps, we assume that no current can flow through their inputs so the current must keep going somewhere. It is forced to flow through Rf which is what causes our output voltage. All the currents from the inputs add together when they flow through Rf and this is how we add the inputs. I have controlled how much voltage each input can contribute by selecting different resistor values which change the current each input can provide.
As the current flows past ground on its way it means that we have now inverted our voltage. This is why I have used -5V in the previous step as it means that the output is now able to be directly fed into the ADC. This could have been overcome by using a non-inverting summer but this would make the calculations very complex and as this circuit isn't practical I decided not to go through the trouble.
Limitations of Physical Implementation
I have already spoken about how using -5V is not practical. This is as it would require another voltage source whereas without it the keypad could be directly run of the Arduino.
When choosing resistor values issue arises in this step where if we want to actually design this we only have certain discrete steps of resistor values we can use. We could just select the closest ones but for this design, as we have such small voltages for the lower buttons we would likely run into issues where the buttons do not read as desired.
The smallest voltage that a button contributes is 0.00488V. Just a 0.192% variation of the MSB resistor could result in an incorrect reading. This would be the total variation of just one resistor which includes error from selecting a practical resistor value rather than theoretical and tolerance of the resistor. While it is unlikely all buttons would be pressed at once it is possible an, in this case, these variations would add up making it more likely for errors. This again makes this circuit difficult and impractical to implement. This issue would only be an issue to the LSB though so if you decreased the keypad size you may be able to get away with it.
Conclusion
While this design is not fully practical for a 10 button Keypad I am tempted to try it out for maybe a 5 or 6 button one as I think that it would work quite well. It is also a good way to get a deeper understanding of how the ADC works and how more information than just the analogue voltage can be extracted from the output.
Again cheers to Cesosas for the inspiration.