Phototransistor
A two-lead NPN phototransistor in a clear 5 mm package, the light sensor in the Arduino Starter Kit.
The kit carries six of them, for the Color Mixing Lamp and the Light Theremin. Aliases: photo transistor, light sensor, ambient light sensor.
It looks like an LED with a water-clear lens and works like a transistor whose base current is light. There is no base lead: light through the lens makes a photocurrent where the base would be, and the transistor's gain turns it into a collector current several hundred times larger.
Pins
| Pin | What it does |
|---|---|
C |
Collector: to the supply side. |
E |
Emitter: to the ground side, usually through the resistor you read across. |
Properties
sensitivity is the collector current per lux, in microamps, with 5 V across
the part: 2 by default.
While it runs
The slider is the light falling on the lens, in lux, 0 to 5000. The chip under the lens brightens with it.
Reading it on an Arduino
The Starter Kit wiring: collector to 5 V, emitter to an analog pin, and 10 k from that pin to ground. The pin reads the collector current times 10 k:
void setup() {
Serial.begin(9600);
}
void loop() {
int light = analogRead(A0); // 0 in the dark, near 1023 in a lit room
Serial.println(light);
delay(100);
}
How it differs from an LDR
An LDR is a resistor whose value follows the light, and in a divider its reading moves smoothly over a wide range of light. A phototransistor is a current that follows the light. Across 10 k it reads in proportion to the light until the resistor runs out of voltage, and then it stops a little short of 5 V: the transistor has saturated. In a bright room the Starter Kit divider sits near the top, and the useful range is from dark to a dim room. A smaller resistor (1 k) spreads it over brighter light.
What the model gets right
A current, not a resistance. In the active region the collector current is
sensitivity x lux, nearly independent of the voltage across the part: 20 lux
is 40 uA, which is 0.4 V across 10 k.
Saturation. It is Ebers-Moll with the base current set by the light, so as the resistor's drop leaves less than a few tenths of a volt across the part the current falls off, and the reading stops near 4.8 V rather than reaching 5 V.
Dark current. 10 nA in the dark, a tenth of a millivolt on 10 k.
Backwards it barely works. Reversed, it runs on the reverse gain, a hundredth of the forward one, so a phototransistor put in the wrong way around reads almost nothing.
The Early effect. The current climbs a little with the voltage across the part, about a tenth from 0 to 5 V, as on a curve tracer.
The numbers are assumptions in the range the visible-light phototransistors' sheets print: tens of microamps at 20 lux, a dark current of tens of nanoamps at most, a gain of several hundred. Real parts vary by a factor of two or more from one to the next.
What it does not model
Color: a real one also sees infrared, and its response peaks in the near infrared, so a filament lamp reads brighter than its lux and an LED dimmer. The angle of the light, the 10 to 20 microsecond rise and fall time, and temperature.
Common mistakes
Wiring it like an LDR with both legs interchangeable: it has a collector and an emitter, and reversed it reads almost nothing.
Leaving out the resistor: with nothing to drop the current across, the analog pin reads 5 V or floats.
See it in action
Light theremin plays the light as a pitch. Open it at /templates.