Wichit Sirichote, wichit.sirichote@gmail.com
Build a simple RPM meter using Pi Zero board and photo sensor. Useful for N20 motor testing.
The RPM Meter is built with a Pi Zero board, RP2040, an optical photo sensor, ITR9608, and a two-digit seven-segment display, 2821BS. The pulse signal from the photo sensor is conditioned with 74HC14 and connected to GP8 . The display is a two-digit seven segment. The segment pins, A to G and DP, are driven by GP0 to GP7 through a 680 Ohms resistor. Digit control pin is a common anode. Each digit is controlled by GP15 and GP14. Q1 and Q2, the PNP transistor supplies the +3.3V to each digit. The control software is written with MMBASIC. The RPM meter is tested with 20 slots encoder disc. The meter can be powered from any USB port.
![]()
The control software was written in BASIC. The PI board uses the MMBASIC interpreter. BASIC program listing is shown below.
SetPin gp0, dout SetPin gp1, dout SetPin gp2, dout SetPin gp3, dout SetPin gp4, dout SetPin gp5, dout SetPin gp6, dout SetPin gp14, dout SetPin gp15, doutSub led1 dSelect Case dCase 0Pin(gp0)=0: Pin(gp1)=0:Pin(gp2)=0: Pin(gp3)=0 Pin(gp4)=0:Pin(gp5)=0: Pin(gp6)=1Pin(gp15)=1: Pin(gp14)=0Case 1Pin(gp0)=1: Pin(gp1)=0:Pin(gp2)=0: Pin(gp3)=1 Pin(gp4)=1:Pin(gp5)=1: Pin(gp6)=1Pin(gp15)=1: Pin(gp14)=0Case 2Pin(gp0)=0: Pin(gp1)=0:Pin(gp2)=1: Pin(gp3)=0 Pin(gp4)=0:Pin(gp5)=1: Pin(gp6)=0Pin(gp15)=1: Pin(gp14)=0Case 3Pin(gp0)=0: Pin(gp1)=0:Pin(gp2)=0: Pin(gp3)=0 Pin(gp4)=1:Pin(gp5)=1: Pin(gp6)=0Pin(gp15)=1: Pin(gp14)=0Case 4Pin(gp0)=1: Pin(gp1)=0:Pin(gp2)=0: Pin(gp3)=1 Pin(gp4)=1:Pin(gp5)=0: Pin(gp6)=0Pin(gp15)=1: Pin(gp14)=0Case 5Pin(gp0)=0: Pin(gp1)=1:Pin(gp2)=0: Pin(gp3)=0 Pin(gp4)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pin(gp4)=1:Pin(gp5)=0: Pin(gp6)=0Pin(gp15)=0: Pin(gp14)=1Case 6Pin(gp0)=0: Pin(gp1)=1:Pin(gp2)=0: Pin(gp3)=0 Pin(gp4)=0:Pin(gp5)=0: Pin(gp6)=0Pin(gp15)=0: Pin(gp14)=1Case 7Pin(gp0)=0: Pin(gp1)=0:Pin(gp2)=0: Pin(gp3)=1 Pin(gp4)=1:Pin(gp5)=1: Pin(gp6)=1Pin(gp15)=0: Pin(gp14)=1Case 8Pin(gp0)=0: Pin(gp1)=0:Pin(gp2)=0: Pin(gp3)=0 Pin(gp4)=0:Pin(gp5)=0: Pin(gp6)=0Pin(gp15)=0: Pin(gp14)=1Case 9Pin(gp0)=0: Pin(gp1)=0:Pin(gp2)=0: Pin(gp3)=0 Pin(gp4)=1:Pin(gp5)=0: Pin(gp6)=0Pin(gp15)=0: Pin(gp14)=1End SelectEnd SubSub turn_off_displayPin(gp14)=1 : Pin(gp15)=1End SubSub scan a,bled1 b Pause (1): turn_off_display led2 a Pause (1): turn_off_displayEnd Sub' set pin gp8 for measuring frequency in HzSetPin gp8, finDof = (Pin(gp8)*60)/20 ' compute rmp using TT motor 20 slots discRem Print f,scan f\10, f Mod 10 ' show on seven segment displayPause (10)LoopThe main program is a forever loop, which reads the frequency at GP8 pulse input, and computes the RPM. The sensor disc attached to the motor being tested is 20 slots encoder disc. The reading is stored in f. Subroutine scan accepts two variables: high digit and low digit. Subroutine LED1 controls the low digit and subroutine LED2 controls the high digit. The display is multiplex switching for low and high digits.
The pulse generator from motor spinning is done by an optical interruptor using a 20-slot encoder disc. The above photo shows 63 RPM.
Download
Source code in BASIC program , BASIC Interpreter for PI zero board
More technical information, please contact Wichit Sirichote, wichit.sirichote@gmail.com
Last updated November, 2025
November 2025