1,155

16

8

Every time I see a keypad, it comes with a lot of pins , it's a big waste of your Arduino pins ,so can we run a keypad with one and only one pin ? .The answer is here.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Bill of Materials

Hardware:

01 Arduino UNO

01 LCD with I2C

16 Push buttons

04 resistors 1.5 kΩ

04 resistors 620 Ω

04 resistors 220 Ω

08 resistors 100 Ω

01 resistor 1 kΩ

07 Jumper wires

Software:

Arduino IDE installed on your PC

Step 2: Schematic and Cicruit

The all idea is that we have 4*4 matrix of push buttons connected vertically to the Ground by the right lead and horizontally by the other lead (the button lead) and resistors of 1.5 kΩ, 620Ω, 220Ω, and 100Ω, the ends of the 4 rows are connected by four 100Ω resistors as shown the schematic.

Every time you push a button you close the circuit and the current goes through a different path and different chain of resistors that's why pin A0 recieve a different analog read for every push button. All what you need now is codding.

Step 3: The Code

#include

#include

LiquidCrystal_I2C lcd(0x3f, 20, 4);

int Button = A0;

void setup()

{

Serial.begin(9600);

lcd.begin();

pinMode(Button, INPUT);

lcd.backlight();

lcd.print("Hello World");

delay(2000);

lcd.clear();

delay(2000); }

void loop()

{

Step 4: Correction of Values

When you open the serial moniter it will show a value of 1023 , if you push a button it will give you another reading you have to take those values and make some changes in the code

Step 5: Project After Criticism and Review

There is no doubt that we are all here to learn and share our knowledge,thanks to some comments left by some people from the community that were very helpful,I decided to make some adjustments and improvements to my project:

The hardware:

I decided to solder all components in a PCB to avoid the problem of bad connection in the breadboards.

The code:

A friend advised me to use a software debouncing and it's just a loop ("for" loop for example) to make the programme take some time to pick a read it means that it make a lot of reads (500 in my examle) but takes only the last one.

for (i=1; i<= 500; i++) { // take only the 500th analogread

An other friend thanks to him advised me to compare "readvalue" with a range of values not one because "readvalue" takes a lot of values for the same push button.The "A" for example gives a read of : 849, 850 ,851 852, 853, 854 ,855 so it's a range of 7 values :a threshold (852) and 3 values left and right. what we have to do here is to compare the absolute value of the difference between "readvalue" and "852" to "3".

Step 7: The Moment of Truth

As you can see the program sometimes confuses buttons but it still work , in theory ther is no thing wrong with the circuit but the code needes more calibration.

Step 8: The End

I hope you like this project and you try to do it, may be you will do better than I did.

Ask me if you have questions ,leave comments and, don't forget to vote for me if you like that.

Recommendations

• Internet of Things Class

22,778 Enrolled

8 Discussions

Very good explanation. I have used something like this in a progect. I changed the resistors and used forward biased diodes to get 0.6V drop between switches I was only using 6 bush buttons but it was necessary to calibrate the voltage ladder to get reliable detection.

even though you are reading analog values might be worth experimenting with hardware
de-bouncing. probably can get by with just one extra capacitor and resistor near the input, might help eliminate false readings if that is an issue. can also use software debouncing but if your already going to have that many components might as well use a few more.