Let's Make Robots!

Making an IR object tracking system

Tracks an objects position
MPSA13.pdf154.35 KB
MPSA14.pdf43.7 KB

In an earlier tutorial on IR object detection sensors I mentioned that they could be used for object tracking. Now I show you how and my progress so far. I've also posted a challenge based on object tracking to squirt pets with a waterpistol. Object tracking with these sensors is more complicated than object detection so I'm going to try and explain it in more detail here including problems I've had as this is still a work in progress. I got the idea for this system after reading Mintvelt's post on "smooth object tracking". Frits also had a hand in inspiring this idea with his Amanda LDR of which this is basically an IR version.

The theory: The method of tracking used here is very simple. The software simply moves the servo until both phototransistors get the same amount of IR. If the object moves to one side then one sensor will get more IR than another and the servo turns to correct the imballance. If you want to track up/down as well as left/right then just make a second unit and mount it vertically instead of horizontally.


My success: This was my prototype object tracker. It was a bit jerky at first as can be seen in the 2nd video. After Rik installed a warpdrive in my code it bacame quite fast and smooth. Unfortunately I lost the video so you'll have to take my word for it. The improved code is OBJECT_TRACKER_V1.7.BAS in the attachments.

The tracking software reads the ambiant light and then turns on the IR LEDs to read the refected light. It subtracts the ambiant light from the reflected light to stop iR coming from a window causing the tracker to turn towards the light. The inputs are then calibrated to allow for component variation. Adjustment is made to the servo position depending on the difference between the calibrated readings. The main changes to my original software to prevent jerkiness was to turn off the servo between adjustments which is really compensating for the picaxe's dodgy bootstrap code. This was V3 of the firmware. 


My failures: After the success of this tracker I decided to make a larger dual axis tracker with greater range! It was a spectacular failure. It had plenty of range but was impossible to callibrate as I had not considered the optical side of the design.


The problem I believe was that light from the LEDs overlapped at different distances depending on where the object (my hand) was relative to the unit. If I calibrated it with my hand 2 meters from it then it really only worked ok with my hand at that distance.


IR_tracking_sensor_2.jpgMy newest array, with navy blue IR LEDs works better as I've gone back to a single phototransistor for the sensor instead of two in parallel. The idea is that fewer lenses are better. The domed end of a LED or a phototransistor is a lens that focuses the light sent or received. The IR LEDs I'm using have a viewing angle of about 30 degrees. Check you datasheet of both LEDs and phototransistor as it can vary.

This design still has problems. After looking at it shining IR onto a sheet of paper through my camera I relised that once again I was getting light from different LEDs reflecting back to a  phototransistor depending on how far away the paper was. You can see the amplifier mounted seperately at the base of the cannon.

So back to the drawing board. First thing I want to change is the way my LEDs and phototransistors are mounted as they are at a fixed position and angle.


In my original prototype, overlapping light wasn't an issue. The diagram below shows why.


In comparison, the diagram of my last design shows where my problem lays. Up close the phototransistor only gets light reflected back from the LEDs next to it but at a greater distance it starts to recieve light from nearby sensors. The best solution I can think of is to have a central, compact light source that reflects back to all the phototransistors.



Mechanical callibration: By adjusting the angle and position of my sensors I should be able to do some of the calibration mechanically which means less math for your processor and a faster response time. It is also better if you can have one single lightsource to eliminate the problem of overlapping light. If you need more than one LED to get more range then cluster them as close as possible in the centre and mount your sensors around the outside facing outward slightly. If your tracker seems to be looking off centre to the object being tracked, try adjusting the angle of the sensors by small increments.

Software callibration: If this is not enough then you will need to calibrate it through software. I did this by disabling the servos and holding my hand at the maximum detection range of the sensors. Using debug to get the readings from the sensors I then divided down the larger numbers so that all readings were the same when the tracker was looking directly at my hand.

New amplifier design: My original amplifier design was based loosly on a one transistor amplifier I was taught at colledge (16 years ago). Since it worked first go I didn't mess with it but really it's not a good design as the original design was for AC signals. I've now simplified it as you can see below.


 The phottransistor and amplification diode form a simple darlington transistor. The 2Kresistor was chosen as the datasheets suggested that the BC549 has the most gain with about 2mA flowing through it. The resistors could be anything from about 1K through to 10K. I would not go less than 1K because you would only waste power. More than 10K could affect the accuracy of the processors ADC due to it's input impedance. More sensitivity could be obtained using your ADC in 10bit mode but I think 8bit should be adequate and simplifies the maths.

Below is the LED array driver circuit. It is very simple and could easily be made with a NPN transistor instead of a FET with no change to component values.



IR_LED_array_Schematic.jpgThis is what I used with my last design. The current is limmited to about 50mA per LED so that I didn't have to worry about damaging the LEDs if they stayed on too long due to a fault in the software while debugging.

Boosting range: So far I have used more LEDs to increase range but this has caused troubles with callibration when the LEDs were not clustered together. The LEDs I've used do have a peak current rating of 1.2A but at this intesity they could be damaged if left on for more than 100uS. I would probably use a 555 timer to control the pulse if I resort to that method of increasing range as this would protect the LEDs from faulty code. The biggest problem with this idea is that the LEDs can only be on for about 100uS. I don't think this will be enough time for the processor to read 4 ADC inputs. I can get a 2.4W IRLED that will handle 1A continuous current but that will cost me $30 AUD plus P&H. At this stage I've ordered some High intensity IR LEDs that will handle 100mA continuous. Because I'm only going to have them on long enough to read my ADC inputs I can possibly push that to 200mA or more as long as the dutycycle is low enough.



