Projects / Pico eight-switch reader on three pins

Pico eight-switch reader on three pins

Intermediate2.3 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. PICO

    Place the chip

    Straddling the middle of the breadboard.

  2. PICO

    Wire power

    Pin 16 to 3V3(OUT), pin 8, 15 and 10 to GND.

  3. PICO

    Wire the control lines

    Pin 1 to GP10, pin 2 to GP11, pin 9 to GP12.

  4. PICO

    Wire the buttons

    Each button from 3V3 to chip pins 14, 13, 12, 11, 3, 4, 5, 6.

  5. PICO

    Add the pull-downs

    A 10 kilo-ohm resistor from each of those pins to GND.

  6. PICO

    Run the program

    The shell prints Buttons down: none.

  7. PICO

    Press buttons

    The numbers of the pressed buttons appear.

In short

How do you build a pico eight-switch reader on three pins?

A Pico reads eight push buttons through a 74HC165 parallel-in shift register using only three pins and prints which buttons are down. You need Raspberry Pi Pico H, 74HC165 parallel-in shift register, Tactile push button 6 mm × 8, Resistor 10 kΩ × 8 and Breadboard 830 Tie Points. It takes 7 steps and about 140 minutes.

Level
Intermediate
Time
About 140 min
Parts
5

Parts list

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

Wiring

FromToWhy
74HC165 pin 16 VCCPico 3V3(OUT) pin 36Power at 3.3 V
74HC165 pin 8 GND, pin 15 CLK INH and pin 10 SERPico GND pin 38Ground, clock enabled, serial input unused
74HC165 pin 1 SH/LDPico GP10 pin 14Load pulse, low loads the buttons
74HC165 pin 2 CLKPico GP11 pin 15Shift clock
74HC165 pin 9 QHPico GP12 pin 16Serial data back to the Pico
Buttons 1 to 83V3 to chip pins 14, 13, 12, 11, 3, 4, 5, 6Button 1 on D0 up to button 8 on D7
Eight 10 kilo-ohm resistorsEach chip input pin to GNDHold each input low until pressed

Code

A shift register turns a row of parallel pins into a serial stream. The 74HC165 has eight input pins. When the load pin goes low, the chip copies the state of all eight inputs into an internal memory at once. After the load pin goes high again, each pulse on the clock pin moves the memory along by one place, so the eight values come out one after another on a single output pin. The Pico reads that pin after each clock pulse and builds a byte. With only three pins you can read eight buttons, and you can chain more chips to read sixteen or twenty-four. The first bit out is input D7, which is why the program shifts the value left as it reads. Each input has a pull-down resistor so that it reads low until the button connects it to 3.3 V, and an unused input pin should never be left floating.

from machine import Pin
import time

load = Pin(10, Pin.OUT, value=1)                    # SH/LD, low loads the inputs
clock = Pin(11, Pin.OUT, value=0)
data = Pin(12, Pin.IN)                              # QH, the serial output

def read_switches():
    load(0)                                         # copy the eight inputs into the chip
    time.sleep_us(5)
    load(1)
    value = 0
    for _ in range(8):
        value = (value << 1) | data()               # first bit out is input D7
        clock(1)
        time.sleep_us(5)
        clock(0)
        time.sleep_us(5)
    return value                                    # bit 0 is button 1 (D0), bit 7 is button 8 (D7)

last = -1
while True:
    v = read_switches()
    if v != last:
        down = [str(i + 1) for i in range(8) if v & (1 << i)]
        print("Buttons down:", " ".join(down) if down else "none")
        last = v
    time.sleep_ms(20)

Test checklist

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

CheckExpected
Nothing pressednone
Press button 1Buttons down: 1
Press button 8Buttons down: 8
Press buttons 2 and 5Buttons down: 2 5
Hold all eightButtons down: 1 2 3 4 5 6 7 8

If it does not work

Always shows some buttons down

Check each input has a 10 kilo-ohm resistor to GND, a floating input reads random.

Buttons in the wrong order

Check which chip pin each button uses, button 1 is pin 14 and button 8 is pin 6.

Nothing ever changes

Check pin 15 is on GND and the load and clock pins are not swapped.

Wrong results

The load pin must go low then high before shifting.

Chip hot

Check pin 16 is on 3.3 V and pin 8 on ground.

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

Ask Lark AI

Common questions

What parts do I need for the pico eight-switch reader on three pins?

Raspberry Pi Pico H, 74HC165 parallel-in shift register, Tactile push button 6 mm × 8, Resistor 10 kΩ × 8 and Breadboard 830 Tie Points.

How long does the pico eight-switch reader on three pins take to build?

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

How do I know the pico eight-switch reader on three pins works?

Nothing pressed: none. Press button 1: Buttons down: 1. Press button 8: Buttons down: 8.

Always shows some buttons down: what should I check?

Check each input has a 10 kilo-ohm resistor to GND, a floating input reads random.

Buttons in the wrong order: what should I check?

Check which chip pin each button uses, button 1 is pin 14 and button 8 is pin 6.

Nothing ever changes: what should I check?

Check pin 15 is on GND and the load and clock pins are not swapped.

Wrong results: what should I check?

The load pin must go low then high before shifting.