The comparator and the light
An LM393 compares the light sensor's voltage with half of VCC. Clear, the sensor is lower, and the comparator pulls SIGNAL LOW and the red LED lights. Blocked, the sensor rises to VCC, the comparator lets go, and a 10 kΩ pulls SIGNAL up to VCC: HIGH, LED dark. There is no hysteresis, so a slow edge can flip it more than once.
Two inputs, one answer
A comparator has two inputs and one output, and it answers one question: which input is higher? On this board the plus input is the light sensor's voltage and the minus input is half of VCC, made by two equal 10 kΩ resistors. The chip is an LM393, the same one the TK29 uses.
Switch between clear and blocked and follow the circuit:
- Clear. The sensor pulls its voltage under half of VCC, so plus is lower than minus. The comparator's output transistor turns on and pulls SIGNAL down to about 0.15 V: LOW.
- Blocked. The sensor passes nothing and R11 lifts its voltage to VCC, above half. The output transistor turns off and lets go.
Only down
The LM393 can pull its output to GND and cannot push it up. That is an open collector. R7, 10 kΩ from SIGNAL to VCC, does the pushing: when the comparator lets go, SIGNAL rises to VCC through it, and that is HIGH. So HIGH on SIGNAL is exactly VCC, which is why VCC has to be your logic voltage.
The light shows LOW
The red LED and its 1 kΩ run from VCC onto SIGNAL. While SIGNAL is HIGH both ends are at VCC and it is dark; while the comparator pulls SIGNAL down it lights, about 1.2 mA from 3.3 V and 2.9 mA from 5 V, worked out for a red LED's usual 2 V. So lit means clear. It needs no sketch, which makes it the first thing to look at when a count is wrong.
No hysteresis
The comparator answers in about a microsecond, and nothing on this board feeds its output back to its input to hold a decision once made. So while the sensor's voltage sits right at half of VCC, any wobble on it flips SIGNAL, and one slow edge can come out as several. A disc spinning at speed crosses that point too quickly for it to matter; a card eased in by hand, or a disc turning a few times a minute, can count twice. The tachometer's sketch deals with it, and the TK29 book's chatter and hysteresis shows the same effect on the same chip.
With the slot blocked the plus input sits at VCC, above the top of the LM393's input range. The sheet allows that as long as the other input stays inside the range, and half of VCC does at room temperature. At 3.3 V the margin is 0.15 V, and the sheet's range narrows when the chip is hot; the block is a bench part, not one to bake.
When it does not work
They agree. The LED lights while SIGNAL is LOW, and 0 is LOW. It runs from VCC onto SIGNAL, so it only has a voltage across it when the comparator pulls SIGNAL down, which is while the slot is clear.
Not from HIGH. HIGH is only the 10 kΩ pull-up, which can supply a fraction of a milliamp before the voltage sags. Read SIGNAL with your board and drive loads from one of its own pins.
There is no need. The board has its own 10 kΩ pull-up on SIGNAL and the comparator pulls it down, so INPUT is enough. INPUT_PULLUP only adds a second pull-up beside the first, which does no harm.
Why VCC goes to 3V3 on an ESP32 and 5V only on an Uno.
VCC is your logic voltage →Edit this page — content/books/ir-speed-sensor/the-comparator-and-the-light.mdx
Questions about this product
See what other owners have asked, and read their solutions.
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.