Need help with my code :)

Hello there.
I’m new to arduino and have been working on a Code system with a 3x4 keypad (7pins)
I’ve written this code but my serial just gives me a lot of numbers and it doens’t do anything if i type on the keypad, is my code wrong or?

int i, k, pwcount=0;
char password = “1801”, entry[10];

void setup()
{
Serial.begin(9600);
for (i=2; i<=5; i++)
pinMode(i, INPUT);
for (i=6; i<=11; i++)
pinMode(i, OUTPUT);

}

void loop()
{
for (i=6; i<=8; i++)
{
reset();
digitalWrite(i, HIGH);
if(digitalRead(2)==HIGH && i==6)
{
blinker();
entry[pwcount] = ‘1’;
pwcount++;
delay (200);
Serial.print(‘1’);
}
if (digitalRead(3)==HIGH && i==6)
{
blinker();
entry[pwcount] = ‘1’;
pwcount++;
delay(200);
Serial.print(‘4’);
}
if (digitalRead(4)==HIGH && i==6)
{
blinker();
entry[pwcount] = ‘7’;
pwcount++;
delay(200);
Serial.print(‘7’);
}
if (digitalRead(5)==HIGH && i==6)
{
blinker();
entry[pwcount] = ‘’;
pwcount++;
delay(200);
Serial.print(’
’);
}
if (digitalRead(2)==HIGH && i==7)
{
blinker();
entry[pwcount] = ‘2’;
pwcount++;
delay(200);
Serial.print(‘2’);
}
if (digitalRead(3)==HIGH && i==7)
{
blinker();
entry[pwcount] = ‘5’;
pwcount++;
delay(200);
Serial.print(‘5’);
}
if (digitalRead(4)==HIGH && i==7)
{
blinker();
entry[pwcount] = ‘8’;
pwcount++;
delay(200);
Serial.print(‘8’);
}
if (digitalRead(5)==HIGH && i==7)
{
blinker();
entry[pwcount] = ‘0’;
pwcount++;
delay(200);
Serial.print(‘0’);
}
if (digitalRead(2)==HIGH && i==8)
{
blinker();
entry[pwcount] = ‘3’;
pwcount++;
delay(200);
Serial.print(‘3’);
}
if (digitalRead(3)==HIGH && i==8)
{
blinker();
entry[pwcount] = ‘6’;
pwcount++;
delay(200);
Serial.print(‘6’);
}
if (digitalRead(4)==HIGH && i==8)
{
blinker();
entry[pwcount] = ‘9’;
pwcount++;
delay(200);
Serial.print(‘9’);
}
if (digitalRead(5)==HIGH && i==8)
{
blinker();
delay(200);
Serial.print(’#’);
pwcount = 0;
for(k=0; k<=4; k++)
{
if (k==4)
{
Serial.print(“Acces Granted”);
digitalWrite(9, HIGH);
delay(2000);
break;
}
if(password[k] != entry[k])
{
Serial.print(“Denied”);
break;
}
}
for(k=0; k<10; k++)
entry[k]=0;
}
}}

void reset()
{
int j;
for(j=6; j<=8; j++)
digitalWrite(j, LOW);
}
void blinker()
{
digitalWrite(11, HIGH);
delay(20);
digitalWrite(11, LOW);
}

How is the keypad wired ?
Why not use the Keypad library to read it ?

Found out what was wrong :slight_smile:

I'm doing this because i did not know of a keypad library :open_mouth:
Found a youtube video, its 4 years old might be why he typed the code like this, but it did give me some understanding about "for" :smiley:

do you have a link to commands and such over the library? :slight_smile:

There are also example programs to exercise the keypad that you could try.

Paul

do you have a link to commands and such over the library?

As has been suggested, there are examples with the library. You also have access to the source code of the library.

Hi,
Keypad library

http://playground.arduino.cc/Code/Keypad

Tom... :slight_smile: