Measuring Motor Speed with a Slot Sensor: Pulse Counts, RPM and Missed Edges
A slot-type optical sensor can turn a rotating disc into a stream of pulses. From those pulses, a controller can estimate speed, detect a stopped mechanism or compare a motor's response under different loads. The sensor does not output RPM directly: the mechanical pattern and counting method supply the missing information.
The PMD Way motor speed sensor module lists a 10 mm slot, a 3.3–5 V supply and a digital OUT signal. The listing does not identify the output circuit or its maximum switching frequency, so establish those details before relying on it at high speed. See the motor speed sensor collection when comparing sensing arrangements.
Define one event per optical transition
A slotted disc alternately blocks and clears the optical path. A single opaque flag can provide one pulse per revolution, while a disc with several slots provides more frequent updates. Omron's photointerrupter application guidance describes rotation counting as a typical use of slot sensors.
Choose what the software counts: rising edges, falling edges or both. Counting both edges normally doubles the events relative to counting one selected edge, but only if every slot and opaque segment is detected reliably. Define “counts per revolution” from the actual event stream, not from a vague encoder label.
Before powering the motor, rotate the disc slowly by hand through one complete turn and compare the count with the expected result. Repeat several times. This simple test catches a doubled edge count, a missing slot or an optical path that never clears.
Calculate speed from known geometry
If C events are counted during T seconds and the system produces N counted events per revolution, RPM = 60 × C ÷ (N × T). All three quantities must use consistent definitions.
For example, a disc with 20 slots, counted on one edge per slot, produces 20 events per revolution. If 100 events arrive in 0.5 seconds, the measured average speed is 60 × 100 ÷ (20 × 0.5), or 600 RPM.
At the same settings, one extra or missing count changes the result by 6 RPM. A longer measurement window reduces that count-related step but makes the displayed speed respond more slowly. The required update rate should come from the application rather than a desire to refresh the display as often as possible.
Period measurement helps at low speed
At low speed, a short fixed window may contain no events or only one. Measuring the interval between equivalent edges can provide a more useful estimate: RPM = 60 ÷ (N × period in seconds). Average over several intervals if the disc spacing or signal is uneven.
A period-based estimate needs a stopped-state timeout. Otherwise the last non-zero speed can remain displayed after the shaft stops. Choose the timeout in relation to the slowest speed you intend to distinguish, and show an uncertain or stopped state explicitly.
Check the electrical output before connecting it
The module's supply range does not establish its output-high voltage or whether OUT is push-pull, open-collector or another arrangement. Obtain the schematic or verify the output behaviour safely with suitable test equipment. Do not assume a module powered at 5 V is compatible with a 3.3 V-only input.
Check whether a pull-up is already fitted and where it connects. If level conversion is needed, use a circuit appropriate to the output type and pulse rate. Establish a common signal reference for a non-isolated connection, while keeping motor-current paths away from the sensor return.
Inspect the waveform with the disc moving slowly, then at the intended speed. A clean static high and low do not guarantee sufficiently fast edges. Long leads, pull-ups, noise and the sensor's response can all affect the signal that reaches the controller.
Make the rotating target mechanically sound
Mount the disc securely and keep it centred in the slot with clearance throughout a full revolution. Include shaft runout and vibration in that clearance check. The disc must block the sensor's infrared light effectively; visual opacity alone is not a complete optical test.
Balance and retain the disc for the intended speed. A loosely attached card may be adequate for a hand-turned demonstration but unsuitable on a fast shaft. Keep fingers, hair and loose wiring away from rotating parts and guard the test arrangement appropriately.
Do not place the sensor where a small movement of its bracket changes whether the beam is blocked. A rigid bracket and repeatable alignment often solve missed-pulse problems more effectively than additional filtering in software.
Capture pulses without doing too much work
For an Arduino implementation, the official attachInterrupt reference explains selecting interrupt-capable pins and trigger modes. Pin availability depends on the board; use the documented mapping rather than copying another board's interrupt number.
Keep the interrupt routine short. Counting an event or recording a timestamp is usually enough; formatting text and updating a display belong outside it. Shared data must be handled correctly, including atomic access where the processor cannot read a multi-byte value in one operation. Declaring a variable volatile alone does not solve every concurrency issue.
At higher rates, a hardware counter or capture peripheral may be preferable. Dynapar's encoder technology overview explains incremental pulse-based feedback. Its industrial product capabilities are not specifications for this small module, so establish the prototype's own reliable operating envelope.
Validate the speed measurement
- Confirm events per revolution with hand rotation.
- Test a slow steady speed and compare counting and period methods.
- Compare against an independent tachometer where quantitative accuracy matters.
- Repeat while the motor starts, stops and changes load.
- Check for false counts with the motor powered but the target stationary.
A single channel does not independently reveal direction. If the shaft reverses, the same pulse stream can occur in either direction; add an appropriate direction-sensing arrangement if needed. Likewise, measuring a motor shaft before a gearbox is not the same as measuring the output shaft.
Record the disc pattern, counting edge, measurement window, timeout and verified speed range. With those details fixed, a simple optical module becomes a useful tachometer whose numbers have a clear physical meaning.