Summary of Arduino – (Very) Basic motion tracking with 2 PIR sensors
This article details a beginner's project using an Arduino to track basic motion with two PIR sensors. The system triggers individual LEDs and controls a servo motor to turn left or right based on which sensor detects movement. While the author notes limitations in precision regarding velocity and exact direction, it serves as a foundational attempt at motion tracking.
Parts used in the 2 PIR Motion Tracking Project:
- 2x 220 Ohm resistor
- 2x 10K Ohm resistor
- 2x PIR sensor
- 1x Servo (5V supply compatible)
- 2x LED
- Arduino Deumilanove w/ ATMEGA328
- Breadboard / Prototyping board
- Jumper/ Connector wires
- Optional 9V DC power supply or USB power
- Soldering iron and solder
- Temporary adhesive
Took me a little while to get started but I’ve managed to wire 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.
First have a look at my previous tutorial – Arduino PIR motion detector circuit. Now we’re going to use 2 of them and this isn’t that different from just using one of them. However this is only a first attempt so I’ve not calibrated anything properly, for instance we can’t ascertain velocity or true direction of movement because these sensors aren’t that precise and have a wide range of detection. But hey, it’s a start!
Arduino PIR Motion Sensor Circuit Parts
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.
Arduino Infrared Motion Detector Circuit
So you’ll see that its really just a lot of wires. The PIRs I’ve soldered on the wires and on their output pin there’s a 10K Ohm resistor for each going between them and the positive rail on the breadboard. The LED’s are the same layout as the basic blink tutorials, 220 Ohm resistor between the positive pin (the longer one) and the Arduino pin.
PIR Motion Sensor Arduino Code
This isn’t too bad. Basically we set 2 sensors and have a few if statements to do shit based on if they turn on or off, so essentially they’re treated just like a couple of switches.
/*
LUCKYLARRY.CO.UK - 2 3pin PIR sensors to track basic motion.
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 // Include servo library, you can get it from http://www.arduino.cc/playground/ComponentLib/Servo
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
}
For more detail: Arduino – (Very) Basic motion tracking with 2 PIR sensors
- How do I wire the PIR sensors for this project?
The output pin of each PIR sensor requires a 10K Ohm resistor connecting it to the positive rail on the breadboard. - Can this project determine the velocity of moving objects?
No, the author states that due to the wide detection range and lack of calibration, the system cannot ascertain velocity. - What type of servo is required for this circuit?
You need a servo that requires no more than a 5V supply. - Which digital pins are used for the left and right PIR sensors?
The left sensor uses digital pin 4 and the right sensor uses digital pin 2. - How does the servo react when both sensors detect motion simultaneously?
The code indicates that if both sensors detect motion, the object is likely between them, but the system is not precise enough to handle this specifically. - What components are needed to connect the LEDs to the Arduino?
An LED requires a 220 Ohm resistor placed between its positive pin and the specific Arduino digital pin. - Does the servo move continuously even after motion stops?
The code logic suggests the servo moves until no motion is detected by the triggering sensor. - Is calibration necessary for accurate direction detection?
The author notes that proper calibration has not been performed, affecting the accuracy of true direction detection.
