Security has always been a major concern for all of us and there are many Hi tech and IoT based security and surveillance system are available in the market. Intruder or Burglar Alarm is one of the classic and popular project among the Electronics students and hobbyists. We have also built many Burglar Alarms based on various technologies:
Today we are adding one more Security Alarm in our list which is based on Ultrasonic Sensor. ThisArduino Controlled Door alarm can be installed near the door to detect the presence of anybody at the door. Whenever somebody comes in the range of Ultrasonic sensor, buzzer starts beeping. You can adjust the sensor detection range according to your door. This system can also serve the purpose of Motion Detector.
Ultrasonic Sensor Module:
Ultrasonic sensor HC-SR04 is used here to detect the presences of any person at the door. The sensor module consists of ultrasonic transmitter, receiver and the control circuit. Ultrasonic Sensor consists of two circular eyes out of which one is used to transmit the ultrasonic wave and the other to receive it.
We can calculate the distance of the object based on the time taken by ultrasonic wave to return back to the sensor. Since the time and speed of sound is known we can calculate the distance by the following formulae.
- Distance = (Time x Speed of Sound) / 2
The value is divided by two since the wave travels forward and backward covering the same distance. But in this project, we have used NewPing.h library, and this library takes care of this calculation and we just need to use some key words, explanation is given in programing section below.
Check the below project to measure the distance of any object and to properly understand the Ultrasonic sensor working:
Circuit Diagram and Explanation:
Circuit connections for this Ultrasonic Alarm are very simple. Trigger pin of ultrasonic sensor is connected to pin no. 12 of Arduino and Echo pin of sensor is connected to pin no 11 of Arduino. Vcc of sensor is connected to 5V pin of Arduino and GND of sensor is connected to GND of Arduino. One pin of buzzer is connected to GND of Arduino and the other pin is connected to 8th pin of Arduino.
Working this Arduino Door Alarm is very easy. Whenever anyone comes in the path/range of Ultrasonic Sensor, microcontroller detects the distance of object from the sensor and if the object is in the defined range, it sends the High signal to the buzzer and buzzer starts beeping.
#define TRIGGER_PIN 12 #define ECHO_PIN 11 #define MAX_DISTANCE 500
if ((sonar.ping_result / US_ROUNDTRIP_CM) < 50) flag = 1; else if ((sonar.ping_result / US_ROUNDTRIP_CM) > 50) flag = 0;