Window Guard is an intruder alarm circuit. This circuit rings an alarm when somebody opens your window from outside. I have made this circuit and tested it on my own bedroom 's window. This circuit is based on Arduino UNO. Arduino UNO is the brain of the circuit. In the sensor part, I have used Avoidance sensor. The avoidance sensor is basically a pair of IR transmitter and receiver. This sensor is widely used in obstacle avoiding robots, Automatic hand sanitizer dispensers, Automatic trash bins etc.
Working principle:
The output of the avoidance sensor is digital. That means, it can output logic LOW (0) or logic HIGH (1).
I adjusted the two volume POTs in such a way, that when there was something/someone in front of the sensor, the output was LOW . And when there was no obstacle in front of the sensor, the output was HIGH. So when I placed it in front of a closed window, the sensor's output was LOW, as soon as the window was opened, the output changed to HIGH.
The output pin of the sensor was connected to Digital pin#2 of the Arduino UNO. By reading the pin continuously, Arduino could understand whether the window is closed or open.
As the acting part of my circuit, I used a buzzer. When the window was closed, that means when the sensor's output was LOW, the buzzer was quiet. But, as soon as the window opened a little bit, the buzzer started making sound, thus making everyone alert.
Components:
1 x Arduino UNO
1 x Avoidance sensor
1 x Buzzer
1 x 2S Li-ion battery pack (You can use any Arduino compatible battery)
Connection:
Arduino Uno | Avoidance sensor |
VCC | + |
GND | - |
2 | D0 |
Arduino UNO | Buzzer |
11 | + |
GND | _ |
Code:
// constants won't change. They're used here to set pin numbers:
const int sensorPin = 2; // the number of the sensor pin
const int buzzerPin = 11; // the number of the buzzer pin
// variables will change:
int sensorState = 0; // variable for reading the sensorpin
void setup() {
// initialize the singnal pin as an output:
pinMode(buzzerPin, OUTPUT);
// initialize the sensor pin as an input:
pinMode(sensorPin, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
// read the state of the sensorpin:
sensorState = digitalRead(sensorPin);
// check if the window is open. If so, the buzzerpin will be High;otherwise, the Buzzerpin will be low.
//When the window is closed, the sensor Output will be low, when the window is opened, the output will be high.
Serial.println(sensorState);
delay(100);
if (sensorState == LOW) {
// turn sensor off:
digitalWrite(buzzerPin, LOW);
} else {
// turn sensor on:
digitalWrite(buzzerPin, HIGH);
}
}