Introduction

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 a 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

ComponentsValueQty
Arduino UNO-1
USB 2.0 cable type A/B-1
Piezo Buzzer-1
Door Sensor-1
9V Power Adapter for Arduino-1
Breadboard-1
Jumper Wires-1

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-

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