IR Module Based Security Alarm for Burglar Detection

About The Project

In this project, we will learn how to create a burglar detection system using Arduino and IR sensor modules. The system utilizes two IR sensors placed a specific distance apart. When both sensors detect an object simultaneously, indicating that a person (or burglar) is passing through, the system will trigger an alarm. This setup helps identify intruders by detecting simultaneous interruptions in the IR beams from both sensors.

IR Sensor Module

An IR (Infrared) sensor module is a device that detects infrared light to identify objects, measure distances, or detect movement. It typically consists of an IR LED (emitter) and an IR photodiode (receiver) arranged in a way that the IR light emitted by the LED can be reflected back to the receiver when an object is in front of it.

When an object comes within the sensor’s range, the IR light emitted by the LED reflects off the object and is detected by the photodiode. This causes the sensor to change its output, which can then be read by a microcontroller.

Circuit Wiring

Program Code

C++
// www.matthewtechub.com
// IR Sensor-Buzzer
// burglar alarm
const int sensor1Pin = 2; 
const int sensor2Pin = 3;
const int buzzerPin = 4; 

// Variables to store sensor states
int sensor1State = 0;
int sensor2State = 0;

void setup() {
  // Initialize the digital pins as inputs and the buzzer pin as output
  pinMode(sensor1Pin, INPUT);
  pinMode(sensor2Pin, INPUT);
  pinMode(buzzerPin, OUTPUT);
  
  // Initialize serial communication (optional)
  Serial.begin(9600);
}

void loop() {
  // Read the current state of both IR sensors
  sensor1State = digitalRead(sensor1Pin);
  sensor2State = digitalRead(sensor2Pin);
  
  // Check if both sensors detect an object simultaneously
  if (sensor1State == LOW && sensor2State == LOW) {
    // Sound the alarm (buzzer)
    digitalWrite(buzzerPin, HIGH); // Turn on the buzzer
    delay(1000); // Buzzer sounds for 1 second
    digitalWrite(buzzerPin, LOW);  // Turn off the buzzer
    
    // Wait until the object passes completely before continuing
    while(digitalRead(sensor1Pin) == LOW || digitalRead(sensor2Pin) == LOW) {
      // Do nothing, just wait
    }
  }
  
  // Short delay to debounce the sensor readings
  delay(50);
}

This Arduino program uses two IR sensors to detect an intruder. When both sensors detect an object simultaneously, it triggers a buzzer alarm.

Code Explanation

Pin Definitions

C++
   const int sensor1Pin = 2; 
   const int sensor2Pin = 3;
   const int buzzerPin = 4;
  • `sensor1Pin` and `sensor2Pin` are the digital pins connected to the two IR sensors.
  • `buzzerPin` is the digital pin connected to the buzzer.

Variables to Store Sensor States

C++
   int sensor1State = 0;
   int sensor2State = 0;
  • These variables store the current states of the IR sensors. `0` represents the sensor reading a LOW state, which typically means an object is detected (assuming active LOW configuration).

Setup Function

C++
   void setup() {
     // Initialize the digital pins as inputs and the buzzer pin as output
     pinMode(sensor1Pin, INPUT);
     pinMode(sensor2Pin, INPUT);
     pinMode(buzzerPin, OUTPUT);
     
     // Initialize serial communication (optional)
     Serial.begin(9600);
   }
  • `pinMode(sensor1Pin, INPUT);` and `pinMode(sensor2Pin, INPUT);` set the IR sensor pins as input pins.
  • `pinMode(buzzerPin, OUTPUT);` sets the buzzer pin as an output pin.
  • `Serial.begin(9600);` initializes serial communication at 9600 baud (not used in this example but useful for debugging).

Loop Function

C++
   void loop() {
     // Read the current state of both IR sensors
     sensor1State = digitalRead(sensor1Pin);
     sensor2State = digitalRead(sensor2Pin);
     
     // Check if both sensors detect an object simultaneously
     if (sensor1State == LOW && sensor2State == LOW) {
       // Sound the alarm (buzzer)
       digitalWrite(buzzerPin, HIGH); // Turn on the buzzer
       delay(1000); // Buzzer sounds for 1 second
       digitalWrite(buzzerPin, LOW);  // Turn off the buzzer
       
       // Wait until the object passes completely before continuing
       while(digitalRead(sensor1Pin) == LOW || digitalRead(sensor2Pin) == LOW) {
         // Do nothing, just wait
       }
     }
     
     // Short delay to debounce the sensor readings
     delay(50);
   }
  • `sensor1State = digitalRead(sensor1Pin);` and `sensor2State = digitalRead(sensor2Pin);` read the states of the IR sensors.
  • The `if` condition checks if both sensors are detecting an object (LOW state). If true, the code turns on the buzzer for 1 second and then turns it off.
  • The `while` loop waits until both sensors no longer detect the object before continuing. This prevents the buzzer from sounding continuously while the object is still in the sensor range.

`delay(50);` adds a short delay to debounce the sensor readings, reducing the chance of false triggers due to rapid changes in sensor input.

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!