optical sensor/How it works/03. Light out, light back
How it works · 03 of 9

Light out, light back

The emitter shines infrared out of the front. Whatever comes back lets the phototransistor conduct, and the current it takes through the 4.7 kΩ pull-up pulls SIGNAL down from VCC. So white paper reads low, black tape reads high, and nothing at all reads the same as black.

Light becomes current, current becomes volts

A phototransistor is a transistor whose base is driven by light instead of a wire. Infrared landing on it lets current flow from its collector to its emitter; the more light, the more current. In the dark it carries almost none: Vishay gives 10 nA typical.

On this board the collector is SIGNAL and the emitter is GND. Between SIGNAL and VCC sits the 4.7 kΩ pull-up. So whatever current the phototransistor takes has to come through that resistor, and every 0.1 mA drops SIGNAL by 0.47 V. That is the whole circuit.

Light out, light back
In front, 3 mm away
Emitter
17 mA, always
Phototransistor
0.43 mA
SIGNAL
about 1.3 V
White paper sends back the most: about 0.43 mA, which drops about 2.0 V across the 4.7 kΩ and leaves SIGNAL near 1.3 V. The floor, a few tenths of a volt, would take 0.64 mA. More light, lower reading.

Pick a surface. The emitter's current never changes. The phototransistor's current, and so SIGNAL, follows what comes back. The voltages are this book's model, not a measurement; the order they come in is the point.

A floor, and a ceiling

SIGNAL cannot go above VCC: with nothing coming back, the pull-up holds it there. It cannot go below a few tenths of a volt either, where the phototransistor is fully on and conducts as hard as it can. It takes about 0.64 mA to pull SIGNAL from 3.3 V to that floor. In this book's model white paper at the best distance sends back about 0.44 mA, which leaves SIGNAL near 1.2 V: well down, short of the floor. A shinier surface, or a sensor that couples better than the model assumes, can reach it.

In between is where the reading means something: grey card, a white surface farther away, the edge of a black line half under the sensor.

High means dark or far

A high reading has two causes the sensor cannot tell apart: a dark surface, or no surface at all. That matters for a robot about to drive off a table. Over the edge, the reading jumps high, exactly as it would over a black line. The next chapter takes that further: the reading also changes with distance, so it is not a measure of either colour or distance alone.

When it does not work

Why does the reading go down when it sees something?

Because the receiver sits between SIGNAL and GND, and the pull-up between SIGNAL and VCC. Light makes the receiver conduct, which drags SIGNAL towards GND. If you would rather have a number that rises, subtract the reading from the ADC's full scale in the sketch.

My black line reads almost like the white paper.

Some black inks, markers and plastics are black only to your eye: at 950 nm they reflect almost as well as paper. Matte black electrical tape is reliably dark in infrared. Always check the real surface with the first reading sketch.

Does room light change the reading?

A little indoors, a lot in sunlight. The receiver's filter blocks visible light, but daylight and filament bulbs carry plenty of infrared, and the receiver cannot tell it from the emitter's. Mount the sensor close and shade it.

Where this goes next

17.5 mA at 3.3 V, 31 mA at 5 V, and what that costs.

The emitter never rests →

Edit this page — content/books/reflective-optical-sensor/light-out-light-back.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

Reflective Optical Sensor

Loading discussions…

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum →