Proximity Detector Alarm
This tutorial will teach you how to make a proximity/motion detector. (Can be done by following the diagram and copying the code)
Start by connecting the 5V power on the Arduino to the + rail of the breadboard and ground to the - rail. Next, place the ultrasonic sensor on the breadboard. Make sure it has space behind it for connections. Connect "Vcc" to the power rail and "Gnd" to the negative rail. Connect "Trig" to pin 13 and connect "Echo" to pin 12. Next place a LED on the breadboard. Connect the long side to pin 10 and the other side to the negative rail. Lastly, connect the the positive wire of the speaker to pin 11 and the negative wire to the negative rail.
Upload the code to the Arduino. Be sure to set the correct distance in the code for you needs. (I set it to 192 as I wanted it to beep when an object got closer than 192 cm)
You are now finished :)
EXPANDED TECHNICAL DETAILS
Proximity Sensing Mechanism
The core of this alarm is the HC-SR04 Ultrasonic Sensor. It utilizes sound waves to detect objects by emitting an ultrasonic burst (40kHz) and timing the interval until the echo is received.
- Accuracy: The sensor is capable of non-contact measurement with an accuracy of up to 3mm, provided the surface of the object is relatively flat and hard.
Feedback Loop & Alerting
The firmware implement a simple but effective distance-to-frequency mapping:
- Distance Calculation:
Distance = (Duration * 0.034) / 2. - Dynamic Alerting: As an object moves closer to the sensor, the Arduino increases the frequency of the active buzzer beeps and the flash rate of the LED. This provides an intuitive "sonar-like" interface where the intensity of the alarm is inversely proportional to the obstacle distance.