17 | P a g e
We can use the color sensor values to test whether the color sensor is on or off a black line.
• On a line will give a low reflectance value or off a line will give a high value.
• Assume for a start that if the reflected light value is less than 50% if we are on or near a black line.
• Place the mBot2 on the middle of the black line
• If both sensors L1 and R1 are on black – go straight ahead
• If only sensor L1 is on black – turn to the left
• If only sensor R1 is on black – turn to the right
First, test the code below without the motors driving. Then take off the comment # and try with the motors running.