Problems with button lock project

So I have tried to make a password lock with 3 buttons and one reset button and for some reason I keep getting weird bugs.

I am a beginner and I spent 2 days trying to fix this relativly easy project but I still keep getting new bugs

I found a video building this kinda lock but I didnt understand the code so I didnt use it instead I created a my own code which probably wont work

The code was suppose to work like this press one button the blue led lights up then you press the second button the blue led lights up for a second and the third button and then a green or a red led lights up (red lights up when the password is wrong and green when right)

 buttonState1 = digitalRead(Pin1);      //  reads button pretty easy
     
  if (buttonState1 == HIGH){
    Pushedbutton1 = 1;
  digitalWrite(bluePin, HIGH);           //    this turns it into another variable which stays on (or is 1)for  
                                                         //     longer that is for the led
 

                                                             
                                                   //  This just turns the Pushbutton variable 
                                                                      //   after certain time to zero without delaying the whole 
                                                                          //      progtam that is why I used the millis thing              
[code]  if (Pushedbutton1 == 1){                  
   if (currentTime1 - previousTime1 >= eventInterval1*2) {
    previousTime1 = currentTime1;
    
    digitalWrite(bluePin, LOW);
    
  
 
    Pushedbutton1 = 0;
  }}                  




if((buttonState2 == 1) && (Step == 0)){                   //    This checks what step of the password it is
  Step = 1;
}                                                                              //    and what button should be pressed which will
 if ((buttonState1 == 1) && (Step == 0)){                  //      add you a Step so you can progress onto the                 
  Rightwrong = 1;                                                      //         next button and also will give you a 
                                                                      //       Rightwrong variable if you pressed a wrong button
  Step = 1;                                                         //     The other steps are the same thing with different 
                                                                        //           numbers
}
 if ((buttonState3 == 1) && (Step == 0)) {
  Rightwrong = 1;
  Step = 1;
}


if ((Rightwrong == 0) && (Step == 3)){        //        Then its the SCORING PART if you have done no 
                                                              //   mistakes and are on the 3step then the green led turns on
Serial.println("Finished");
  digitalWrite(greenPin, HIGH);
Step = 0;
Rightwrong = 0;
delay (3000);
digitalWrite(greenPin, LOW);
}





if ((Rightwrong == 1) && (Step == 3)){               //  but if you have done a mistake then the red led turns 
                                                                          //    on pretty simple
digitalWrite(redPin, HIGH);
Step = 0;
Rightwrong = 0;
Pushedbutton1 = 0;
Pushedbutton2 = 0;
Pushedbutton3 = 0;
delay (3000);
digitalWrite(redPin, LOW);

but for some reason you need to press the buttons at once to get a green light and the red light keeps flashing and also whenewer you press two buttons it turns the step to 3 and all these other problems

The circuit nothing special just 3 buttons with 20 Ohm resistors and a RGB led with no resistors because I
dont care and the led should only be on for no more than 1 minute

If you think 3 buttons is not enough for a proper lock … then you are right this is just a test

If you think I should rewrite my own code or just replace few statements just let me know

Thanks

The files are here (The file was too large that is why it is on my drive) :

https://drive.google.com/drive/folders/1wkHGJXXlNg-7aQ1_jUSXCgG9VdpY2-yJ?usp=sharing

4Button_password_lock.ino (4.67 KB)

DIWHY: The files are here (The file was too large that is why it is on my drive) :

https://drive.google.com/drive/folders/1wkHGJXXlNg-7aQ1_jUSXCgG9VdpY2-yJ?usp=sharing

You'll get more responses, and thus more help, by uploading your INO file as an attachment. Just "modify" your post and use the attachments button near the bottom. Few, if any, will go through the trouble to cut and paste your URL and then download it.

Hi, Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum". OR http://forum.arduino.cc/index.php/topic,148850.0.html. Then look down to item #7 about how to post your code. It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Tom.... :)

So I updated my post the project is directly there with more details about the code and the circuit

Hi, We need your complete code, so we can see how you have setup I/O and any functions. Please ad your complete code as a new post. Thanks.. Tom.... :)

Here is the code:

const int Pin1 = 2;
const int Pin2 = 3;
const int Pin3 = 4;
const int Pin4 = 5;

int buttonState1 = 0;  
int buttonState2 = 0;  
int buttonState3 = 0;  
int buttonState4 = 0;  

const int redPin = 11;
const int greenPin = 10;
const int bluePin = 9;  

int onoffbluepin = 0;

int nowyoucan = 1;

int Step = 0;

const unsigned long eventInterval1 = 1500;
unsigned long previousTime1 = 0;
const unsigned long eventInterval2 = 1500;
unsigned long previousTime2 = 0;
const unsigned long eventInterval3 = 1500;
unsigned long previousTime3 = 0;
const unsigned long eventInterval4 = 1500;
unsigned long previousTime4 = 0;


const unsigned long eventInterval5 = 400;
unsigned long previousTime5 = 0;



int Pushedbutton1 = 0;
int Pushedbutton2 = 0;
int Pushedbutton3 = 0;
int Pushedbutton4 = 0;

int Rightwrong = 0; //if right than 0 if wrong than 1
void setup() {

  Serial.begin(9600);
  
  pinMode(Pin1, INPUT);
  pinMode(Pin2, INPUT);
  pinMode(Pin3, INPUT);
  pinMode(Pin4, INPUT);
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);

}

