When the reading is wrong
Look at where the reading sits. Always at the top means nothing comes back or nothing can pull SIGNAL down: GND, the side facing the surface, the distance. Always near the bottom means something else is lighting the receiver. White and black alike means the ink or the height. A reading that wanders is a floating pin.
Where does it sit?
Run the first reading and hold white paper, then black tape, 3 mm from the domes. A working block gives a short bar over white and a long one over black. If it does not, where the numbers sit says where to look.
Pick what you see. The dark bars are where a working block reads, from this book's model; the red bands are where the fault puts it.
At the top: nothing pulls it down
SIGNAL starts at VCC and only light coming back pulls it down. So a reading stuck at the top means the emitter is dark (GND not connected), the light goes the wrong way (the back of the block faces the surface: the sensor looks out of the front, the side with the pin names), or the surface is too far.
At the bottom: too much light
Near 0 over black tape means the receiver is lit by something that is not your surface. The filter in its dome blocks visible light, not infrared, and the sun and filament bulbs are full of it. The emitter is always on, so the board cannot tell its own light from the room's. Shade it: a short tube of black card, a skirt on the robot, or simply closer to the surface.
Both the same: the ink, or the height
If white and black read alike, the black is pale in infrared, or the sensor is too far or pressed flat against the surface. Try matte black electrical tape at 2 to 5 mm.
Wandering: a floating pin
A reading that drifts or follows your hand is connected to nothing that holds it. Check the wire is on SIGNAL, the right-hand pin, not NC beside it, that the sketch reads the pin you wired, and that VCC is there. Then check VCC is your board's logic voltage: 3V3, or 5V on an Uno.
When it does not work
Check GND first: without it the emitter is dark. Then that the front, with the two domes, faces the paper, and that the paper is 2 to 5 mm away. Past a couple of centimetres, white paper reads like nothing at all.
Something else is lighting the receiver: sunlight, a filament bulb, a heat lamp. Shade the sensor. If it still reads 0 in the dark, SIGNAL is shorted to GND or the sketch reads another pin.
SIGNAL is floating: on NC, on a different pin from SENSOR_PIN, or VCC is not connected so nothing pulls it up. Count from the square pad: GND, VCC, NC, SIGNAL.
The height changed, the surface changed, or the light did. Recalibrate at the robot's own height over its own floor, and shade the sensor from the room.
A phototransistor with no emitter: it measures the room's light instead of its own coming back.
The other light sensor: the TK20 Ambient Light Sensor →Edit this page — content/books/reflective-optical-sensor/when-the-reading-is-wrong.mdx
Questions about this product
See what other owners have asked, and read their solutions.
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.