Burglar Alarm System — Arduino
I successfully crafted a burglar alarm system using an Arduino Uno, incorporating an ultrasonic sensor SR04 and a buzzer. The Arduino controlled the system, the ultrasonic sensor detected movement, and the buzzer sounded a robust alarm in response. This DIY creation represents a powerful fusion of technology and innovation for enhanced home security.
Necessary Components
- Arduino Board
2. Ultrasonic Sensor (SR04)
3. Buzzer
Get damian-chamel’s stories in your inbox
Join Medium for free to get updates from this writer.
4. LED light
5. 100 Ω Resistor
Schematic Diagram
Arduino Program (source code)
// Arduino pin configuration
#define TRIG_PIN 13
#define ECHO_PIN 12
#define IND_LED 11
#define BUZ_PIN 9
bool entered;
long duration, distance;
void setup() {
Serial.begin(9600);
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
pinMode(IND_LED, OUTPUT);
pinMode(BUZ_PIN, OUTPUT);
entered = false;
}
void loop() {
// Clear sensor
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
// Generate 10 microseconds pulse to the sensor
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
duration = pulseIn(ECHO_PIN, HIGH); // in microseconds
distance = (duration / 2) / 29.1; // in cm
// Assuming door width is 10cm (If someone crossed the 10cm range, alarm will be raised)
if (distance < 10) {
entered = true;
}
// Alarm raises when someone crossed the range
if (entered) {
// Turn on alarm light
digitalWrite(IND_LED, HIGH);
// Generate 2KHz buzzer noise
tone(BUZ_PIN, 2000);
delay(500);
digitalWrite(IND_LED, LOW);
noTone(BUZ_PIN);
}
Serial.print(distance);
Serial.println(" cm");
delay(500);
}Link to the simulation









