Data Sheet
Project 12 Distance Sensor
This sketch changes which LED is on depending on the amount of light the
phototransistor is getting. Build the circuit and load sketch Distance_Sensor
into Snapino
TM
using the programming instructions in project 3.
Vary the amount of light shining on the phototransistor (Q4) - if the light is
bright then the green LED (D2) will be on, if there is less light then the
yellow LED (D10) will be on, and if there is low light or no light then the
red LED (D1) will be on. This can be used to determine the distance
something is above it, since the object will slowly block out more light the
closer it gets to the phototransistor.
Once programmed, you can use the 9V battery connector to power the
circuit instead of the USB cable, then walk around with it.
Programming Note:
This sketch works by measuring how
much light the phototransistor is getting,
and assigning that value to a variable,
in this case the variable is “Val”. The
Arduino then uses this value to
determine which light to turn on. If the
variable is above a certain value, the
Arduino switches the LED from green
to yellow, and if the value still gets too
high, the Arduino switches the yellow
LED to the red LED.
You can adjust the sensitivity by
changing values 750 and 150 to be
higher or lower.
Use the preceding circuit, but load sketch
Photo_Stop into Snapino
TM
. The LEDs change
colors in a stoplight pattern, with the rate of change
controlled by the phototransistor (Q4). Vary the
amount of light shining on the phototransistor; the
brighter the light, the faster the LEDs change.
Programming Note: This sketch reads the value
from the phototransistor, and uses that value to
change the time delay, causing the stoplight to
switch the LEDs faster or slower.
-23-
Project 13
Photo Stop
SCSNAPINO_Manual_112816.qxp 12/30/16 2:00 PM Page 24










