Ramesh
Published © GPL3+

Bluetooth Controlled Automatic Door using PIR Sensor

Here to learn How to Make an Bluetooth controlled Automatic Door Opening and closing System Using Arduino, PIR Sensor HC-SR501 and android a

IntermediateProtip4 hours2,016
Bluetooth Controlled Automatic Door using PIR Sensor

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
HC-05 Bluetooth Module
HC-05 Bluetooth Module
×1

Software apps and online services

MIT App Inventor
MIT App Inventor

Hand tools and fabrication machines

10 Pc. Jumper Wire Kit, 5 cm Long
10 Pc. Jumper Wire Kit, 5 cm Long

Story

Read more

Schematics

Circuit diagram

Code

Bluetooth Controlled Automatic door

Arduino
#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);

  }

        

}

Credits

Ramesh

Ramesh

15 projects • 18 followers

Comments