Entering/Verifying Pincodes on Arduino

Goodday.

Hi, Im a beginner on arduino, our project is about entering/verifying pincodes on Arduino.
The pushbutton acts as the number input, arduino must check/verify the codes entered (sequence sensitive) and if verified correct, LED sequence will trigger. (our code is 1325) using 5 pushbuttons, pushbutton 4 is blank.
(I stored the codes on myArray and to be compared on the pushbutton strokes assigned also to another array).

*array,if,else,for,while,digitalRead,. are the only functions we can use in this exercise.

  1. How can I assign 1st pushbutton pressed on index 1 of myArraytest... on and so on and so forth?
  2. How can arduino detect 1st/2nd/3rd etc.. pushbutton pressed?

Hoping someone may help :))
Suggestions are welcome.. Thanks :)) and more power :slight_smile:

PS. The codes below are still in beta and it is flawed.

int i;
int pin1;
int pin2;
int pin3;
int pin5;
int myArray[]={1,3,2,5};
int myArraytest[3];

void setup()
{

for(i=0;i<=7;i=i+1)
{
pinMode(i,OUTPUT);
}
}

void loop()
{

myArray[0]=1;
myArray[1]=3;
myArray[2]=2;
myArray[3]=5;

pin1=digitalRead(26);
pin2=digitalRead(25);
pin3=digitalRead(24);
pin5=digitalRead(22);

//Assign 1st pushbutton pressed to index 1 of myArrayTest, 2nd pusbutton pressed to 2nd. etc....
// Codes below are fas

if(pin1==1)
{
myArraytest[0]=1;

}

if(pin2==1)
{
myArraytest[1]=2;

}

if(pin3==1)
{
myArraytest[2]=3;

}

if(pin5==1)
{
myArraytest[3]=5;

}

if(myArraytest[0]==myArray[0]&&myArraytest[1]==myArray[1]&&myArraytest[2]==myArray[2]&&myArraytest[3]==myArray[3])
{

for(i=0;i<=6;i++)
{
digitalWrite(i,HIGH);
delay(100);
}
i=7;

while(i=7)
{
digitalWrite(i,HIGH);
delay(100);
digitalWrite(i,!HIGH);
delay(100);

}

}

}

and it is flawed.

Is that all we get to work from?

Please read the "how to use the forum" stickies. They will tell you how to format and post code and, more importantly, how to ask a question.

A schematic of your wiring would help, too.

  while(i=7) time to visit the Reference

Thanks for the quick reply.

No you can re-write the entire code. The array thing was just my idea. but array,if,else,for,while,digitalRead are the only functions that can be used.

Pushbutton1 >> pin26
Pushbutton2 >> pin25
Pushbutton3 >> pin24
Pushbutton4 >> pin23
Pushbutton5 >> pin22

while(i=7)
is A part of the the LED sequence code.

The LED sequence is OK, the problem is the verifying of codes. Thanks again :slight_smile:

Can you use Serial.print to look at the values of your variables as the sketch runs? Can you use delay() to slow things down so that you can watch what is happening? Once the sketch is working remove the prints and delays.

And will you post the schematic?

Im sorry i dont know how to do the serial print. I do not know how to explain the schematics but you may refer below.
Using Arduino Mega 2560
LED1=RX(0)
LED2=TX(1)
LED3=2
LED4=3
LED5=4
LED6=5
LED7=6
LED8=7
LED9=8
LED10=9
LED11=10
LED12=11
LED13=12
LED14=13
PushButton1=26
PushButton2=25
PushButton3=24
Pushbutton4=23
Pushbutton5=22..

The current program will run but it will have a conflict in the condition, therefore not allowing the sequence to start. I want to know if how can I assign the 1st pushbutton pressed on the 1st index of the array may it be pushbutton 1 or 2 or 3 or etc...

Thanks for helping again :slight_smile:

How are the switches wired?

Did you fix the error in the while statement that I pointed out in reply #1?

+5V Arduino -> tact switch -> arduino digital pin (22,23,24,25,26) -> Resistor -> GND

the while statement is correct. The problem is in the "pincode" program.. The codes that verify if the pushbutton matches the code or the password assigned. Thanks :slight_smile:

Post your new code, please.