An object-detection alarm with an ultrasonic sensor and buzzer
A beginner IoT circuit: an HC-SR04 distance sensor watches the space in front of it, and a buzzer sounds the moment something enters range.
What you'll need
- 01 Arduino Uno (or compatible board)
- 02 HC-SR04 ultrasonic distance sensor
- 03 Active buzzer
- 04 Breadboard
- 05 Jumper wires
Wiring
Keep the sensor and buzzer on separate pins so their signals don't interfere.
| Component pin | Connects to |
|---|---|
| Sensor VCC | Arduino 5V |
| Sensor GND | Arduino GND |
| Sensor TRIG | Digital pin 9 |
| Sensor ECHO | Digital pin 10 |
| Buzzer + | Digital pin 8 |
| Buzzer − | Arduino GND |
Build steps
-
Wire the circuit
Place the sensor and buzzer on the breadboard and connect them to the Arduino following the pin table above.
-
Install the Arduino IDE
Download it from arduino.cc, then connect your board over USB.
-
Select your board and port
In the IDE, set Tools > Board to your Arduino model, and Tools > Port to the port it's connected on.
-
Upload the sketch
Paste in the code below and click Upload. Wait for "Done uploading" in the status bar.
-
Test it
Open the Serial Monitor to watch live distance readings, then wave a hand in front of the sensor — the buzzer should sound.
The code
tone(BUZZER_PIN, 1000) and noTone(BUZZER_PIN) to get an audible pitch.Wrap-up
That's the whole circuit: the sensor pings continuously, the Arduino measures how long the echo takes to bounce back, and the buzzer fires the instant something crosses the threshold distance. From here it's easy to extend — log detections over time, add an LED, or swap the buzzer for a relay to trigger something bigger.
No comments:
Post a Comment