is on either side (Figure 3).
• If your tape is too wide, you can either cut it thinner,
or widen the light sensor attachment to
accommodate.
• Ideally, you should have a bit of wiggle room for your
light sensors. They should be about 1. 5-2 times as far
apart as the line is wide.
Now let’s get a feel for exactly what our program
should look like. Remember, we want Eddie to start with
one light sensor on either side of the line, and go straight
forward until the line turns, at which point it should turn
into the line. Let’s take a closer look (Figure 4).
This figure shows the first step of our program: the
robot moving forward until the first bend of the line. Take
note of which sensor is tripped when the line bends left
(Figure 5). If the left sensor (port 1) sees the line, we want
the robot to turn to the left, as it does in this figure. If the
right sensor (port 2) sees the line, we want Eddie to turn to
the right. Make sense? As it turns out, a good way to write
the program is to have Eddie turn ONLY until the applicable
sensor no longer sees the line meaning that it’s back on
track. Let’s get started on the program.
Coding the Double Light Sensor
Line Follower
While there are many ways to structure this code, we’ll
take a look at one basic, linear structure that should be easy
to understand. Let’s get started.
Dual LIght Sensor Program Instructions
Figure 1. Start with an infinite loop, in which the rest of our
program will take place.
Figure 2. Add a "switch" controlled by a light sensor. Ensure that
you select port 1, and find a threshold value appropriate for
your lighting conditions.
Figure 3. If Eddie sees the floor (lighter than the tape) with his
left light sensor (port 1), then we want him to spin his motor
backwards, making the left wheel roll forwards! (Be sure to set
duration to "Unlimited")
Figure 4. If Eddie sees the dark tape with his light sensor on
port 1, we want him to spin his motor forwards, so the wheel
rolls backwards! (Be sure to set duration to "Unlimited")
SERVO 11.2010 39