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.

  • 30,296 views
  • 10 comments
  • 31 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
  • 5 followers

Additional contributors

  • The schematic by Smraza Keen

Published on

January 4, 2018

Members who respect this project

DefaultPhotoDefaultDefaultDefaultDefaultDefaultDefault

and 23 others

See similar projects
you might like

Similar projects you might like

Ultrasonic Security System

Project tutorial by Ivan

  • 84,091 views
  • 52 comments
  • 170 respects

Getting Started with the HC-SR04 Ultrasonic sensor

by Isaac100

  • 135,800 views
  • 34 comments
  • 88 respects

Ultrasonic Sensor with Alarm, LCD and Temperature

Project tutorial by MichDragstar

  • 26,521 views
  • 10 comments
  • 36 respects

Ultrasonic Sensor with LCD Display Using 433MHz

Project tutorial by mcharrison500

  • 24,409 views
  • 1 comment
  • 32 respects

Complete Digital Clock Including Alarm and Motion Sensor

Project showcase by LAGSILVA

  • 31,589 views
  • 37 comments
  • 97 respects

IOT - Smart Jar Using ESP8266, Arduino and Ultrasonic Sensor

Project tutorial by Team Smazee

  • 16,910 views
  • 5 comments
  • 18 respects
Add projectSign up / Login