IR Light Sensors for the MiniBots 1999 
[ Homepage ][ Send me mail ] © Kam Leang

1  Introduction
The following mini-article presents information on the light sensor system found on the Minibots.   Light sensors such as phototransistors, IR detectors, CdS cells, etc. are one of the least expensive and most useful sensors for home brewed robotic projects.   I've used these sensors on most of my robot projects.  With these sensors, you can program a robot to find and track a light source or hide from it by going towards the darkest area.  In addition, light sensors can be used to build a robot that can follow a painted line on the floor (see the article I wrote about how to do this).  These are just a few examples of the possibilities that one can explore using light sensors.

2  Setup
Each Minibot was equipped with three IR light detectors located at the front just above the sonar sensor (see the Figure below).  Using these sensors, a Minibot was capable of finding and tracking an IR light source, such as light emitted by a flash light.

The diagram below shows the top view of a Minibot and the orientation of the three light sensors and two touch sensors (feelers).  The two light sensors on the edges were used in differential mode, meaning the robot would drive forward and steer based on the error between these two sensors.  The middle sensor (optional) was used to detect if the light source was directly in front of the robot.  Finally, the two touch sensors acted as feelers to detect objects while the robot was wandering towards a light source.

If you are planning to build a robot similar to the Minibots, I highly recommend incorporating some type of light sensor to your system.  IR detectors similar to the ones available from Radio Shack will suffice. Digikey (refer to this article for part numbers) and a host of other electronic component suppliers also stock a wide variety of light sensors.  Assuming that you are using the Radio Shack brand IR detectors, the diagram below illustrates the interface between a sensor and the 68HC11E2 (BotBoard) microcontroller.  Simply wire up the sensor in a voltage divider configuration and feed the signal (Va) into the A/D port of the HC11 as shown below.

3  Theory of Operation
The theory of operation is simple.  When the sensor detects no IR light, then the resistance between point a and ground is huge or infinite (open circuit), therefore the voltage measured at point a (Va) with respect to ground is approximately +5V.  As IR light shines on the sensor, the resistance begins to decrease resulting in a decrease in Va.  Can you write down the expression for the change in Va with respect to the change in the resistance of the IR detector mathematically?  More light means lower resistance, hence the lower the voltage.  There comes a point when the sensor becomes saturated with IR light resulting in a near zero resistance and approximately zero voltage.   Therefore, the voltage swing from +5V to zero volts at point a--depending upon the light intensity--can be easily measured by an A/D port of a microcontroller.  Using this value, a robot is able to determine the amount of light its sensors detects, and thus can respond appropriately.

4  Sample Software
Sample ASM code for the HC11 is included.  Click to download light.zip.  Unzip the light.zip file.  light1.asm and light2.asm are separate files that need to be compiled into .s19 format.  The other files are referenced by light.asm and light2.asm.  I've used Rapid to compile the programs, so tailor the example code to your compiler.  Rapid supports header (*.h) files, hence the reference in the sample code.

The file light.asm, when downloaded to a robot similar to the Minibot is programmed to use two light sensors connected to ADR1 and ADR2 to scan and find an IR light source.  I'm assuming that two servo motors are used for locomotion.  Use a flashlight as a source of IR light.  Refer to light.asm code for more details.

The file light2.asm is a bit more complex.  It requires the robot to have three IR sensors connected to ports ADR1, ADR2, and ADR3, where ADR2 is the middle sensor.  In addition, two touch sensors are also used for object detection and avoidance (optional).  The Mood LED is also optional and can be left out (see sample code for more details).  The behavior of the program is simple.  When no light source is picked up by the middle sensor (indicated by a certain threshold read from ADR2), the robot simply scans in a circle.  Once light is detected by the middle sensor, which is below some threshold, then the robot begins to drive towards the source while monitoring its two edge light sensors and touch sensors.  If the light level of the middle sensor is above the "detect light" threshold, then the robot will rotate in the direction of the greatest amount of light determined by the difference or error between the two edge light sensors.  The process repeats.  Along with the behavior of finding and driving towards a light source, the robot is capable of avoiding objects using its touch sensors.  If either sensor is activated, the robot determines which sensor was tripped and avoids accordingly.  Refer to sample code for more details.

Have fun with this example.