Datasheet

Chapter 6 Light-Sensitive Navigation with Phototransistors
182Robotics with the BOE Shield-Bot
void setup() // Built-in initialization block
{
Serial.begin(9600); // Set data rate to 9600 bps
}
void loop() // Main loop auto-repeats
{
Serial.print("A3 = "); // Display "A3 = "
Serial.print(volts(A3)); // Display measured A3 volts
Serial.println(" volts"); // Display " volts" & newline
delay(1000); // Delay for 1 second
}
float volts(int adPin) // Measures volts at adPin
{ // Returns floating point voltage
return float(analogRead(adPin)) * 5.0 / 1024.0;
}
Halt Under the Bright Light
The sketch HaltUnderBrightLight will make the BOE Shield-Bot go forward until the
phototransistor detects light that’s bright enough to make the voltage applied to A3 exceed
3.5 V. You can change the 3.5 V value to one that’s halfway between the high and low voltage
values you recorded from the last sketch.
Calculate the half-way point between the ambient and bright light voltages you
recorded from the last sketch.
In the HaltUnderBrightLight sketch, substitute your half way point value in place
of 3.5 in the statement
if(volts(A3) > 3.5.
Run your modified version of HaltUnderBrightLight on the Arduino.
Hold your flashlight or lamp about a foot off of the floor, and put the BOE Shield-
Bot on the floor a couple feet away but pointed so it will go straight under the
light.
Move the power switch to position 2 so the BOE Shield-Bot will drive forward.
How close did it get to stopping directly under the light?
Try making adjustments to the threshold you set in the
if(volts(A3)
>…)
statement to get the BOE Shield-Bot to park right underneath that bright
light.
/*
* Robotics with the BOE Shield - HaltUnderBrightLight
* Display voltage of phototransistor circuit output connected to A3 in
* the serial monitor.
*/