As it is used in quizzes event, when one of the buttons is pressed first the other button when pressed does not sound. The buttons used is 4 push button . Bell (Speaker) and lights used as a marker which button is pressed first. Relay as driver light and bell. Arduino UNO as its processor.
Hardware Requirement
- Relay Module 5V with 4 Channel
- Arduino UNO
- Push Button
- A Buzzer
- Power supply +5 Volt
- Jumper
Relay Module with 4 Channel | Source
Block Diagram
Schematic
Arduino - Button Wiring
Arduino - Relay Wiring
Arduino - Buzzer Wiring
Source Code/Sketch
const int tombolA = 2;
const int tombolB = 3;
const int tombolC = 4;
const int tombolD = 5;
const int lampuA = 8;
const int lampuB = 9;
const int lampuC = 10;
const int lampuD = 11;
const int bel = 12;
void setup(){
for(char i=2; i<6; i++){
pinMode(i, INPUT);
digitalWrite(i,HIGH);
}
for(char i=8; i<13; i++){
pinMode(i, OUTPUT);
digitalWrite(i,LOW);
}
}
void loop(){
if(digitalRead(tombolA)==LOW){
digitalWrite(bel,HIGH);
digitalWrite(lampuA,HIGH);
delay(500);
while(!digitalRead(tombolA));
digitalWrite(bel,LOW);
digitalWrite(lampuA,LOW);
}
else if(digitalRead(tombolB)==LOW){
digitalWrite(bel,HIGH);
digitalWrite(lampuB,HIGH);
delay(500);
while(!digitalRead(tombolB));
digitalWrite(bel,LOW);
digitalWrite(lampuB,LOW);
}
else if(digitalRead(tombolC)==LOW){
digitalWrite(bel,HIGH);
digitalWrite(lampuC,HIGH);
delay(500);
while(!digitalRead(tombolC));
digitalWrite(bel,LOW);
digitalWrite(lampuC,LOW);
}
else if(digitalRead(tombolD)==LOW){
digitalWrite(bel,HIGH);
digitalWrite(lampuD,HIGH);
delay(500);
while(!digitalRead(tombolD));
digitalWrite(bel,LOW);
digitalWrite(lampuD,LOW);
}
}
const int tombolB = 3;
const int tombolC = 4;
const int tombolD = 5;
const int lampuA = 8;
const int lampuB = 9;
const int lampuC = 10;
const int lampuD = 11;
const int bel = 12;
void setup(){
for(char i=2; i<6; i++){
pinMode(i, INPUT);
digitalWrite(i,HIGH);
}
for(char i=8; i<13; i++){
pinMode(i, OUTPUT);
digitalWrite(i,LOW);
}
}
void loop(){
if(digitalRead(tombolA)==LOW){
digitalWrite(bel,HIGH);
digitalWrite(lampuA,HIGH);
delay(500);
while(!digitalRead(tombolA));
digitalWrite(bel,LOW);
digitalWrite(lampuA,LOW);
}
else if(digitalRead(tombolB)==LOW){
digitalWrite(bel,HIGH);
digitalWrite(lampuB,HIGH);
delay(500);
while(!digitalRead(tombolB));
digitalWrite(bel,LOW);
digitalWrite(lampuB,LOW);
}
else if(digitalRead(tombolC)==LOW){
digitalWrite(bel,HIGH);
digitalWrite(lampuC,HIGH);
delay(500);
while(!digitalRead(tombolC));
digitalWrite(bel,LOW);
digitalWrite(lampuC,LOW);
}
else if(digitalRead(tombolD)==LOW){
digitalWrite(bel,HIGH);
digitalWrite(lampuD,HIGH);
delay(500);
while(!digitalRead(tombolD));
digitalWrite(bel,LOW);
digitalWrite(lampuD,LOW);
}
}
No comments:
Post a Comment