Most of the time it happens our children open the fridge door and left it open Also sometimes we need more security in our garages and doors so this DIY Door Alarm is useful in such kind of application. So Today we are going to make a simple “Door Alarm Sensor” using Arduino and a magnetic reed switch and buzzer. We use an atmega328p chip here in our designed PCB.
Overall circuit working is simple. It simply beeps a buzzer whenever the door is left open. So let get’s started making it without wasting time.
[jlcpcb_1]
Hardware Components
You will require the following hardware for Arduino-Door Sensor – Piezo Buzzer
Click the Upload button on Arduino IDE to upload code to Arduino
Move the magnet close to the reed switch and then move it far from the reed switch.
Listen to the piezo buzzer’s sound
Schematic
Make connections according to the circuit diagram given below.
Wiring / Connections
Arduino
Door Sensor
Piezo Buzzer
D3
–
+ve Pin
GND
Pin 2
GND
D13
Pin 1
–
Installing Arduino IDE
First, you need to install Arduino IDE Software from its official website Arduino. Here is a simple step-by-step guide on “How to install Arduino IDE“.
Arduino Code
Now copy the following code and upload it to Arduino IDE Software.
const int DOOR_SENSOR_PIN = 13; // Arduino pin connected to door sensor's pin
const int BUZZER_PIN = 3; // Arduino pin connected to Buzzer's pin
int doorState;
void setup() {
Serial.begin(9600); // initialize serial
pinMode(DOOR_SENSOR_PIN, INPUT_PULLUP); // set arduino pin to input pull-up mode
pinMode(BUZZER_PIN, OUTPUT); // set arduino pin to output mode
}
void loop() {
doorState = digitalRead(DOOR_SENSOR_PIN); // read state
if (doorState == HIGH) {
Serial.println("The door is open");;
digitalWrite(BUZZER_PIN, HIGH); // turn on Piezo Buzzer
} else {
Serial.println("The door is closed");
digitalWrite(BUZZER_PIN, LOW); // turn off Piezo Buzzer
}
}
Applications
Security Door
Malls, Shops Banks, etc
Conclusion
We hope you have found this Arduino Door Sensor Alarm very useful. If you feel any difficulty in making it feel free to ask anything in the comment section.