Datasheet

Chapter 6 Light-Sensitive Navigation with Phototransistors
198Robotics with the BOE Shield-Bot
The final measurement will be stored in a floating point variable named ndShade, so that
gets declared first. Then, the next line does the zero-justified normalized differential shade
math. The result will be a value in the 0.5 to +0.5 range that represents the fraction of total
shade that
tRight detects, compared to tLeft. When ndShade is 0, it means tRight
and
tLeft are the same values, so the sensors are detecting equally bright light. The
closer
ndShade gets to 0.5, the darker the shade over the right sensor. The closer ndShade
gets to 0.5 the darker the shade over the left sensor. This will be very useful for navigation.
Let’s test it first with the Serial Monitor.
Example Sketch: LightSensorValues
This screen capture shows a Serial Monitor example with the LightSensorValues sketch
running. With shade over the right sensor, the
ndShade value is about 0.4. With shade over
the left sensor, it’s about 0.4.
Make sure there is no direct sunlight streaming in nearby windows. Indoor
lighting is good, but direct sunlight will still flood the sensors.
Verify that when you cast shade over the BOE Shield-Bot’s left sensor, it results in
negative values, with darker shade resulting in larger negative values.
Verify that when you cast shade over the BOE Shield-Bot’s right sensor, it results
in positive values, with darker shade resulting in larger positive values.
Verify that when both sensors see about the same level of light or shade,
that
ndShade reports values close to 0.
Try casting equal shade over both sensors. Even though the overall light level
dropped, the value of
ndShade should still stay close to zero.
About equal light
Shade over right
Shade over Left
Back to about equal