Robotics with the Boe-Bot text v2.2
Chapter 6: Light Sensitive Navigation with Photoresistors ยท Page 221 
 PULSOUT 13, 650 
 PULSOUT 12, 650 
ELSE ' Go forward. 
 PULSOUT 13, 850 
 PULSOUT 12, 650 
ENDIF 
Here is another code block that works a little better. This code block fixes the turning 
back and forth problem under certain conditions. The timeLeft variable now has to be 
larger than timeRight by a margin of 15 before the Boe-Bot will apply a left pulse.  
Likewise, timeRight has to be larger than timeLeft by 15 before the Boe-Bot adjusts to 
the left. This gives the Boe-Bot the opportunity to apply enough forward pulses before it 
has to correct with a turn, but only at certain light levels. 
IF (timeLeft > timeRight + 15) THEN ' Turn right. 
 PULSOUT 13, 850 
 PULSOUT 12, 850 
ELSEIF (timeRight > timeLeft + 15) THEN ' Turn left. 
 PULSOUT 13, 650 
 PULSOUT 12, 650 
ELSE ' Go forward. 
 PULSOUT 13, 850 
 PULSOUT 12, 650 
ENDIF 
The problem with the code block above is that it works under medium dark conditions 
only. If you take it into a much darker area, the Boe-Bot starts turning back and forth 
again, and it never applies any forward pulses. If you take it into a brighter area, the Boe-
Bot just goes forward, and never makes any adjustments to the left or right. 
Why does that happen? 
Here is the answer: When the Boe-Bot is in a dark part of a room, the measurement for 
each photoresistor will be large. For the Boe-Bot to decide to turn toward a light source, 
the difference between these two measurements has to be large. When the Boe-Bot is in 
a more brightly lit area, the measurement for each photoresistor will be smaller. For the 
Boe-Bot to decide to make a turn, the difference between photoresistor measurements 
also has to be much smaller than it was in the darker part of the room. The way to make 
this difference respond to the lighting conditions is to make it a variable that is a fraction 
of the average of 
timeRight and timeLeft. That way, it will always be the right value, 
regardless whether the lighting is bright or dim. 










