Slots and rpm
A disc with N openings gives N pulses a turn. Pulses a second times 60 over N is revolutions a minute; revolutions a minute times N over 60 is how many pulses the sketch must count. Counting for one second, the reading moves in steps of 60 / N rpm: 3 rpm on a 20-slot disc, 60 rpm on one opening.
One pulse per bar
Put a slotted disc on a shaft and its rim through the slot. Each bar that passes blocks the beam once, so SIGNAL goes HIGH once per bar, and a disc with 20 openings has 20 bars: 20 pulses every turn. The sketch counts rising edges, the moment each bar enters the beam.
Change the openings and the speed. Two lines of arithmetic cover everything:
pulses a second = rpm × openings / 60
rpm = pulses a second × 60 / openingsAt 600 rpm a 20-slot disc gives 200 pulses a second, one every 5 ms, each HIGH for about 2.5 ms. That is already too quick for the first read's 10 ms loop.
The step size
The tachometer counts for one second and then does the second line. A count is a whole number, so the answer moves in steps of 60 / openings rpm: 3 rpm with 20 openings, 60 rpm with one. One opening is fine for a slow wheel turning once a second; for a motor, more openings give a finer reading from the same second.
Openings the beam can see
The beam passes through windows the sheet draws about 0.7 mm wide. For the block to see a bar and then a gap, both have to be wider than that where they cross the slot, or the light never fully stops or fully returns. On a disc with 20 equal bars and openings, each is about 1.6 mm wide at a radius of 10 mm, which is enough; halve the radius or double the openings and it is getting tight.
When it does not work
That is the step size. A one-second count on a 20-slot disc can only give multiples of 3 rpm, so a speed between two steps alternates between them. More openings, or counting for longer, makes the steps finer.
The sketch is counting both edges of each bar, or SLOTS is half the real number of openings. Count RISING edges only, and count the openings on your disc, not the bars on one side of it.
Discs with 20 openings are commonly sold for slot sensors like this one, sized for small hobby gear motors. You can also cut one from card: equal openings and bars, each wider than about a millimetre where they pass the slot, and deep enough to reach past the windows.
Counting every pulse on an interrupt, and printing rpm once a second.
A tachometer →Edit this page — content/books/ir-speed-sensor/slots-and-rpm.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.