close
ARDUINO

PIR BASED GATE (SHUTTER) OPEN CLOSE

In this project we will see how the gate is opened and closed when the human passes in front of the PIR sensor. When human comes in front of PIR sensor the barrier will be opened automatically and closed after 5 seconds. This system has close loop technique.

This program is used to open the gate. When there is a human movement in front of pir sensor,the output of pir sensor goes to high and the servo motor will be activated by 90 degree speedly and the red led will be off and green led will be on. After some time (4 second), it will come back to 0 degree slowly slowly and red led will be on and green led will be off. Also the detection range from 3 meter to 7 meter.

Use dvd writer shutter mechanism as a gate. In this mechanism there a dc motor with rack and pinion assembly and limit switch assembly. The dc motor will move the mechanism up side to open the gate and down side to close the door when we apply the +5vdc to pin number 1 and ground to pin number 2. The limit switch has three pin. Pin 3 is the up side limit pin. Pin 4 is common pin and pin 5 is the down side limit pin. Pin 3 and 4 are connected with arduino shield with 10k pullup resistor as shown in diagram and pin 4 is connected with ground. In the mechanism there are 5 pins.

The motor will rotate to move the shutter up side till the pin 3 and pin 4 are open. When pin 3 and 4 are connected via limit switch assembly the motor will be stopped. And the opposite for close. This type of programming is done in this program.

This is very useful because in normal programming we have keep the delay for motor on or off. In this case the limit switch will inform the door is open or close.

Using Time Delay

/*This program is used to open the barrier. When there is a human movement 
 * in front of pir sensor,the output of pir sensor goes to high and 
 * the servo motor will be activated by 90 degree speedly and 
 * the red led will be off 
 * and green led will be on.
 * After some time (4 second), it will come back to 0 degree slowly slowly and 
 * red led will be on and green led will be off.
 * 
 * This project can be used at tall plaza, garage, society gate etc.
 * 
 * Note: The pir high duration can be adjustable from 5 sec to 200 sec using pot.
 * Also the detection range from 3 meter to 7 meter.
 * 
*/
/* Hardware Requirement
 * Arduino Uno 
 * USB cable for Arduino board programming
 * Arduino Shield for dc motor, stepper and servo
 * +5V 1A power supply for shield
 * PIR sensor
 * Servo motor 9g
 * 5mm Red LED 1
 * 5mm Green LED 1
 * 330 ohms Resistor 2
 * PVC straw
 * Female to Female Jumpers 10
 * 
 * 5V dc motor with rack and pinion mechanism
 * 
 * Note: In this code the gate opening and closing 
 * time is based on time delay.
*/
#include <Servo.h>
Servo myservo;      // create servo object to control a servo
int pos = 0;        // variable to store the servo position
const int red = A3;   //define red led
const int grn = A2;  //define green led
const int pir = A0; //pir sensor is sonnected at pin A0
int val = 0;        // variable to store the sensor status (value)
void setup()
{
  pinMode(pir,INPUT); //pir output pin is connected to A0 pin of an Arduino
  pinMode(red, OUTPUT); 
  pinMode(grn, OUTPUT);
  
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  digitalWrite(red, HIGH); // turn the LED on 
  digitalWrite(grn, LOW); // turn the LED off 
  
  for (pos = 90; pos >= 0; pos -= 1)// goes from 90 degrees to 0 degrees
  { 
      myservo.write(pos);   // tell servo to go to position in variable 'pos'
     
      delay(20);            // waits 20ms for the servo to reach the position
  }
  
}
void loop() 
{
  
  val = digitalRead(pir);    // read sensor value
   
  if (val == HIGH)            // check if the sensor is HIGH 
  { 
    // goes from 0 degrees to 90 degrees in steps of 1 degree
    for (pos = 0; pos <= 90; pos += 1) 
    {
      myservo.write(pos);     // tell servo to go to position in variable 'pos'
    
      delay(5);               // waits 5ms for the servo to reach the position
    }
    digitalWrite(red, LOW); // turn the LED off 
    
    digitalWrite(grn, HIGH); // turn the LED on    
    
    delay(4000);    //wait for 4000ms
    
    digitalWrite(red, HIGH); // turn the LED on 
    
    digitalWrite(grn, LOW); // turn the LED off 
     
    for (pos = 90; pos >= 0; pos -= 1)// goes from 90 degrees to 0 degrees 
    {  
      myservo.write(pos);   // tell servo to go to position in variable 'pos'
      
      delay(20);            // waits 15ms for the servo to reach the position
    
    }
  }
}

