Arduino Door Alarm Sensor using Magnetic Reed Switch

9,063 views

Introduction

Most of the time it happens our children open the fridge door and leave 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.

This Project is sponsored by PCBWay. They have an open-source community, people can share their design projects with each other. Moreover, every time people place an order for your board, PCBWay will donate 10% of the cost of PCB to you, for your contribution to the Open Source Community.

Hardware Components

You will require the following hardware for Arduino-Door Sensor – Piezo Buzzer

S.noComponentValueQty
1.Arduino UNO1
2.USB 2.0 cable type A/B1
3.Piezo Buzzer1
4.Door Sensor1
5.Power Adapter for Arduino9V1
6.Breadboard1
7.Jumper Wires1

Steps for Making Arduino Door Alarm

  • Connect Arduino to PC via USB cable
  • Open Arduino IDE, select the right board and port
  • Copy the above code and open it with Arduino IDE
  • 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.

Arduino-Door Sensor - Piezo Buzzer - Circuit

Wiring / Connections

ArduinoDoor SensorPiezo Buzzer
D3+ve Pin
GNDPin 2GND
D13Pin 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.