Simple motion tracking with PIR sensors

0
6374

Motion tracking with PIR sensor : ARDUINO

[nextpage title=”Description” ]

Description

In This Project  I used 2 PIR infrared sensors with an Arduino to sense motion either on the left or on the right side. The result will trigger an LED to represent each PIR sensor then I also added in a servo to be controlled – so it turns left when triggered by the left sensor and so on.

[sam id=”3″ codes=”true”]

 

[/nextpage]

[nextpage title=”Component” ]

[sam_block id=”2″]

 

Component Requirements

2x 220 Ohm resistor (Red, Red, Brown, Gold)
2x 10K Ohm resistor (Brown, Black, Orange, Gold)
2x PIR sensor
1x Servo (has to need no more than 5v supply)
2x LED
Arduino Deumilanove w/ ATMEGA328
Breadboard / Prototyping board
Jumper/ Connector wires
Optional 9V DC power supply or use the USB power for the Arduino
You will also need a soldering iron and solder if you use the same PIR as myself.
Some sort of  temporary adhesive to hold the sensors in place.

[/nextpage]

[sam id=”3″ codes=”true”]

 

 

[/nextpage]

[nextpage title=”Video” ]

[sam id=”3″ codes=”true”]

[sam_block id=”2″]

 

http://youtu.be/f9tic1FR0EU[sam id=”3″ codes=”true”]

[/nextpage]

[nextpage title=”Circuit Diagram” ]

Circuit Diagram

[sam_block id=”2″]

Motion tracking with PIR sensor

[sam id=”3″ codes=”true”]

[/nextpage]

[nextpage title=”Code” ]

Arduino Code

>> subscribe to view code& circuit diagram  (free  registration)

[sam_block id=”2″]

 

[message_box title=”MESSAGE TITLE” color=”red”]

We have 1 sensor for left, 1 for right.
 
The left sensor is triggered, the LED for the left comes on and the servo moves until no motion is detected.
The same happens if the right sensor is triggered.
 
If both sensors detect motion then its likely the object may be between the 2 but given the field of detection
its not going to be precice. Enjoy!
 
*/
 
#include Servo myservo;                                                    // Create a servo object
int pos = 0;                                                      // Variable to store the servo position in degrees
int pinPIRleft = 4;                                               // left infrared sensor, digital pin 4
int pinLEDleft = 8;	                                          // left LED, digital pin 8
int pinPIRright = 2;                                              // right sensor, digital pin 2
int pinLEDright = 10;                                             // right LED, digital pin 10
 
void setup() {
  pinMode(pinLEDleft, OUTPUT);                                    // set LEDs as outputs
  pinMode(pinLEDright, OUTPUT);
  pinMode(pinPIRleft, INPUT);                                     // set sensors as inputs
  pinMode(pinPIRright, INPUT);
  myservo.attach(9);                                              // set the servo to digital pin 9
}
 
void loop() {
 
  if (digitalRead(pinPIRleft) == LOW) {                           // if left detects motion
    digitalWrite(pinLEDleft, HIGH);                               // turn on LED
    if ((pos < 180) && (digitalRead(pinPIRright) == HIGH)) {      // if less than 180 degrees and the right sensor is off then move servo
      pos += 1;                                                   // increment servo degrees by +1
      myservo.write(pos);                                         // write the position to the servo
      delay(15);
    }
  } else {
    digitalWrite(pinLEDleft, LOW);                                // otherwise turn off LED and no servo movement
  }
 
  if (digitalRead(pinPIRright) == LOW) {
    digitalWrite(pinLEDright, HIGH);
    if ((pos >= 1) && (digitalRead(pinPIRleft) == HIGH)) {
      pos -= 1;
      myservo.write(pos);
      delay(15);
    }
  } else {
    digitalWrite(pinLEDright, LOW);
  }
 
  if ((digitalRead(pinPIRleft) == LOW) && (digitalRead(pinPIRright) == LOW)) {
    // do something here if both sensors detect movement.
  }
}

[/message_box]

 

[/nextpage]

[sam id=”3″ codes=”true”]

 

[sam_block id=”2″][wysija_form id=”1″]