Project showcase
Door Alarm With Ultrasonic Sensor

Door Alarm With Ultrasonic Sensor

This project uses an ultrasonic sensor to "sense" if the door opens or closes.

  • 10,030 views
  • 3 comments
  • 14 respects

Components and supplies

About this project

I decided to make this project so I could know when somebody opens a door. As my first project, I realize that this is not the simplest way to do this but I really enjoyed doing it.

Code

distance alarmArduino
An alarm that measures the distance between the wall and door nob or door.
const int TrigPin = 2;
const int EchoPin = 3;
const int Data = 8;
float cm;
void setup()
{
  Serial.begin(9600);
  pinMode(TrigPin, OUTPUT);
  pinMode(EchoPin, INPUT);
  pinMode(Data,OUTPUT);
}
void loop()
{
  digitalWrite(TrigPin, LOW);       
  delayMicroseconds(2);
  digitalWrite(TrigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(TrigPin, LOW);
  cm = pulseIn(EchoPin, HIGH) / 58.0; //The echo time is converted into cm
  cm = (int(cm * 100.0)) / 100.0;     //Keep two decimal places
  Serial.println();
  if(cm<15){ //if you are puting the sensor behind the door use ">" sysmbole insted of ">" p.s. make sure tat the door nob is less than 15 cm away
      digitalWrite(Data,HIGH);
      delay(200);
      Serial.print("Door closed");
    }
    else
    {
      digitalWrite(Data,LOW);
      delay(200);  
      Serial.print("Door open");
    }
  delay(200);
}

Schematics

distance warnig
Distance warning ugipseoajm

Comments

Author

Mattg
MattG
  • 1 project
  • 2 followers

Additional contributors

  • The schematic by Smraza Keen

Published on

January 4, 2018

Members who respect this project

DefaultPhoto

and 13 others

See similar projects
you might like

Similar projects you might like

Ultrasonic Sensor with LCD Display Using 433MHz

Project tutorial by mcharrison500

  • 2,829 views
  • 0 comments
  • 15 respects

Ultrasonic Sensor with Alarm, LCD and Temperature

Project tutorial by MichDragstar

  • 4,648 views
  • 7 comments
  • 19 respects

Complete Digital Clock Including Alarm and Motion Sensor

Project tutorial by LAGSILVA

  • 12,678 views
  • 11 comments
  • 50 respects

IOT - Smart Jar Using ESP8266, Arduino and Ultrasonic Sensor

Project tutorial by Team Smazee

  • 6,216 views
  • 4 comments
  • 12 respects
Add projectSign up / Login