Light Sensors, Part 1
Line Detection

Introduction to Light Sensors

Light sensors are like eyes for your robots, except that they can only see areas of light and dark. This may seem a bit limited at first but it is possible to use light sensors to detect different artifacts in the robot's environment. Light sensors are often used to aid a robot in navigating around its environment, either by following lines or detecting certain artifacts it encounters.

How a light sensor works

If you look at the end of the light sensor opposite the connector wire you will see what appear to be two small lights.

The red light on the left outputs light that reflects off of whatever surface the sensor is pointed at and the clear "light" on the right, which isn't really a light, measures the amount of light that is reflected off the surface. In this way the sensor is able to tell the difference between areas of varying darkness, from bright white to solid black.

Another important thing to know about the light sensor is that it returns a single numeric value that takes into account all of the colors and shades that fall inside the area of its light path. For example, if half of the illuminated area is white and half is black, the sensor will return a value that is somewhere between the values it returns if the area is completely white or black. It won't tell you what parts of the area are black and what parts are white. You will learn why this fact is important in the next lesson when we explore line following.

Testing light sensors

Here is a simple program that reads the current value of a light sensor connected to each input port and stores the values in separate containers. When you have a block in your program that reads from a light sensor Robolab tells your RCX to turn on that light sensor when you run the program. The program shown here reads from all three input ports – it doesn’t matter if there is a light sensor connected to all inputs. Any input that has a light sensor connected to it will turn on the light sensor.

After downloading and running the above program the three input ports will be set up to turn on a light sensor. You can use the View command on the RCX to examine the value of any light sensors you have connected to the input ports.

Activity

Connect a light sensor to any of the input ports. Download the light sensor test program and run it. You won’t see it do anything except turn on the light sensor (note: it is possible that the light sensor will already be turned on, in which case the program won’t appear to do anything – that’s OK, you’re still ready to proceed). Move the robot around so that the light sensor is above different colors. For best results make sure the light is within an inch or so of the color you are examining. Next, press the View button on the RCX so that the view arrow is pointing to the input port where your light sensor is connected. Write down the color and light sensor value in the table below. Do this for at least four different colors.

Color Light Sensor Value
   
   
   
   
   

Line detection

Once you understand how a light sensor works you can begin to use it in interesting ways. One such way is to detect when the robot encounters a line while navigating around in its environment. This is a useful trick you can use to help improve the accuracy of your programs when positioning the robot. For example, if there is a line immediately in front of some object you want your robot to stop next to then you can drive the robot forward until it encounters the line. Assuming that the area where the robot will be driving over is bright white, your program can simply wait until the light sensor tells your robot that it is over the line.

Activity

Using what you know about light sensors and line detection describe, in plain English, how you might write a program to detect a line.

 

 

 

Copyright © 2003, Hacienda Robotics Program.