top of page

Bluetooth Controlled Automatic Door using PIR Sensor

Updated: Jul 13, 2021


Here to learn How to Make an Bluetooth controlled Automatic Door Opening and closing System Using Arduino, PIR Sensor HC-SR501 and android application, which automatically opens and closes the door by detecting a person and controlled by android app.

You might have seen Automatic Door Opener Systems at office, shopping malls, cinemas, hospitals etc. where, as soon as a person approaches the door (at about 2 or 3 feet), the door automatically slides open. And after some time (about 5 to 10 seconds), the door closes by sliding in the reverse direction.

Such Automatic Door Opener Systems are very useful as you do not need a person to standby the door and open it whenever a guest comes. Also, since the doors are opened and closed only when a person approaches the door. This automatic control and Stop control using bluetooth HC-05 through android application.


So, In order to understand the potential of this concept, we have implemented a simple Automatic Door Opener System using Arduino and PIR HC-SR501 Sensor, Servo and Bluetooth.


Circuit Diagram

Components Required

Arduino Nano - 1 no

Bluetooth module HC-05 - 1no

PIR HC-SR501sensor - 1 no

Servo mini - 1 no

HC-SR501 PIR sensor

The PIR sensor stands for Passive Infrared sensor. It is a low cost sensor which can detect the presence of Human beings or animals. This sensor has three output pins Vcc, Output and Ground

The module can be powered from voltage 4.5V to 20V but, typically 5V is used. Once the module is powered allow the module to calibrate itself for few minutes, 2 minutes is a well settled time. Then observe the output on the output pin. Before we analyze the output we need to know that there are two operating modes in this sensor such as Repeatable(H) and Non- Repeatable(L) and mode. The Repeatable mode is the default mode. The output of the sensor can be set by shorting any two pins on the left of the module.

Repeatable(H) mode (used in this Project)

In Repeatable(H) mode the output pin Dout will go high (3.3V) when a person is detected within range and goes low after a particular time (time is set by “Off time control” potentiometer). In this mode the output pin will go high irrespective of whether the person is still present inside the range or has left the area. The sensitivity can be set using the “sensitivity control” potentiometer

Non- Repeatable(L) mode

In “I” mode the output pin Dout will go high (3.3V) when a person is detected within range and will stay high as long as he/she stays within the limit of the Sensors range. Once the person has left the area the pin will go low after the particular time which can be set using the potentiometer. The sensitivity can be set using the “sensitivity control” potentiometer


There are two important materials present in the sensor one is the pyroelectric crystal which can detect the heat signatures from a living organism (humans/animals) and the other is a Fresnel lenses which can widen the range of the sensor. Yes the white colour things is just a lense that is used to widen the range of the sensor, if you remove the lense you can find the Pyroelectric sensor inside it covered inside a protective metal casing as shown above.

PIR Sensor Applications

  • Automatic Street/Garage/Warehouse or Garden Lights

  • Burglar Alarms

  • Security cams as motion detectors

  • Industrial Automation Control

Download Datasheet


Bluetooth HC-05 Module

HC-05 is a Bluetooth module which is designed for wireless communication. This module can be used in a master or slave configuration. Bluetooth serial modules allow all serial enabled devices to communicate with each other using Bluetooth.

It has 6 pins,

1.Key/EN: It is used to bring Bluetooth module in AT commands mode. If Key/EN pin is set to high, then this module will work in command mode. Otherwise by default it is in data mode. The default baud rate of HC-05 in command mode is 38400bps and 9600 in data mode.


HC-05 module has two modes,

Data mode: Exchange of data between devices.

Command mode: It uses AT commands which are used to change setting of HC-05. To send these commands to module serial (USART) port is used.


2. VCC: Connect 5 V or 3.3 V to this Pin.

3. GND: Ground Pin of module.

4. TXD: Transmit Serial data (wirelessly received data by Bluetooth module transmitted out serially on TXD pin)

5. RXD: Receive data serially (received data will be transmitted wirelessly by Bluetooth module).

6. State: It tells whether module is connected or not.


HC-05 module Information

HC-05 has red LED which indicates connection status, whether the Bluetooth is connected or not. Before connecting to HC-05 module this red LED blinks continuously in a periodic manner. When it gets connected to any other Bluetooth device, its blinking slows down to two seconds.

This module works on 3.3 V. We can connect 5V supply voltage as well since the module has on board 5 to 3.3 V regulator.

As HC-05 Bluetooth module has 3.3 V level for RX/TX and microcontroller can detect 3.3 V level, so, no need to shift transmit level of HC-05 module. But we need to shift the transmit voltage level from microcontroller to RX of HC-05 module.

HC-05 Default Settings

  • Default Bluetooth Name: “HC-05”

  • Default Password: 1234 or 0000

  • Default Communication: Slave

  • Default Mode: Data Mode

  • Data Mode Baud Rate: 9600, 8, N, 1

  • Command Mode Baud Rate: 38400, 8, N, 1

  • Default firmware: LINVOR


Installing the Arduino Library

No special library for this project.


Subscribe and Download code.

Download Android application.

Download aia file for android development


Mobile Output

First open Mobile application BT PIR and select Bluetooth image, after that select bluetooth HC-05 device to connect and enter Password as mentioned above (0000 or 1234).

Arduino Code:

#include <Servo.h>

const int PIR_PIN = 8; // Arduino pin connected to motion sensor's pin

const int SERVO_PIN = 9; // Arduino pin connected to servo motor's pin


Servo servo; // create servo object to control a servo


// variables will change:

int angle = 0; // the current angle of servo motor

int lastMotionState; // the previous state of motion sensor

int currentMotionState; // the current state of motion sensor

char switchstate;

void setup() {

Serial.begin(9600); // initialize serial

pinMode(PIR_PIN, INPUT); // set arduino pin to input mode

servo.attach(SERVO_PIN); // attaches the servo on pin 9 to the servo object


servo.write(angle);

currentMotionState = digitalRead(PIR_PIN);

}


void loop() {

while(Serial.available()>0){

//code to be executed only when Serial.available()>0

/*Serial.available>0 is to check if there is any reading from the

HC-05 Bluetooth module.*/

switchstate = Serial.read();

/*The character we had declared earlier is now being assigned a value-

the value of whatever Serial.read() is.*/

//Serial.read() is to read the value coming from app.

Serial.print(switchstate);

//This will print the value onto the Serial monitor.

Serial.print("\n");

//This moves to the next line after every new line printed.

delay(15);

}

lastMotionState = currentMotionState; // save the last state

currentMotionState = digitalRead(PIR_PIN); // read new state


if (currentMotionState == LOW && lastMotionState == HIGH && (switchstate == 'A')) { // pin state change: LOW -> HIGH

// Serial.println("DOOR CLOSE");

Serial.println(currentMotionState);

servo.write(0);

}

//else

if (currentMotionState == HIGH && lastMotionState == LOW && (switchstate == 'A')) { // pin state change: HIGH -> LOW

// Serial.println("DOOR OPEN");

Serial.println(currentMotionState);

servo.write(90);

}

}

bottom of page