Build it step by step
0 of 7 doneMount the motor
Fix it in its bracket and the bracket to the board or a table.
Wire the knob
Ends to 3V3(OUT) and GND, middle to GP26.
Wire the transistor
Base through 1 kilo-ohm to GP15, emitter to GND, collector to the motor.
Wire the motor supply
Other motor wire to VBUS pin 40.
Add the diode
Across the motor, stripe towards VBUS.
Run the program
The shell shows the speed in percent.
Turn the knob
Slowly up, the motor starts and speeds up.
How do you build a pico N20 motor speed knob?
A Pico drives a small N20 geared motor on a mounting bracket through a TIP120 transistor with a flyback diode, and a potentiometer sets the speed with PWM. You need Raspberry Pi Pico H, N20 micro metal gear motor, Motor mount bracket (N20 / BO), TIP120 Darlington transistor, Resistor 1 kΩ, Signal Diode 1N4148, Potentiometer 10 kΩ and Breadboard 830 Tie Points. It takes 7 steps and about 120 minutes.
- Level
- Beginner
- Time
- About 120 min
- Parts
- 8
Wiring
| From | To | Why |
|---|---|---|
| Potentiometer ends | Pico 3V3(OUT) pin 36 and GND pin 38 | Knob across 3.3 V |
| Potentiometer middle | Pico GP26 pin 31 | ADC0 input |
| Pico GP15 pin 20 | 1 kilo-ohm resistor to TIP120 base (left pin, flat side towards you) | PWM control signal |
| TIP120 emitter (right pin) | Pico GND pin 38 | Common ground for motor and Pico |
| TIP120 collector (middle pin) | Motor wire 2 | Switches the motor to ground |
| Motor wire 1 | Pico VBUS pin 40 (5 V from USB) | Motor supply |
| 1N4148 diode | Across the motor, stripe (cathode) on the VBUS side | Flyback diode absorbs the voltage spike |
Code
A small motor needs more current than a Pico pin can give, so the pin only controls a transistor and the transistor carries the motor current. The TIP120 is a Darlington transistor, two transistors in one, so a few milliamps into its base can switch an amp. A 1 kilo-ohm resistor limits the base current. PWM, pulse-width modulation, switches the motor on and off a thousand times a second and the fraction of time it is on sets the average power and so the speed. A motor is a coil, and when the current is cut the coil pushes out a spike of voltage. The 1N4148 diode across the motor gives that spike a path so it does not damage the transistor. The diode must be the right way round, with its stripe towards the positive supply. The program reads the knob eight times and averages it, leaves a small dead zone at the bottom so the motor can be fully off, and skips the low duty values at which a motor only hums. The TIP120 drops about a volt, so the motor runs a little slower than its rating. Power the motor from a USB port that can supply enough current and do not hold the shaft, because a stalled motor draws much more. Keep wires clear of the gears.
from machine import Pin, PWM, ADC
import time
motor = PWM(Pin(15))
motor.freq(1000) # 1 kHz is quiet enough for a small motor
knob = ADC(26)
MIN_START = 18000 # below this duty the motor only hums, so jump over it
def duty_for(reading):
if reading < 3000: # a dead zone at the bottom so the motor can be fully off
return 0
span = 65535 - MIN_START
return int(MIN_START + (reading - 3000) * span / (65535 - 3000))
last_percent = -1
while True:
total = 0
for _ in range(8):
total += knob.read_u16()
reading = total // 8
duty = duty_for(reading)
motor.duty_u16(duty)
percent = duty * 100 // 65535
if percent != last_percent:
print("Speed", percent, "%")
last_percent = percent
time.sleep_ms(30)Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Knob fully left | Motor off, speed 0 |
| Turn slowly right | Motor starts, then gets faster |
| Knob fully right | Top speed |
| Turn back left | Slows to a stop |
| Touch the transistor after a minute | Only slightly warm |
If it does not work
Motor does not turn
Check the transistor pins (base, collector, emitter) against its datasheet.
Motor only hums at low speed
Normal, the program skips the lowest duty.
Pico resets when the motor starts
Use a better USB port or cable, or power the motor from a separate supply with a common ground.
Transistor gets hot
Make sure it is fully switched on and the motor is not stalled.
Speed jumps around
Check the knob wiring and keep wires short.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the pico N20 motor speed knob?
Raspberry Pi Pico H, N20 micro metal gear motor, Motor mount bracket (N20 / BO), TIP120 Darlington transistor, Resistor 1 kΩ, Signal Diode 1N4148, Potentiometer 10 kΩ and Breadboard 830 Tie Points.
How long does the pico N20 motor speed knob take to build?
About 120 minutes for a beginner maker, in 7 steps.
How do I know the pico N20 motor speed knob works?
Knob fully left: Motor off, speed 0. Turn slowly right: Motor starts, then gets faster. Knob fully right: Top speed.
Motor does not turn: what should I check?
Check the transistor pins (base, collector, emitter) against its datasheet.
Motor only hums at low speed: what should I check?
Normal, the program skips the lowest duty.
Pico resets when the motor starts: what should I check?
Use a better USB port or cable, or power the motor from a separate supply with a common ground.
Transistor gets hot: what should I check?
Make sure it is fully switched on and the motor is not stalled.
