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.
// 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?
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?
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.