When a street light turns itself on at at dusk, or a camera knows when to use auto-flash, a light-sensing phototransistor may be at work. Let’s try using a phototransistor with the Propeller microcontroller for measuring light levels.
A transistor is like a valve that allows electric current to flow through its collector (C) and emitter (E) terminals. The base (B) terminal controls the rate of flow. Depending on the type of transistor, flow rate may be affected by voltage, by applied current, or by light as with phototransistor. The more light striking its base, the more current it will let flow.
We'll use the phototransistor along with a capacitor and a resistor in a charge transfer or QT circuit. This circuit lets us read a very wide range of light levels, and it does so without needing A/D conversion. QT circuits are a simple option for a variety of analog sensors.
The QT circuit behaves very similarly to the RC time circuit used with the potentiometer. The capacitor in the circuit acts like a very small battery, and the phototransistor influences the rate its charge drains by acting as light-controlled current valve. More light = quicker capacitor discharge, less light = slower discharge. The Propeller’s job will be to measure and report the discharge time, using the RC charge/discharge block.
(1) Phototransistor (#350-00029)
(1) 0.01 µF capacitor (labeled 103, #200-01031)
(1) 0.1 µF capacitor (labeled 104, #200-01040)
(1) 220 ohm resistor (red-red-brown, #150-02210)
The Sense Light application will display a number that corresponds with the light level the QT circuit detects.
If you tried the BlocklyProp potentiometer example, this code should look very similar! Only the I/O pin number and variable name have changed.
The code is inside a repeat forever loop, so it can check the circuit and update the measured value continuously. The next three blocks work together to take the capacitor discharge time measurement. They must appear in this order, with no other blocks in between.
After that, a Terminal clear screen block erases any old data and returns the cursor to the top-left position. Then the Terminal print number block displays the value of shade. A pause (ms) 200 block gives us enough time to see the measured value before the loop repeats.
Photoresistor CdS cells are light-controlled variable resistors that also work well with RC-time measurements. CdS cells were once common, but because cadminum is environmentally unfriendly, phototransistors have replaced them in many simple applications.
Photodiodes are also common. Though less sensitive than phototransistors, they are much faster at taking measurements, and overall better suited to the design of specialty equipment. Some devices only sense light in a certain part of the spectrum.
Infrared receivers detect light waves only in the infrared spectrum, not visible to the human eye. These sensors look for infrared light switching on/off in timed bursts, which correspond to different key presses on devices such as a TV remote.
If you use a capacitor that’s 10 times as large, your decay measurements will take ten times as long. So, the value rc_time returns will be 10 times larger.