speed sensor/Using it/10. When the count is wrong
Using it · 10 of 10

When the count is wrong

Start with the red LED: it shows the comparator's answer with no sketch involved, lit for clear and dark for blocked. If the LED follows the slot and the count does not, the fault is between SIGNAL and your sketch. If the LED does not follow, it is power, the windows, or what you put in the slot.

The LED first

When the count is wrong
What you see
Dark with nothing in the slot means the comparator is not pulling SIGNAL down: no power, or no beam reaching the sensor. Count from the square pad, GND, VCC, NC, SIGNAL. Then look into the slot: a label, dust or a burr over one window blocks the beam as well as a card does. If a block works from 5V but not from 3V3, its LED and sensor are a weak pair; the book cannot promise a margin the sheet does not give.

The red LED is the comparator's answer, drawn in light. It is fed from VCC onto SIGNAL, so it needs no sketch and no microcontroller: VCC and GND alone are enough to see it work. That splits every fault in two.

  • The LED follows the slot, lit when clear and dark when blocked: the block works. The fault is the SIGNAL wire, the pin number in the sketch, or how the sketch counts.
  • The LED does not follow: the fault is on the block's side. No power, something over a window, an object the beam sees through, or light getting in from outside.

A block that reads blocked when empty

The one fault that can be the block's own is a sensor too weak to pull its voltage under half of VCC with the slot clear. The LED then stays dark with nothing in the slot. A beam across a slot explains why the margin is thinner at 3.3 V than at 5 V. Check the windows are clean first; a smudge does the same thing.

Counts, not levels

When the level is right and the count is wrong, it is almost always one of two things. Too many at slow speed is the comparator flipping on a slow edge, and the lockout is the fix. Too few at high speed is polling, or a rate past what the block can follow.

When it does not work

The LED is dark with nothing in the slot.

Check VCC and GND from the square pad, then look into the slot for dust, a label or a burr over a window. If the block works from 5V on an Uno but not from 3V3, its LED and sensor are a weak pair for 3.3 V; a different block, or 5V with an Uno, is the fix.

It never reads HIGH, whatever I push in.

The object lets infrared through, or does not reach the beam. Try card or metal, pushed to the bottom of the slot. Thin paper and many plastics are close to transparent to infrared.

It counts too many at slow speeds.

The comparator has no hysteresis, so a slow edge flips it more than once. Raise LOCKOUT_US in the tachometer, keeping it under the time between two bars at your top speed.

It counts too few at high speed.

A polling sketch misses short pulses: use the tachometer's interrupt. Past about 1,900 pulses a second the light sensor itself cannot keep up: use fewer openings.

It misreads near a window.

Sunlight holds plenty of infrared, and the slot is open at the top and the ends. Enough of it keeps the sensor conducting with a bar in the way. Shade the slot.

Where this goes next

The same infrared LED and light sensor side by side, reading light bounced off a surface instead of a beam across a slot.

The other optical sensor: the TK57 Reflective Optical Sensor →

Edit this page — content/books/ir-speed-sensor/when-the-count-is-wrong.mdx

Community

Questions about this product

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

Ask a question ↗

Infrared Speed 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 →