OBJECT TRACKER

   
 
EVER WONDERED HOW A MILITARY DEFENSE SYSTEM IS ABLE TO LOCK DOWN AND TRACK AN INCOMING MISSILE AND SHOOT IT DOWN ?

Well, Today we'll make one. Well..not really, but we will try to make an electronic system very similar! This electronic system is called "Object Tracker" and now we will learn about it. From the name you can tell that this system is able to track objects. We will be making it using Arduino and Ultrasonic sensor.

WORKING PROCEDURE 

Ultrasonic sensors emit sound waves of high frequency at regular intervals. If there is an object in front of the sensor the wave gets reflected back as echo signals to the sensor, which  calculates the time-span between emitting the signal and receiving the signal. Now setting a particular echo travel time range, if there is an object in front of one sensor for which the echo time-span falls within that specified range then we can rotate the servo motor to that side of the ultrasonic sensor. 

So, in this case, a travel time range is set between 100~1500 microseconds. If there is an object in front one sensor for which the echo time-span falls in between 100~1500 µs then we command the servo to rotate to that side of the sensor. Similar procedure is applicable for the other sensor too.

Keep in Mind:

  • It is always better to use an external power supply to power the servo .
  • The jittering of servo can be solved by placing a capacitor of around 470µF.
  • The Capacitor must be placed between the servo Vcc and GND lines  (Maintain Polarity).

THE COMPONENTS

  • ARDUINO UNO BOARD                              
  • ULTRASONIC-SENSOR HC-SR04               
  • SERVO MOTOR SG90                    
  • BREAD BOARD                                 
  • CARDBOARD                                 
  • GLUE GUN                                   
  • JUMPER WIRES ( M-M | M-F )     

SCHEMATIC

ObjectTracker-schematic
Schematic diagram of Object Tracker

THE COMPLETE CODE

/*author : Sadman Alvee -> owner of impedancPlus*/ #include<Servo.h> //UltrasonicSensor_Left int trigPinLeft = 6; int echoPinLeft = 5; int signalTimeLeft; //UltrasonicSensor_Right int trigPinRight = 13; int echoPinRight = 12; int signalTimeRight; //Servo Motor int servoPin = 9; int pos; int lastPos; //Create an Object of type - SERVO Servo thisServo; void _servoMechanism(int usLeft, int usRight) { //The core logic of this program will be implemented here if (usLeft > 100 && usLeft < 1500 && usLeft < usRight) { for (pos = lastPos; pos <= 140; pos += 3) { thisServo.write(pos); delay(20); lastPos = pos; //For debugging purpose Serial.print("Object at left: "); Serial.println(pos); } } else if (usRight > 100 && usRight < 1500 && usRight < usLeft) { for (pos = lastPos; pos >= 10; pos -= 3) { thisServo.write(pos); delay(20); lastPos = pos; Serial.print("Object at Right: "); Serial.print(lastPos); } } else { thisServo.write(90); //Default Servo Angle lastPos = pos; } } void _ultrasonicMechanism() { //LEFT SENSOR digitalWrite(trigPinLeft, LOW); delayMicroseconds(5); digitalWrite(trigPinLeft, HIGH); delayMicroseconds(5); digitalWrite(trigPinLeft, LOW); delayMicroseconds(5); signalTimeLeft = pulseIn(echoPinLeft, HIGH); //RIGHT SENSOR digitalWrite(trigPinRight, LOW); delayMicroseconds(5); digitalWrite(trigPinRight, HIGH); delayMicroseconds(5); digitalWrite(trigPinRight, LOW); delayMicroseconds(5); signalTimeRight = pulseIn(echoPinRight, HIGH); _servoMechanism(signalTimeLeft, signalTimeRight); _printData(); } void _printData() { //For Printing values and checking Serial.print("Left: "); Serial.println(signalTimeLeft); delay(1000); Serial.print("Right: "); Serial.println(signalTimeRight); Serial.println(" "); delay(1000); } void setup() { // put your setup code here, to run once: pinMode(trigPinLeft, OUTPUT); pinMode(echoPinLeft, INPUT); pinMode(trigPinRight, OUTPUT); pinMode(echoPinRight, INPUT); thisServo.attach(servoPin); Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: thisServo.write(90); //Servo Angle 90 Degrees at Starting _ultrasonicMechanism(); }

Comments