PyRaspBeta

Potentiometer

A potentiometer is a resistor with a moving contact — a knob. It costs $1.50 and gives you an analog control: turn it and the wiper's voltage slides between the two ends of the track. The Pi has no analog inputs, so the wiper is read through an ADC such as the MCP3008 or ADS1115; the knob + ADC board kit is this exact pairing pre-wired. The shop's part is a linear 9 mm rotary pot with 1 kΩ, 10 kΩ or 100 kΩ tracks (10 kΩ default).

Potentiometer

Pins

PinWhat it isType
1End 1 (fully anticlockwise)passive
WWiperpassive
3End 3 (fully clockwise)passive
SettingTypeRangeDefault
ohmsenum1000, 10000, 10000010000

Wire the two ends across 3V3 and GND. 1 is the anticlockwise end, 3 the clockwise end, and W (the wiper) follows the knob: at 0 % it sits at the 1 end, at 100 % at the 3 end. The ohms setting is positional — Potentiometer(10000).

Wiring it in circuit.py

A pot on channel 0 of an MCP3008, using the Pi's hardware SPI pins:

circuit.py
from wiring import *

pi = Pi()

pot = Potentiometer(10000)
adc = MCP3008()

pi.V3_3 >> pot.pin3            # clockwise end to 3.3 V
pot.pin1 >> pi.GND             # anticlockwise end to ground
pot.wiper >> adc.ch0           # wiper: 0–3.3 V follows the knob

pi.V3_3 >> adc.vdd
adc.vdd >> adc.vref             # reference = 3.3 V, so full scale is 3.3 V
adc.agnd >> pi.GND
adc.dgnd >> pi.GND
pi.SCLK >> adc.clk
pi.MISO >> adc.dout
pi.MOSI >> adc.din
pi.CE0 >> adc.cs

The kit version replaces the first six wires with one part: kits.KnobADC() exposes vdd, gnd, clk, dout, din and cs.

Driving it in main.py

main.py
from gpiozero import MCP3008
from time import sleep

knob = MCP3008(channel=0)     # 0.0 at one end, 1.0 at the other

while True:
    print(f"knob {knob.value:.2f}")
    sleep(0.5)

knob.value is the wiper voltage ÷ VREF; multiply by 100 for a percentage, or use it straight as a duty cycle for PWM.

Electrical notes

  • The model is two resistors meeting at the wiper: turning moves resistance from 1–W to W–3. With the ends on 3V3 and GND the wiper never exceeds 3.3 V, which is what makes this safe for the ADC.
  • Track resistance is ±20 % in the feed (a trackTolerancePct knob), but the divider ratio stays exact, so a percentage reading is as good as the ADC. The end resistance is 20 Ω, so the wiper never quite reaches the rails.
  • Power rating is 0.05 W. Across 10 kΩ at 3.3 V the track burns only about 1.1 mW — fine. Wiring the wiper straight to a supply can burn the track at one end; don't use a pot as a rheostat for a load.
  • Full rotation is 300°; the canvas knob turns the same arc.
  • The MCP3008 must run from 3.3 V here, not 5 V, or its 5 V logic reaches the Pi's SPI pins. The datasheet notes cover that trap.

Simulator vs real hardware

  • The shaft position is a datafeed field measured in percent: drag it in the inspector, drive it with a wave, or replay a recording. The knob angle on the canvas follows it.
  • The behaviour refreshes every 20 ms, so fast turns arrive as smooth steps rather than continuously.
  • Real pots crackle when worn and have a mechanical dead zone at each end; the model is clean apart from the 20 Ω end resistance and the tolerance offset.
  • A real knob is read by the ADC, so the same program works on a bench unchanged — the difference is in the ADC's noise, which the MCP3008 model includes as quantisation to 10 bits.

Going deeper

Further reading