Switches & motion

Switch & push button

Two pieces of metal that touch or don't. Closed, a switch is a wire; open, it is a gap that stops current everywhere in the loop. A push button is only closed while you hold it.

Pins

Either side
: A simple on/off switch has no polarity.
Tactile buttons
: They have four legs joined in two pairs. Pressing connects one pair to the other; measure to be sure which legs are which.

Switches are named by poles and throws: SPST is one circuit on/off, SPDT picks between two. Small 6 mm tactile buttons are the usual input on circuit boards.

What to look for inside

  • A switch in a loop with a lamp. It closes, stays closed, then opens again.
  • Closed, metal touches metal and current flows all the way round. Open, the air gap stops it everywhere at once.
  • Look at the moment it closes: the contacts hit, spring apart and hit again. That is contact bounce (slowed right down here; in reality it lasts a few milliseconds).

The numbers that matter

SpecTypical
Current rating
Above it the contacts arc and wear out.
50 mA (tactile) to 15 A (mains)
Voltage rating
A switch rated for low voltage can arc across when switching mains.
12 V to 250 V AC
Bounce time
How long the contacts chatter. Your debounce must wait longer than this.
1 ms to 10 ms

Where you’ll use it

  • Power switches and mode selectors.
  • Buttons read by a GPIO pin with a pull-up resistor.
  • Limit switches that tell a machine it has reached the end of its travel.

Common mistakes

  • Reading a button with no pull-up or pull-down. The input floats and reads random values while the button is not pressed.
  • Forgetting to debounce. One press gets counted as three or four.

Lessons that use it

Go deeper

τ=R C≳tbounce\tau = R\,C \gtrsim t_{bounce}

RC debounce: make the time constant longer than the bounce.

Read next

All components · All lessons · Glossary