How to Activate and Deactivate Switches?

Hey I'm currently trying to make a buzzer system with 3 push buttons, 3 LEDs, and 1 buzzer. The way I want to set it up is so that if you press one switch it will deactivate the other two, light up the LED for 30 seconds and activate the buzzer for 2 seconds. And then reset the loop.

I was thinking of doing ladder logic because the set up is simple and I'm more familiar with it but it's too costy. So my friend recommended the Arduino UNO. However, my problem is with the code setup. I know basic concepts of programing just don't know how to set up this code properly.

Here is what the concept for the code I think that would work:

  • Have a constant Loop
    use if statements inside the loop
    Assuming 1 = ON and 0 = OFF
    Loop
    If S1 = 1, then L1 = 1, L2 = L3 = 0 and kill loop before reseting for 30 seconds,

else,
S2 = 1, then L2 = 1, L1 = L3 = 0 and kill loop before reseting for 30 seconds,

else,
S3 = 1, then L3 = 1, L2 = L1 = 0 and kill loop before reseting for 30 seconds,

I'm new to the Arduino board and will take any advice that I can get. I was able to do all my wiring with the 3 switchs, 3 LEDs, and Buzzer and make it work so that u press S1, L1 and Buzzer lights up and so on, but my issue is what is the best way to incorporate the Arduino board to disable the other two switchs while the first one is press. Similar to a gameshow buzzer system.

Thank you

One of the few times when using delay() actually is has an advantage over writing a slightly more complex state machine.

Create a while loop that loops until one of the buttons is pressed.
Determine which button was pressed and the light the LED and turn the buzzer on.
Wait 2 seconds and turn the buzzer off.
Wait 28 seconds
Repeat.

Please don't cross post.

You can't actually activate or deactivate a switch. You can decide to read the switch state, or not, at any given time. You can decide to read the switch, but not act on the information, at any given time.

What would be a good exercise is to first implement Arcch's suggestion with delay(), and then implement the read/don't read logic (or the use/don't use logic) using millis() and a state machine.

Being able to write code that uses state machines and time based state changes, without the artificiality of delay() is a good thing.

//Hi!
//i'm new too with Arduino:
//try that sketch; i built the circuit and all worked well.

//notide that
int Bu1=9;
int Bu2=10;
int Bu3=11;

int L1=3;
int L2=4;
int L3=5;

int buzz=2;

void setup(){
//i could initialize the pins one by one,
//but this method is quite handy, and i made it mine
for(int x=3;x<6;x++){
pinMode(x,OUTPUT);
}
for (int x=9;x<12;x++){
pinMode(x,INPUT);
}
}

void loop(){

int ledarray[]={3,4,5};
int buttonstate[]={digitalRead(Bu1),digitalRead(Bu2),digitalRead(Bu3)};

for(int x=0;x<3;x++){
if (buttonstate[x]==1){
digitalWrite(ledarray[x],HIGH);
tone(buzz,440,2000);
//while waiting nothing can happen
//so other buttons cannot be read
delay(30000);
digitalWrite(ledarray[x],LOW);
delay(10);
}

}

}

//hope you'll enjoy!
// if you need, i may post the circuit scheme made with fritzing!

I don't think that copying/pasting that "code" is going to help anyone. If you are going to post code that others might use, you should do it right, using the code icon (the one with the # on it).

as i said, i'm totally new...
im sorry!

int Bu1=9;
int Bu2=10;
int Bu3=11;

int L1=3;
int L2=4;
int L3=5;

int buzz=2;

void setup(){
  for(int x=3;x<6;x++){
    pinMode(x,OUTPUT);
  }
  for (int x=9;x<12;x++){
    pinMode(x,INPUT);
  }
}

void loop(){
  
  int ledarray[]={3,4,5};
  int buttonstate[]={digitalRead(Bu1),digitalRead(Bu2),digitalRead(Bu3)};
  
  for(int x=0;x<3;x++){
    if (buttonstate[x]==1){
      digitalWrite(ledarray[x],HIGH);
      tone(buzz,440,2000);
      delay(30000);
      digitalWrite(ledarray[x],LOW);
      delay(10);
    }
    
  }
  
}

Much better. Thank you.