void loop() {


  unsigned long currentTime1 = millis();
  unsigned long currentTime2 = millis();
  unsigned long currentTime3 = millis();
  unsigned long currentTime4 = millis();
  unsigned long currentTime5 = millis();

  

    
  buttonState1 = digitalRead(Pin1);
  delay(10);
  buttonState2 = digitalRead(Pin2);
  delay(10);
   buttonState3 = digitalRead(Pin3);
  delay(100);
  buttonState4 = digitalRead(Pin4);
  delay(10);

  if (buttonState1 == HIGH){
    Pushedbutton1 = 1;
  digitalWrite(bluePin, HIGH);
  
  }
  
  if (buttonState2 == HIGH){
  Pushedbutton2 = 1;
  digitalWrite(bluePin, HIGH);
  
  }
  
  if (buttonState3 == HIGH){
     Pushedbutton3 = 1;
  digitalWrite(bluePin, HIGH);

  }
  if (buttonState4 == HIGH){
     Pushedbutton4 = 1;
  digitalWrite(redPin, HIGH);

  }

if (Pushedbutton4 == 1){
    Rightwrong = 0;
    Step = 0;
    Pushedbutton4 = 0;
    Pushedbutton3 = 0;
    Pushedbutton2 = 0;
    Pushedbutton1 = 0;
   if (currentTime4 - previousTime4 >= eventInterval4*2) {
    previousTime4 = currentTime4;
   
    delay (1000);
    digitalWrite(redPin, LOW);
    
   

    
  }}











if((buttonState2 == 1) && (Step == 0)){
  Step = 1;
}  
 if ((buttonState1 == 1) && (Step == 0)){
  Rightwrong = 1;
  Step = 1;
}
 if ((buttonState3 == 1) && (Step == 0)) {
  Rightwrong = 1;
  Step = 1;
}








if((buttonState3 == 1) && (Step == 1)){
  Step = 2;
} 
 if ((buttonState2 == 1) && (Step == 1)){
  Rightwrong = 1;
  Step = 2;
  
}
 if ((buttonState3 == 1) && (Step == 1)){
  Rightwrong = 1;
  Step = 2;
}







if ((buttonState3 == 1) && (Step == 2)) {
  Step = 3;
  
} 
if ((buttonState2 == 1) && (Step == 2)) {
  Rightwrong = 1;
  Step = 3;
  
}

if ((buttonState1 == 1) && (Step == 2)){
  Rightwrong = 1;
  Step = 3;
}





if (Pushedbutton1 == 1){
   if (currentTime1 - previousTime1 >= eventInterval1*2) {
    previousTime1 = currentTime1;
    
    digitalWrite(bluePin, LOW);
    




    Pushedbutton1 = 0;
  }}

if (Pushedbutton2 == 1){
   if (currentTime2 - previousTime2 >= eventInterval2) {
    previousTime2 = currentTime2;
    
    digitalWrite(bluePin, LOW);
   
    Pushedbutton2 = 0;
  }}

if (Pushedbutton3 == 1){
   if (currentTime3 - previousTime3 >= eventInterval3*2) {
    previousTime3 = currentTime3;
    
    digitalWrite(bluePin, LOW);
    
  
    Pushedbutton3 = 0;
  }}


if (currentTime5 - previousTime5 >= eventInterval5) {
    previousTime5 = currentTime5;
Serial.println ("Step");
Serial.print (Step);
Serial.println("Rightwrong");
Serial.print (Rightwrong);
//Serial.println("Buttonstate");
// Serial.print (buttonState1);
//Serial.println ("Pushedbutton first");
// Serial.print (Pushedbutton1);
// Serial.println("Pushedbutton second");
// Serial.print (Pushedbutton2);
// Serial.println("Pushedbutton third");
// Serial.print (Pushedbutton3);


//Serial.println("Buttonstate1");
// Serial.print (buttonState1);
// Serial.println ("buttonState2");
//Serial.print (buttonState2);
// Serial.println("buttonState3");
// Serial.print (buttonState3);
// Serial.println("buttonState4");
// Serial.print (buttonState4);

}

if ((Rightwrong == 0) && (Step == 3)){
Serial.println("Finished");
  digitalWrite(greenPin, HIGH);
Step = 0;
Rightwrong = 0;
delay (3000);
digitalWrite(greenPin, LOW);
}

if ((Rightwrong == 1) && (Step == 3)){
digitalWrite(redPin, HIGH);
Step = 0;
Rightwrong = 0;
Pushedbutton1 = 0;
Pushedbutton2 = 0;
Pushedbutton3 = 0;
delay (3000);
digitalWrite(redPin, LOW);

}
}

for clarifaction yes the blue led is suppose to confirm each press