Hardware protection: This is a circuit I've designed to protect the IR LEDs if you want to push them to their limit.


This uses a 555 timer to control the timing of the pulse to my IR LEDs. With the component values shown it should pulse the LEDs for just under 100uS and then canot be retriggered for at least 200uS. This means that the LEDs cannot be damaged even if the signal from the processor stays high due to a fault in the code. In this circuit, the computer triggers a pulse by pulling pin 2 which is held high by a 100K resistor down below 2/3rds of the 5V supply. This will only happen if the 1uF timing capacitor is suitably discharged which needs at least 200uS to occur. Once triggered, pin 3 goes high. This turns on the FET to power the LEDs and begins charging the timing capacitor via a diode and the 1K3 resistor. At this point the processor can no longer trigger a pulse. Once the timing capacitor and thus pin 6 exceeds 2/3 of the 5V supply, the 555 timer changes pin 3 to a low state. The LEDs are turned off and the timing capacitor discharges by the 2K7 resistor and it's diode. After aprox. 200uS the timing capacitor should have discharged back below 1/3rd of the 5V supply and the circuit is now ready to be triggered again.


This circuit is not essential. The picaxe basic language for example has a pulsout command that can send out a pulse in multiples of 10us with a 4MHz clock. One reason you might choose to use a circuit like this, even with good code is that if an interupt occurs during a pulseout then it could cause the LEDs to be on longer than normal.


Udate: 19-1-2009
I've been experimenting with improving the sensitivity of the IR detector using a high gain darlington transistor MSPA13 which has a gain of 5000+. The BC549 only had a gain of between 200-800 depending on the individual transistor. Below is a picture of my test platform. There is a MPSA14 that has a hfe of 10000. That should be better again. These transistors can be obtained world wide from Futurlec. The MPSA13 cost 14c US and the MPSA14 is only 6c US at the time of this update.


This is a 14M with my new detection circuit on an analog input. The maximum current through the IR LED is only 25mA although the multimeter registers less than 10mA total current draw since the LED is only on very briefly. Using this setup and using the readadc10 command to maximise sensitivity the picaxe could detect the wall from about 1 meter and my hand from about 400mm. This is running on a 3.7V LiPo battery (on the right) from a toy helicopter as I'm looking at using this circuit in a micro wall racer.It would be more sensitive on 5V.








Below is the schematic for the new IR detection circuit.


 I tried several resistors to increase gain. With a 100 ohm resistor I got less range but I also got less range with a 470 ohm resistor. The 220 ohms could probably be fine tuned better but was good enough for this experiment.



















IR_obstacle_detector_3_Schematic.jpgThis is a version you may want to try as it's gain can be adjusted by the 500 ohm trimpot allowing it to be callibrated easily.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

I don't mind critisism, nor is IR the only option, sonar would be better in many ways except expense. The reason I've posted this before it is working perfectly is so that others can experiment as well and perhaps come up with something better or new all together. What I'm finding is that the problem is more complex than circuitry and software, the optical setup is more complex than I though. My prototype ended up working very well because it was simple. Once I tried to improve range by adding extra IR LEDs and sensors, I added complexity to the optical design.

I now have some high intensity, narrow angle (10 degrees) IR LEDs as used in remotes. I'm hoping this will solve a lot of problems by increasing range while using a single light source.

without a Dalek reference? For that all you geeks ought to be ..........ed!
They must know I haven't fitted the 200MW pulsed plasma, beam weapon yet. (the MkIII fusion power cells won't be invented for another 10years).
what if you got IR leds with a narrower beam angle?

That will help with range, some IR LEDs for remotes have a 10degree angle. One thing I've found is you can have too much range. Because my hand is less reflective than the white wall behind me it see's my hand as a shadow and looks away from me towards the brighter wall even though it's further away.

Even if you don't have white walls, too much range will mean more clutter and the processor will have problems telling what to lock onto.

Then if you get too long of range, get leds with low beam angle and low mcd rating :D

The trick is to get a usefull amount of range. Admittedly IR at 940nm is starting to look less promising as a means of object tracking. Ultrasonic would work better as it does not get affected by daylight or colour. expense is the problem there. 4 of the EZ1 maxbotic sensors would cost me about $200 AUD (aprox. $135 US).

I've now got 4 PIR sensors that work on body heat (5-14um). Since it's pets that I want to hunt this may be the most accurate sensor and they only cost  $1.90 (US) each. As a bonus they use a lot less power than all those LEDs.

Would it be feasible to make the sensor auto calibrate with each transmission/reading iteration?

Start sending IR (throttled by pwm) at low intensity until the detector reaches a certain threshold. Then take the pwm value as a measure of distance directly, or rather as a measure of reflectiveness. Then blast away with full duty cycles and take another measurement.

Or something like that. I am not very sharp anymore, this late at night.

Making the intensity of the LEDs change to suit the enviroment, not only for white walls but also to help overcome sunlight. The PWM output directly would be no good as this is an analog system and even filtered to produce an analog output, there is a time delay required for it to stabilise when being turned on and off after callibration. It would not be a lot of time but would slow response time. A serial DAC is probably best. I'll edit this post later with some options for this including suitable schematics and datasheets. I'm waiting for some high intensity IR LEDs to arrive. When they do I'll give this a try.

but your waiting music is reeally killing me!