3 Button 3 Light, buzzer system, Need help with code.

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

Welcome! It sounds like you are making something for a TV competition show?! I think the logic will be simple:

Assuming buttons down gives LOW logic:

#define ready 0
#define triggered 1
#define Buzzer 3
#define LED1 4
#define LED2 5
#define LED3 6

byte state=ready;
byte trigger=0;
byte triggered_led;
unsigned long trigger_time;

void setup()
{
  pinMode(Buzzer,OUTPUT);
  pinMode(LED1,OUTPUT);
  pinMode(LED2,OUTPUT);
  pinMode(LED3,OUTPUT);

  digitalWrite(LED1,LOW);
  digitalWrite(LED2,LOW);
  digitalWrite(LED3,LOW);

  pinMode(button0,INPUT);
  pinMode(button1,INPUT);
  pinMode(button2,INPUT);

  digitalWrite(button0,HIGH);
  digitalWrite(button1,HIGH);
  digitalWrite(button2,HIGH);
}

1 thread is enough, don't cross post.

Arrch:
1 thread is enough, don't cross post.

Yikes, now that you pointed it out, I've removed half my supplied code, fair enough until the OP removes one of the two post. ]:slight_smile:

Try this:

// define pins to be used
int S1 = 2; //switch 1
int S2 = 3;
int S3 = 4;
int L1 = 5;  // light 1
int L2 = 6;
int L3 = 7;
int B = 8;  // buzzer

void setup() {                
  // initialize the digital pins.
  // assume switches will wire from ground to input pins
  pinMode(S1, INPUT_PULLUP);
  pinMode(S2, INPUT_PULLUP);
  pinMode(S3, INPUT_PULLUP); 
  pinMode(L1, OUTPUT);    // if using leds please remember to use series resistors with them
  pinMode(L2, OUTPUT);
  pinMode(L3, OUTPUT);
  pinMode(B, OUTPUT);    // buzzer wired from output pin to ground 
}

void loop() {
  
  if (!digitalRead(S1))
    { digitalWrite(L1,HIGH); // turn on lamp 1
      digitalWrite(B,HIGH); // turn on buzzer
      delay(2000);           // wait 2 seconds
      digitalWrite(B,LOW); // turn off buffer
      delay(28000);         //  wait 28 more seconds
      digitalWrite(L1,LOW);  // turn off lamp 1
    }
  if (!digitalRead(S2))
    { digitalWrite(L2,HIGH); // turn on lamp 2
      digitalWrite(B,HIGH); // turn on buzzer
      delay(2000);           // wait 2 seconds
      digitalWrite(B,LOW); // turn off buffer
      delay(28000);         //  wait 28 more seconds
      digitalWrite(L2,LOW);  // turn off lamp 2
    }
    
   if (!digitalRead(S3))
    { digitalWrite(L3,HIGH); // turn on lamp 3
      digitalWrite(B,HIGH); // turn on buzzer
      delay(2000);           // wait 2 seconds
      digitalWrite(B,LOW); // turn off buffer
      delay(28000);         //  wait 28 more seconds
      digitalWrite(L3,LOW);  // turn off lamp 3
    }
}

Just don't tell PaulS I used delay() statements, ok? :smiley:

Lefty

andiator:
And then reset the loop.

So far you have explained:

Three buttons enabled.
One button is triggered.
All three buttons disabled. Buzzer starts. One LED goes on.
Two seconds later, buzzer stops.
28 seconds later, LED goes off.

At what point do you want to re-enable the buttons - only after the whole cycle has completed and the LED has gone off again?

retrolefty:

  if (!S1)

You're testing pin numbers? :wink:

I'd have thought it made more sense to put the switch and LED pin numbers into arrays and iterate through the arrays.

PeterH:

retrolefty:

  if (!S1)

You're testing pin numbers? :wink:

I'd have thought it made more sense to put the switch and LED pin numbers into arrays and iterate through the arrays.

Yep, was rushing through and forgot all about reading the input pins. :smiley:

Thanks, will edit

Retrolefty,

Thank you so much for your code... This thing works like a champ... All I had to to is wire it up and bam, its beautiful. I'm so excited now. All I got left is build a chase for this thing, solder everything, and make it look nice. Thanks again. This thing is awesome.

Everyone,
Thank you for all your input. I apologize for the cross post. At first I didn't see the programming thread so I placed it in the Project guidance and then saw the programming and thought that one fits better.

-Andy

Just don't tell PaulS I used delay() statements, ok?

I'm pretty sure he'll find out.