Hello there,
I am currently trying to use a keypad matrix (12 keys) with arduino with 1 pin.
My current issue is, that i cant print the actual values in serial monitor.
The Serial monitor Outputs exactly:
Programm started
(the first digit i press)
(nothing else, no matter what i press)
any Ideas what could be the problem?
I have an original Arduino Uno with ATMEGA 328P-PU chip
Here is the code:
//Keypad
int thresholds[12] = {928, 908, 884, 848, 834, 811, 782, 769, 756, 725, 725, 700};
char keypad[12] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '*', '0', '#'};
void setup() {
Serial.begin(9600);
delay (250);
Serial.println("Program started");
}
void loop() {
int value = analogRead(A1);
for (int i = 0; i < 12; i++)
{
if ( abs(value - thresholds[i]) < 5)
{
Serial.println(keypad[i]);
while (analogRead(A1) < 1000) {delay(100);}
}
}
}
Here is the code to read out the analog values corresponding to the keypad matrix: (btw the serial monitor works fine on this code)
void setup() {
Serial.begin(9600);
}
void loop() {
int value = analogRead(A1);
Serial.println(value);
delay(100);
}
thanks in advance
Please read the "how to use the forum-please read" stickies to see how to format and post code. Compare what is posted with your real code to see why we ask that code be in code tags. We can't help you until we see the real code without italics.
if ( abs(value - thresholds) < 5)
Serial.println(keypad);
Do you see the problems with these lines?
Hello groundFungus,
Sorry for the inconvenience, I did not see the post till now, thanks for pointing that out tho.
Here is the code shown right:
Normal code:
//Keypad
int thresholds[12] = {928, 908, 884, 848, 834, 811, 782, 769, 756, 725, 725, 700};
char keypad[12] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '*', '0', '#'};
void setup() {
Serial.begin(9600);
delay (250);
Serial.println("Program started");
}
void loop() {
int value = analogRead(A1);
for (int i = 0; i < 12; i++)
{
if ( abs(value - thresholds[i]) < 5)
{
Serial.println(keypad[i]);
while (analogRead(A1) < 1000) {delay(100);}
}
}
}
code to read out the values(serial monitor works here):
void setup() {
Serial.begin(9600);
}
void loop() {
int value = analogRead(A1);
Serial.println(value);
delay(100);
}
Thanks in advance.
while (analogRead(A1) < 1000) {delay(100);}
The first thing that I would do is insert a serial print in the while loop to see if the value returned by the analogRead is actually ever greater than 1000. If it is not, you will get stuck there.
Hello, when I insert it like this.
if ( abs(value - thresholds[i]) < 5)
{
Serial.println(keypad[i]);
while (analogRead(A1) < 1000) {delay(100);
Serial.println(analogRead(A1));}
}
and do a serial print, it spits out values between 390-405, so it never exceeds 1000,
but it does not change anything when i press a button.
The buttons are wired up correctly, as i can see with a multimeter, that the values change, as well as with the testprogramm.
I have attached the basic wiring which i adjusted to a 12 key keypad (deleted the last 220 resistor and the letter row).
Thanks for your time.