Tracking Objek
Tracking Objek
Problem definition
The product has to detect and track a moving person autonomously while keeping the person in
the middle of the camera’s frame.
Project components
The design of the tracking system is divided into 3 major components:
Turning base – to provide the rotational motion
Sensors – to detect the movement of a person
Controller – to control the orientation of the rotational motion corresponding to the
activation of the sensors.
Material selection
Turning base
A generic servo motor was chosen because it is cheap. Furthermore, the servo motor
satisfies the needs of the project, since the webcam provided is not heavy. Apart from the
servo motor, pan/tilt brackets were required to mount the webcam to the motor.
Sensors
PIR (Passive Infrared) sensors were selected as the sensors for motion tracking because
they are cheap and they are capable of sensing human’s radiation (Infrared) up to 10
meters of range. A total of 4 PIR sensors were required for this project.
Controller
An Arduino Uno microcontroller was chosen because it was already available at the
beginning of the project and it satisfies the needs of the project for controlling purposes.
Detailed design
The webcam is screw mounted to the pan/tilt brackets which are attached to the servo motor. The
servo motor is connected to the Arduino Uno microcontroller which commands it to turn the
brackets, consequently turning the camera in the yaw axis. The angle of rotation is limited to 0,
60, 120, 180 degrees since only 4 PIR sensors were used. The direction of rotation determined by
which one of the 4 PIR sensors, connected to the microcontroller, is interrupted by a person’s
movement. Figure 3 is the circuit diagram developed on Fritzing.
In regards to the power budgeting, the Arduino Uno microcontroller does not have sufficient
current to operate the servo, thus a separate power source (5V) is required to power the servo
alone. Nevertheless, another power source (5V) is sufficient to power the microcontroller and all
4 of the PIR sensors. It is important to note that the servo has to be grounded to both the power
source and the microcontroller’s ground.
Figure 4 shows the preliminary setup of the system. Figure 5 shows the end product with
isolating hoods.
Demonstration
Figures 6 to 9 demonstrate how the device senses and tracks a person moving from the first to
the last PIR sensors’ position in a clockwise direction. Furthermore, the figures show the 4
angles of orientations of the webcam.
Figure 8 – Activation of the third PIR sensor (120 degrees angle of orientation)
Figure 9 – Activation of the fourth PIR sensor (180 degrees angle of orientation)
Challenges
1. Coding
The major challenge lies in the coding portion of the project. A total of 5 coding
iterations were made to develop a reliable system. The main problem that occurred was
that the servo motor turns back and forth a couple of times before settling at the desired
orientation when a person moves from one position to another. This can be explained by
the fact that the view factor of the sensors is relatively wide. The issue was mitigated by
introducing a “counter” for each sensor. The controller counts the number of times a
sensor sees the person and averages the counts, then turns the servo to that particular
direction. Appended below are segments of the code showing the how averaging of the
counters works.
For(int count = 0; count < 100; count++ ){
pirVal_1 = digitalRead(PIR1);
}... (do the same for other PIR sensors)
if(pirVal_1 == HIGH){
count1 = count1 + 1;
ave1 = 7*ave1/10 + 3*count1/10;
}... (do the same for other PIR sensors)
2. Wiring
The customized wiring connectors loosen fairly easily and would sometimes disconnect
from the sensor. The problem was solved by soldering the wire to the connectors.
Future work
1. Incorporate more PIR sensors for more angles.
2. Adding 1 more servo motor for pitching angles.
Conclusion
The goal of this project is to design and implement a human motion-detecting and tracking
system. The system is accomplished by incorporating a generic servo motor, 1 pan/tilt brackets,
4 PIR sensors and an Arduino Uno microcontroller. The system is limited to 4 yaw orientations
(0, 60, 120, 180 degrees) since only 4 PIR sensors were used. The generic servo motor is suitable
for the scope of this project project because it is easy to program and it has relatively precise
position control capabilities. The Arduino microcontroller is suitable because it is reliable in
receiving the signals from the PIR sensors, at the same time controlling the servo motor’s
rotation.
References
[1] https://learn.adafruit.com/pir-passive-infrared-proximity-motion-sensor/how-pirs-work
Appendix A
Appended below is the code.
//Motion sensing and tracking using PIR sensors and servo motor
//By: Jhi Yong Loke and Xu Zheng
//May 1, 2016
#include <Servo.h>
Servo servo;
//initialize the counters which counts the duration of which the person
stands in front of the sensors
float count1;
float count2;
float count3;
float count4;
/////////////////////////////////////////////////////////////////////////////
//initialize the average of the counters
float ave1;
float ave2;
float ave3;
float ave4;
/////////////////////////////////////////////////////////////////////////////
void setup(){
Serial.begin(9600);
servo.attach(9); // Attaches the servo to pin 7
pinMode(PIR1, INPUT);
pinMode(PIR2, INPUT);
pinMode(PIR3, INPUT);
pinMode(PIR4, INPUT);
}
/////////////////////////////////////////////////////////////////////////////
void loop(){
//loop for counting the overall duration a person is in front of each PIR
sensor
for(int count = 0; count < 100; count++ ){
pirVal_1 = digitalRead(PIR1);
pirVal_2 = digitalRead(PIR2);
pirVal_3 = digitalRead(PIR3);
pirVal_4 = digitalRead(PIR4);
if(pirVal_1 == HIGH){
count1 = count1 + 1;
ave1 = 7*ave1/10 + 3*count1/10; //counts the average duration a person is
in front of the PIR sensor
}
else{}
if(pirVal_2 == HIGH){
count2 = count2 + 1;
ave2 = 7*ave2/10 + 3*count2/10; //counts the average duration a person is
in front of the PIR sensor
}
else{}
if(pirVal_3 == HIGH){
count3 = count3 + 1;
ave3 = 7*ave3/10 + 3*count3/10; //counts the average duration a person is
in front of the PIR sensor
}
else{}
if(pirVal_4 == HIGH){
count4 = count4 + 1;
ave4 = 7*ave4/10 + 3*count4/10; //counts the average duration a person is
in front of the PIR sensor
}
else{}
}
/////////////////////////////////////////////////////////////////////////////
//sets the counts, the averages and the signal values back to 0 for the next
loop
count1 = 0;
count2 = 0;
count3 = 0;
count4 = 0;
ave1 = 0;
ave2 = 0;
ave3 = 0;
ave4 = 0;
pirVal_1 = LOW;
pirVal_2 = LOW;
pirVal_3 = LOW;
pirVal_4 = LOW;
/////////////////////////////////////////////////////////////////////////////
}