Simple Light to Voltage Sensor

Imagine that your cyber:bot is navigating a course, and there’s a dark or shady area at the end, such as a cardboard box garage.  Your robot’s final task in the course is to stop inside that dark area.  Or, perhaps you want the robot to search for and stop under bright light.  There’s a simple phototransistor circuit you can use that lets the micro:bit module know it detected bright or dim light by comparing the ambient light to some specified level. 

Ambient means ‘existing or present on all sides’ according to Merriam Webster’s dictionary.  For the light level in a room, think about ambient light as the overall level of brightness.

Parts List

(1) phototransistor
(2) jumper wires
(1) resistor, 2 kΩ (red-black-red)
(1) cardboard box "garage" that fits the cyber:bot
(1) Optional - a flashlight or desk lamp, incandescent works best

After some testing, and depending on the light conditions, you might end up replacing the 2 kΩ resistor with one of these resistors, so keep them handy:

(1) resistor, 220 Ω (red-red-brown)
(1) resistor, 470 Ω (yellow-violet-brown)
(1) resistor, 1 kΩ (brown-black-red)
(1) resistor, 4.7 kΩ (yellow-violet-red)
(1) resistor, 10 kΩ (brown-black-orange)

The drawing below will help you tell apart the phototransistor and infrared LED, since they look similar.

Building the Voltage Detector

The schematic and wiring diagram below show the schematic and wiring diagram of a circuit very similar to the ones in streetlights that turn on automatically at night.  The circuit outputs a voltage that varies depending on how much light shines on the phototransistor.  The cyber:bot will monitor the voltage level with one of its analog to digital pins.

  • Set the cyber:bot board's power switch to 0 — always do this before building or modifying circuits on the board.
  • Build the circuit shown, using the 2 kΩ resistor.
  • Double-check to make sure you connect the phototransistor’s emitter lead (by the flat spot) to the resistor, and its collector to 3.3V.
  • Also double-check that the phototransistor’s leads are not touching each other.