2
SKILL
LEVEL
Ringo Educational Guide Rev04.1 ~ Plum Geek
Using Ringo’s Edge Sensors
// ... continued from previous page ...
Serial.print(leftDiff); // print the results to the serial window
Serial.print(“ “);
Serial.print(rightDiff); // print the results to the serial window
Serial.print(“ “);
Serial.print(rearDiff); // print the results to the serial window
Serial.println(“”);
// blank line with carriage return
delay(250);
// wait 1/4 second before doing it again
}
In this example we turn on the invisible infrared lights (sometimes called “IR” lights)
to light up the surface. Then we wait 200 microseconds (2/10ths of a millisecond)
to give the light sensors time to react and stabilize to the new lighting level. The
delayMicroseconds()
function is used for this.
delayMicroseconds()
is useful for
delaying very short amounts of time. A microsecond is a millionth of a second. It
is good practice to add a slight delay between changing the input to a sensor (like
the light level) and reading the sensor as it may take a short time for the sensor to
stabilize to the new input level. After we let the sensors stabilize to the new light
level, we read each of them.
We then do the same process after turning off the IR lights. Finally we subtract out
the ambient light level and send the results to your serial monitor window so you
can see the readings.
Experiment with Ringo over different surfaces and see how the number changes.
The first number in the serial window is the front left, then front right, then rear
sensor value. As you place a sensor over a different material you will see this
value change. Hold him a ways off the surface and these numbers will likely go
under 100. On a black surface or dark desk, you’ll probably see 100 to 150, and
if you place him on a white piece of paper, the values should shoot up to 800 or
more.
It is easy to make Ringo react in different ways to these values. For example, if you
run him on a white surface and surround it with black tape, you could turn on his
motors and repeatedly evaluate if the reading remains over 500, and if it ever drops
below 500, you stop the motors. This would cause Ringo to drive until
he reached the tape line.