Buttons & Potentiometer
Momentary buttons, debouncing, and the potentiometer — a variable resistor that controls everything from volume to position.
Momentary Push Buttons
A push button is a momentary SPST switch — conducts only while held, returns to open on release.
Pinout of a standard 4-pin tactile button:
The four pins are arranged in two pairs. Each pair is internally connected. The button bridges the two pairs when pressed.
1 ── 2
| | ← button
3 ── 4
Pins 1&2 are always connected. Pins 3&4 are always connected. Pressing the button connects 1-2 to 3-4. This often confuses people since it looks like four independent pins.
Wiring with pull-up:
Vcc ─── 10kΩ ─── Signal pin (reads HIGH when open)
│
[BUTTON]
│
GND
Press button → pin connects to GND → reads LOW. The resistor prevents a short between Vcc and GND.
Most microcontrollers have internal pull-ups, so the external 10kΩ becomes optional.
Debouncing
Mechanical contacts bounce on make and break — the circuit rapidly opens and closes a few dozen times in under 20ms.
For a human reading a display: invisible. For a microcontroller at MHz: reads as many presses.
Software debounce (state machine approach):
bool lastState = HIGH;
bool stableState = HIGH;
unsigned long lastChange = 0;
const int DEBOUNCE_MS = 20;
bool readButton() {
bool current = digitalRead(BUTTON_PIN);
if (current != lastState) {
lastChange = millis();
lastState = current;
}
if (millis() - lastChange >= DEBOUNCE_MS) {
stableState = lastState;
}
return stableState;
}
Hardware debounce: an RC filter (100Ω + 100nF) smooths the bounce before it reaches the pin. Simpler but wastes components.
Potentiometer
A potentiometer (“pot”) is a resistor with three terminals: two ends and a wiper that slides along the resistive element.
End A ───[resistive track]─── End B
│
Wiper (W)
As a variable resistor (rheostat): use one end + the wiper. Resistance varies from 0 to max.
As a voltage divider: connect Vcc to one end, GND to the other, and read the wiper. Wiper output scales from 0V to Vcc as you turn the knob.
Vwiper = Vcc × (position / max_position)
Turn it fully: 0V. Halfway: Vcc/2. Full: Vcc.
Common values
10kΩ is the most common value for general use. High enough not to waste significant current; low enough to drive typical ADC inputs.
Tapers
- Linear taper (B): resistance changes uniformly with rotation. Good for precise control, position sensing.
- Audio taper / log taper (A): resistance changes logarithmically. Matches how human hearing perceives volume — we hear in decades, not linear increments.
That’s why “audio pot” is a thing. A linear pot on a volume knob feels like it jumps from quiet to loud in the first 10% of rotation.
Uses
- Volume controls
- Brightness adjustment
- Calibration trim
- Joystick position sensing (two pots, one per axis)
- User-set thresholds for comparator circuits