Using Limit Switch

/*This program is used to open the gate when 
 * there is a human movement in front of pir sensor,
 * the output of pir sensor goes to high  and 
 * the servo motor will be activated by 90 degree speedly. 
 * After some time (10 second), it will 
 * come back to 0 degree slowly slowly.
 * Note: The pir high duration can be adjustable 
 * from 5 sec to 200 sec using pot.
 * Also the detection range from 3 meter to 7 meter.
 * 
 * Also in this project we have used DVD drive shutter mechanism 
 * to open or close the gate.
 * This project is used to open or close the garage door open 
 * automatically.
 * We hase used limit switch while openin or closing the door.
*/
#include <Servo.h>
#include <AFMotor.h>
AF_DCMotor motor(1);
Servo myservo;      // create servo object to control a servo
int pos = 0;        // variable to store the servo position
const int pir = A0; //pir sensor is sonnected at pin A0
const int upper = A5; //upper limit switch is sonnected at pin A4
const int lower = A4; //lower limit is sonnected at pin A5
const int red = A3;   //define red led
const int grn = A2;  //define green led
int val = 0;        // variable to store the sensor status (value)
int up = 0;         // variable to store the upper limit switch value
int lo = 0;         // variable to store the lower limit switch value
void setup()
{
  pinMode(pir,INPUT); //pir output pin is connected to A0 pin of an Arduino
  pinMode(upper,INPUT); 
  
  pinMode(lower,INPUT); 
  
  pinMode(red, OUTPUT); 
  pinMode(grn, OUTPUT);
  
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
digitalWrite(red, HIGH); // turn the LED on 
     digitalWrite(grn, LOW); // turn the LED off 
  for (pos = 90; pos >= 0; pos -= 1)// goes from 90 degrees to 0 degrees
  { 
      myservo.write(pos);              // tell servo to go to position in variable 'pos'
     
      //delay(20);                       // waits 20ms for the servo to reach the position
  }
  //Set initial speed of the motor & stop
  do
    {
      lo = digitalRead(lower);   // read lower switch value
      // Turn on motor
      motor.run(BACKWARD);
      motor.setSpeed(255);
    }while(lo == 1);  
    //delay(1000);    //wait for 10000ms
    motor.run(RELEASE);
  
  //motor.setSpeed(200);
  
  //motor.run(RELEASE);
  
}
void loop() 
{
  
  val = digitalRead(pir);    // read sensor value
  
  up = digitalRead(upper);   // read upper switch value
  
  lo = digitalRead(lower);   // read lower switch value
   
  if (val == HIGH)            // check if the sensor is HIGH 
  {
     for (pos = 0; pos <= 90; pos += 1) // goes from 0 degrees to 90 degrees in steps of 1 degree
     {
      again:
        myservo.write(pos);              // tell servo to go to position in variable 'pos'
    
        delay(1);                       // waits 5ms for the servo to reach the position
    }
    do
    {
      up = digitalRead(upper);   // read lower switch value
      // Turn on motor
      motor.run(FORWARD);
      motor.setSpeed(255);
    }while(up == 1);  
    //delay(1000);    //wait for 10000ms
    motor.run(RELEASE);
     digitalWrite(red, LOW); // turn the LED off 
     digitalWrite(grn, HIGH); // turn the LED on 
    delay(5000);    //wait for 10000ms
     digitalWrite(red, HIGH); // turn the LED on 
     digitalWrite(grn, LOW); // turn the LED off 
    for (pos = 90; pos >= 0; pos -= 1)// goes from 90 degrees to 0 degrees 
    { 
      
      myservo.write(pos); // tell servo to go to position in variable 'pos'
      
      delay(1);           // waits 15ms for the servo to reach the position
    }
    do
    {
    motor.run(BACKWARD);
    motor.setSpeed(255);  
    lo = digitalRead(lower);   // read upper switch value
    }while(lo==1);
    //delay(1000);    //wait for 10000ms
   motor.run(RELEASE); 
  }
}
admin

The author admin

Leave a Response

WhatsApp chat