Build the Light Sensor Circuits

Phototransistors are a common type of analog light sensor – the kind that might help a porch light automatically turn on at night. Think of the phototransistor as a light-controlled current valve. When light strikes the base of the device (B), more current will conduct into its collector lead (C) and flow out of its emitter lead (E).

Now, it's time to build and test two phototransistor circuits to give your ActivityBot phototransistor "eyes." Leave the piezo speaker circuit in place.



  • (2) Phototransistor (#350-00029)
  • (2) 0.01 µF capacitor (labeled 103)
  • (2) 220 ohm resistor (red-red-brown)


Build the Light Sensor Circuits

Build the light sensor circuits shown below.

  • Make sure the phototransistor's shorter leads and flat spots are connected to ground, as shown in the wiring diagram below.
  • Use the 0.01 µF capacitors, labeled "103." The capacitors in your ActivityBot kit are not polar; it does not matter which way you plug them in.
  • Point the phototransistors upwards and outwards, about 90° from each other, and about 45° from vertical.

Wiring for the Navigate by Visible Light tutorial.

*P14/P15 resistors are only needed for ActivityBot kits using External Encoders (#32500).


Test the Light Sensor Circuits

This test will display raw light sensor readings in the Terminal window. You will need a flashlight or lamp that is brighter than the overall light level in the room.

The phototransistor circuits are designed to work well indoors, with fluorescent or incandescent lighting.  Make sure to avoid direct sunlight and direct halogen lights; they flood the phototransistors with too much infrared light. 

  • In your robotics area, close window blinds to block direct sunlight, and point any halogen lamps upward so that the light reflects off the ceiling.
  • Log into your BlocklyProp account and create a new project.

  • Build the project Test ActivityBot Light Sensors, above.
  • Put the Activity Board's power switch in position 1.
  • Click the Run Once button.
  • Hold your hand over one phototransistor, and then the other, while watching the values change in the Terminal.

The values shown above were taken in a room with overhead fluorescent lighting. Notice how covering the left phototransistor causes the lightLeft measurement to be larger.

Mismatched Measurements 
It is unlikely that your two phototransistor measurements will match exactly. Each sensor will vary slightly as a natural part of the manufacturing process, and the brightness levels are rarely precisely even in any environment. However, if one gives a measurement about 100 times larger than the other when exposed to the same level of light, that phototransistor is probably plugged in backward. In this case, check your circuit and try again.


How it Works

Take a peek back at the circuit schematic, for P9. Think of the 0.01 µF capacitor in the circuit as a tiny battery, and the phototransistor as a light-controlled current valve. 

The first block in the repeat forever loop is make PIN 9 high. This block supplies current to the capacitor battery, which only takes a pause 1 (ms) to charge. Immediately after that, the block RC discharge PIN 9 changes I/O pin P9 from output-high to input.  As an input, P9 will switch from sensing a high signal to a low signal as the capacitor battery drains its current through the phototransistor valve.  The Propeller is measuring how long it takes for this logic transition to happen, and the RC block stores this discharge time in the lightLeft variable block.

The next three blocks in the repeat forever loop go through the same process with the P5 phototransistor circuit and storing another discharge time measurement in the lightRight variable.  

When bright light is shining on a phototransistor, its valve is wide open and current drains through it very quickly, so the measured discharge time is small. When the phototransistor is covered up, its valve opens only a little, and the current will drain more slowly, resulting in a higher discharge time value.  The remaining blocks in the loop display the discharge time of both variables in the Terminal. The Terminal screen capture above was taken when the left phototransistor was covered up, so the value of lightLeft is larger than the value of lightRight.


Did You Know?

QT is short for Charge Transfer: In this activity, each photoresistor is being used in a charge transfer or QT circuit.  This circuit lets the robot sense a much wider range of light levels than an analog-to-digital conversion circuit you might typically see with this sensor. This QT circuit is a simple option for using a variety of analog sensors with a digital I/O pin.

Visible and Invisible Light: Light travels in waves so small that the distance between adjacent peaks is measured in nanometers (nm), which are billionths of meters.  The figure below shows the wavelengths for colors of light we are familiar with, along with some the human eye cannot detect, such as ultraviolet and infrared.  The phototransistor in your ActivityBot kit detects visible light but is most sensitive to 850 nm wavelengths, which is in the infrared range.

Your Turn

Just for fun, let's see if the phototransistor can detect different colors.

  • Zoom in on the color wavelength graph above.
  • Hold your robot up to the screen, placing one phototransistor very close to the color bar.
  • What color gives the highest reading? What colors give the lowest? 

From your observation, do you think a clear phototransistor alone, like this one, could be used as a color sensor? Why or why not?