RPM Meter, PI Zero
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, dout           
Sub led1 d
           
 Select Case d
 Case 0
 Pin(gp0)=0: Pin(gp1)=0:Pin(gp2)=0: Pin(gp3)=0
   Pin(gp4)=0:Pin(gp5)=0: Pin(gp6)=1
 Pin(gp15)=1: Pin(gp14)=0
 Case 1
 Pin(gp0)=1: Pin(gp1)=0:Pin(gp2)=0: Pin(gp3)=1
   Pin(gp4)=1:Pin(gp5)=1: Pin(gp6)=1
 Pin(gp15)=1: Pin(gp14)=0
 Case 2
 Pin(gp0)=0: Pin(gp1)=0:Pin(gp2)=1: Pin(gp3)=0
   Pin(gp4)=0:Pin(gp5)=1: Pin(gp6)=0
 Pin(gp15)=1: Pin(gp14)=0
 Case 3
 Pin(gp0)=0: Pin(gp1)=0:Pin(gp2)=0: Pin(gp3)=0
   Pin(gp4)=1:Pin(gp5)=1: Pin(gp6)=0
 Pin(gp15)=1: Pin(gp14)=0
 Case 4
 Pin(gp0)=1: Pin(gp1)=0:Pin(gp2)=0: Pin(gp3)=1
   Pin(gp4)=1:Pin(gp5)=0: Pin(gp6)=0
 Pin(gp15)=1: Pin(gp14)=0
 Case 5
 Pin(gp0)=0: Pin(gp1)=1:Pin(gp2)=0: Pin(gp3)=0
   Pin(gp4)=1:Pin(gp5)=0: Pin(gp6)=0
 Pin(gp15)=1: Pin(gp14)=0
 Case 6
 Pin(gp0)=0: Pin(gp1)=1:Pin(gp2)=0: Pin(gp3)=0
   Pin(gp4)=0:Pin(gp5)=0: Pin(gp6)=0
 Pin(gp15)=1: Pin(gp14)=0
 Case 7
 Pin(gp0)=0: Pin(gp1)=0:Pin(gp2)=0: Pin(gp3)=1
   Pin(gp4)=1:Pin(gp5)=1: Pin(gp6)=1
 Pin(gp15)=1: Pin(gp14)=0
 Case 8
 Pin(gp0)=0: Pin(gp1)=0:Pin(gp2)=0: Pin(gp3)=0
   Pin(gp4)=0:Pin(gp5)=0: Pin(gp6)=0
 Pin(gp15)=1: Pin(gp14)=0
 Case 9
 Pin(gp0)=0: Pin(gp1)=0:Pin(gp2)=0: Pin(gp3)=0
   Pin(gp4)=1:Pin(gp5)=0: Pin(gp6)=0
 Pin(gp15)=1: Pin(gp14)=0
           
 End Select
           
 End Sub
           
 Sub led2 d
           
 Select Case d
 Case 0
 Pin(gp0)=0: Pin(gp1)=0:Pin(gp2)=0: Pin(gp3)=0
   Pin(gp4)=0:Pin(gp5)=0: Pin(gp6)=1
 Pin(gp15)=0: Pin(gp14)=1
 Case 1
 Pin(gp0)=1: Pin(gp1)=0:Pin(gp2)=0: Pin(gp3)=1
   Pin(gp4)=1:Pin(gp5)=1: Pin(gp6)=1
 Pin(gp15)=0: Pin(gp14)=1
 Case 2
 Pin(gp0)=0: Pin(gp1)=0:Pin(gp2)=1: Pin(gp3)=0
   Pin(gp4)=0:Pin(gp5)=1: Pin(gp6)=0
 Pin(gp15)=0: Pin(gp14)=1
 Case 3
 Pin(gp0)=0: Pin(gp1)=0:Pin(gp2)=0: Pin(gp3)=0
   Pin(gp4)=1:Pin(gp5)=1: Pin(gp6)=0
 Pin(gp15)=0: Pin(gp14)=1
 Case 4
 Pin(gp0)=1: Pin(gp1)=0:Pin(gp2)=0: Pin(gp3)=1
   Pin(gp4)=1:Pin(gp5)=0: Pin(gp6)=0
 Pin(gp15)=0: Pin(gp14)=1
 Case 5
 Pin(gp0)=0: Pin(gp1)=1:Pin(gp2)=0: Pin(gp3)=0
   Pin(gp4)=1:Pin(gp5)=0: Pin(gp6)=0
 Pin(gp15)=0: Pin(gp14)=1
 Case 6
 Pin(gp0)=0: Pin(gp1)=1:Pin(gp2)=0: Pin(gp3)=0
   Pin(gp4)=0:Pin(gp5)=0: Pin(gp6)=0
 Pin(gp15)=0: Pin(gp14)=1
 Case 7
 Pin(gp0)=0: Pin(gp1)=0:Pin(gp2)=0: Pin(gp3)=1
   Pin(gp4)=1:Pin(gp5)=1: Pin(gp6)=1
 Pin(gp15)=0: Pin(gp14)=1
 Case 8
 Pin(gp0)=0: Pin(gp1)=0:Pin(gp2)=0: Pin(gp3)=0
   Pin(gp4)=0:Pin(gp5)=0: Pin(gp6)=0
 Pin(gp15)=0: Pin(gp14)=1
 Case 9
 Pin(gp0)=0: Pin(gp1)=0:Pin(gp2)=0: Pin(gp3)=0
   Pin(gp4)=1:Pin(gp5)=0: Pin(gp6)=0
 Pin(gp15)=0: Pin(gp14)=1
 End Select
           
 End Sub
           
Sub turn_off_display
 Pin(gp14)=1 : Pin(gp15)=1
 End Sub
Sub scan a,b
 led1 b
   Pause (1): turn_off_display
   led2 a
   Pause (1): turn_off_display
 End Sub
           
' set pin gp8 for measuring frequency in Hz
SetPin gp8, fin
           
Do
 f = (Pin(gp8)*60)/20 ' compute rmp using TT motor 20 slots disc
 Rem Print f,
 scan f\10, f Mod 10 ' show on seven segment display
 Pause (10)
Loop
 

The 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