Home / Home made Projects / Arduino Projects / Ultrasonic sensor based Automatic Door using Arduino

Ultrasonic sensor based Automatic Door using Arduino

This article is about the application of HC SR04 ultrasonic range sensor to design automatic door using Arduino controller. All the associated details like working principle, connection diagram and program for this project are presented as well as explained.


In present days, the world is moving towards automation. Previously the doors were used to be manual however due to the increase in users, automatic doors were introduced. Presently, the automatic doors are mostly based on weight sensor. When user steps near the door, the weight sensor senses the person and opens the door. The main drawback of these doors is that (in most cases) users have to stop for a moment before the door opens. This little delay can cause congestion if the users are in great numbers. Therefore this article introduces a fairly new concept of automatic doors which are based upon the ultrasonic sensors. The advantage of ultrasonic sensor over weight sensor is that they can sense the people at far distance.

Working of the ultrasonic sensor:

Ultrasonic range finder works in the similar fashion as the sonar used by ships and submarines. The sensor sends the sound wave and it is reflected by the object it hits. By using the speed of the sound and time of travel, distance of the object can be found.  For detail working and understanding of ultra sonic range finder pleasse click HC-SR04 ultrasonic sensor ranger finder


The calculation of Ultrasonic range finder is based upon the basic formula of speed/velocity.

S=V\ \times \ t

Where S= Distance

V= Velocity

T= time

If any two quantaties in eq(1) are known the third can be calaulated.

Ultrasonic sensor utilizes the sound to measure the distance. The speed of sound in air is constant which is 343m/s in dry air at 20 ºC.

Converting value from (m/s) to smaller units (cm/microseconds)

343{m}/{s\ }\ =\ \ \frac{34300\ cm}{1,000,000\ us}=\ \ 0.0343\ {cm}/{us\ }

0.0343 is a fractional value. For ease in programing, we convert it into whole numbers by taking its reciprocal

0.0343{cm}/{us}=\frac{1}{0.0343\ }=29.15\ {us}/{cm}

It means that in 29.15 us, sound travel distance of 1cm. Similarly 291.5us will correspond to 10cm distance.

Working Principle of automatic door using Arduino

The system will work as follows.

  • If there is no passenger or object in vicinity of door upto 18inch (1.4 feet), it will remain close.
  • If there is any object or person in vicinity of 18 iches, (1.5 feet), the door will open automatically.
  • The door will remain open until that person stays in vicinity of door upto 18inches.
  • The system is setup with one sensor so it can work for one side of door for the purpose of simplicity. It can be extended by one more sensor using same process for other side passengers.

Schematic Diagram

Main electrical components for this project are

  • Servo motor
  • Arduino
  • HC-SR04 Ultrasonic sensor
  • LCD (2×16)

The key component being utilized in automatic door using Arduino project is the ultrasonic sensor HC-SR-04. This module utilizes four pins of the Arduino board for its interfacing. Pin names and function of each pin of HC-SR04 are as follows.simulation result automatic door 1Vcc: It connect 5V of the power supply to the HC-SR04 sensor.

Trig: A triggering pulse of 10us is sent on this so that sensor goes into ranging mode to detect object.

Echo: This pin send sound waves after triggering and waits for its echo. If echo is received, it means object is detected.

Gnd: It is used to ground (provide 0 V to) the sensor.

Test Pin (For simulation purpose only) : To simulate HC-SR04 ultrasonic sensor, a new pin called test pin is added to the simulation model. The input to this pin is voltage. Higher voltage will means more distance from the sensor as a result echo will be received after considerable delay. Less voltage implies to near object, less delay in receiving echo.

The simulation model of HC-SR04 is not readily available in proteus library. It can be found in


As already explained in working principle that if object is detected, the door will unlock or open. The status of the door will be displayed on LCD screen. The servo will rotate to open door physically. If no object is detected, the servo will rotate to close the door and status will be displayed on LCD screen.

Simulation Results.

The proposed automatic door using Arduino is tested in ISIS Proteus. Initially the voltage is kept high such that distance calculated by automatic door using ultrasonic senor is more than 18inches. The response of ultrasonic sensor based automatic door is shown in the figure.
Connection diagram of automatic door using arduino

The scope shows two signals. Yellow signal shows the triggering signal given by arduino to the sensor while the blue signal shows the delay between the trigger and receiving of echo. The delay consist of almost 6.5 squares which is equal to the 6.5ms. This time corresponds to 18.2 inches. So the door is closed.

Now the object is brought closer by reducing the voltage (in simulation only). Delay consists of 2.5ms which corresponds to 7 inches (less than 18) as a result, the door is unlocked.

simulation result automatic door 2


#include <LiquidCrystal.h> // Libraries
#include <Servo.h>
const int pingPin = 7; // Trigger Pin of Ultrasonic Sensor
const int echoPin = 6; // Echo Pin of Ultrasonic Sensor
const int debug = 0; // If we want to debug put =1
LiquidCrystal lcd(12,11,5,4,3,2); //pin of Arduino
unsigned int lock=0; // Status latch
boolean button; // Button pressed
Servo myservo; // type Servo
void setup(){ // SETUP
  pinMode(6, INPUT);   // button
  pinMode(8, OUTPUT);
  digitalWrite(8, HIGH);
  myservo.attach(9);   // Port 7
  myservo.write(90);   // Lock by default
// latch.write(degrees)
// 90 = Closed
// LCD
  lcd.begin(16,2); // 16 characters 2 rows
  lcd.setCursor(0,1); // move one line down to write
  lcd.print(“Auto Door System”);
void loop(){
  button = 0; // As default
  lcd.clear(); // Clean Screen
  lcd.setCursor(0,0); // beginning
long duration, inches, cm;
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
digitalWrite(pingPin, HIGH);
digitalWrite(pingPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
Serial.print(“in, “);
  if (inches <= 18){   // If pulse
    button = true;
    lock = 0;
  if ( lock == 0){
    myservo.write(-90); // put degrees = open door
  if (inches >= 18){
    button = false;
    lock = 1;
  if ( lock == 1)
      myservo.write(90);       //closes the door
  // Log
  if(debug == 1){
//My function print lcd
void print_status(char* text){
long microsecondsToInches(long microseconds)
return microseconds / 74 / 2;
 long microsecondsToCentimeters(long microseconds)
return microseconds / 29 / 2;

About Syed Noman ud din

Syed Noman ud din is an Electrical Engineer and working in Industry from last 3 years. He writes technical articles for electrical and electronic engineers. He has also published several research publications in renowned international journals.

Check Also

Arduino based power meter using Emon Library

This article assist the user to construct home made Arduino based power meter. The connection …

Leave a Reply

Your email address will not be published. Required fields are marked *