Projects / Pico stepper gauge dial

Pico stepper gauge dial

Intermediate2.7 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. PICO

    Wire the driver

    + to VBUS, - to GND, IN1 to IN4 to GP10 to GP13.

  2. PICO

    Plug in the motor

    The five-wire plug fits the socket one way.

  3. PICO

    Wire the potentiometer

    Ends to 3V3(OUT) and GND, middle to GP26.

  4. PICO

    Fit the needle

    Turn the shaft by hand to the left, then push the needle on pointing at 0.

  5. PICO

    Run the program

    The needle follows the knob.

  6. PICO

    Turn the knob slowly

    The needle sweeps across 270 degrees.

  7. PICO

    Draw the dial

    Mark the scale on card behind the needle.

In short

How do you build a pico stepper gauge dial?

A Pico turns a 28BYJ-48 stepper through a ULN2003 board to point a paper needle at a value set with a potentiometer. You need Raspberry Pi Pico H, ULN2003 driver board, 28BYJ-48 Stepper Motor, Potentiometer 10 kΩ and Breadboard 830 Tie Points. It takes 7 steps and about 160 minutes.

Level
Intermediate
Time
About 160 min
Parts
5

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
ULN2003 board + (power)Pico VBUS pin 405 V from USB
ULN2003 board -Pico GND pin 38Common ground
ULN2003 IN1 to IN4Pico GP10, GP11, GP12, GP13 pins 14, 15, 16, 17Coil control
Stepper plugULN2003 board socketFive-wire connector, one way round
Potentiometer endsPico 3V3(OUT) pin 36 and GND pin 38Reference voltage
Potentiometer middlePico GP26 pin 31ADC0, sets the target

Code

The 28BYJ-48 is a small stepper motor with a gearbox, so it turns slowly with a lot of force and holds its position. Inside are four coils, and energising them in a repeating pattern turns the shaft one small step at a time. The ULN2003 board is a set of power switches that lets the Pico's small signals drive those coils. The program uses the half-step pattern of eight states, which is smoother than the four-state pattern, and the gearbox needs about 4096 half steps for one full turn of the output. The potentiometer sets a target between 0 and 270 degrees, and each pass of the loop moves the motor one half step toward it. Because a stepper has no position sensor, the program only knows where the needle is by counting, so you must turn the needle by hand to its left stop before you power it. When the needle arrives the coils are switched off, which stops them heating up. Do not force the needle by hand while it is powered.

import time
from machine import Pin, ADC

coils = [Pin(10, Pin.OUT), Pin(11, Pin.OUT), Pin(12, Pin.OUT), Pin(13, Pin.OUT)]
pot = ADC(26)

HALF_STEPS = [0b0001, 0b0011, 0b0010, 0b0110, 0b0100, 0b1100, 0b1000, 0b1001]
MAX_POSITION = 3072                                 # 270 degrees: 4096 half steps make one turn
DEADBAND = 6                                        # ignore tiny differences so it does not jitter

position = 0                                        # the needle must start at the left stop
phase = 0

def apply(pattern):
    for i, c in enumerate(coils):
        c.value((pattern >> i) & 1)

def step(direction):
    global phase, position
    phase = (phase + direction) % 8
    apply(HALF_STEPS[phase])
    position += direction

def read_target():
    total = 0
    for _ in range(16):
        total += pot.read_u16()
    avg = total // 16
    return avg * MAX_POSITION // 65535

while True:
    target = read_target()
    if target - position > DEADBAND:
        step(1)
    elif position - target > DEADBAND:
        step(-1)
    else:
        apply(0)                                    # switch the coils off when it has arrived
    time.sleep_ms(3)                                # about 330 half steps a second, safe for this motor

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Knob fully leftNeedle at 0
Knob fully rightNeedle at 270 degrees
Knob in the middleNeedle at 135 degrees
Stop turning the knobThe motor stops and does not buzz
Turn quicklyThe needle follows without skipping

If it does not work

Motor shakes but does not turn

Check the four wires are in order IN1 to IN4 and the plug is fully in.

Skips steps

Raise the 3 millisecond pause, for example to 5.

Needle drifts away from the scale

Steps were lost, power off, reset the needle by hand and restart.

Motor gets hot

Check the program releases the coils when it arrives.

Jitters at rest

Increase the DEADBAND.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the pico stepper gauge dial?

Raspberry Pi Pico H, ULN2003 driver board, 28BYJ-48 Stepper Motor, Potentiometer 10 kΩ and Breadboard 830 Tie Points.

How long does the pico stepper gauge dial take to build?

About 160 minutes for a intermediate maker, in 7 steps.

How do I know the pico stepper gauge dial works?

Knob fully left: Needle at 0. Knob fully right: Needle at 270 degrees. Knob in the middle: Needle at 135 degrees.

Motor shakes but does not turn: what should I check?

Check the four wires are in order IN1 to IN4 and the plug is fully in.

Skips steps: what should I check?

Raise the 3 millisecond pause, for example to 5.

Needle drifts away from the scale: what should I check?

Steps were lost, power off, reset the needle by hand and restart.

Motor gets hot: what should I check?

Check the program releases the coils when it arrives.