Arduino Hands-free Buzzer
Hello people from the world! It is I, Sreecharan Chakka, a 7th grader from the planet earth.
All of you used a buzzer before in your life right? You press on the big red button and it buzzes for you. Well, during this situation, that kind of buzzer is not a good idea if lots of people are touching it like the buzzers that are used in Jeopardy! That is why I created this: Hands-free buzzer made with Arduino.
All the materials needed:
- Ultrasonic Sound Sensor HC-SR04 x2 Ultrasonic Sound Sensor
- Arduino Mega 2560 x1 Arduino Mega 2560
- Buzzer x1 (any one should work fine)
- LED x2 (Preferably 2 colors) LED's
- Jumper wires
- Resistors x2 220Ω
Making the Circuit
First, we have to build the circuit. Here is the wiring:
- Ultrasonic Sensor #1: VCC-5V; TRIG-10; ECHO-9; GND-GND
- Ultrasonic Sensor #2: VCC-5V; TRIG-3; ECHO-4; GND-GND
- LED #1: Anode/Positive-2; Cathode/Negative-GND(with resistor)
- LED #2: Anode/Positive-8: Cathode/Negative-GND(with resistor)
- Buzzer: Positive-7; Negative-GND
That's all the wiring. Phew!
Adding the Code!
The code is very simple. When the object is 10 cm above the ultrasonic sensors, the led will light up and the buzzer will buzz.
Here is the code:
#define trigPin 10 #define echoPin 9 #define trigPin2 3 #define echoPin2 4 #define led 8 #define led2 2 #define buzzer1 7 void setup(){ Serial.begin (9600); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); pinMode(led, OUTPUT); pinMode(trigPin2, OUTPUT); pinMode(echoPin2, INPUT); pinMode(led2, OUTPUT); pinMode(buzzer1, OUTPUT); } void loop(){ long duration1, distance1; digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); duration1 = pulseIn(echoPin, HIGH); distance1 = (duration1/2) / 29.1; if (distance1 < 10){ digitalWrite(buzzer1, HIGH); digitalWrite(led,HIGH); delay(2000); digitalWrite(buzzer1, LOW); } else { digitalWrite(led,LOW); } Serial.print(distance1); Serial.println(" cm"); delay(500); // you don't actually need the serial print. Either way it works with or without the serial print long duration2, distance2; digitalWrite(trigPin2, LOW); delayMicroseconds(2); digitalWrite(trigPin2, HIGH); delayMicroseconds(10); digitalWrite(trigPin2, LOW); duration2 = pulseIn(echoPin2, HIGH); distance2 = (duration2/2) / 29.1; if (distance2 < 10){ digitalWrite(buzzer1, HIGH); digitalWrite(led2,HIGH); delay(2000); digitalWrite(buzzer1, LOW); } else { digitalWrite(led2,LOW); } Serial.print(distance2); Serial.println(" cm"); delay(500); }
Downloads
We Are Done!
We are done! Now you can use a hands-free buzzer to avoid contact with an actual buzzer!
Hope you liked this project. If you have any questions, just post it in the comments. Until then, stay safe and goodbye!