Connect a switch

cable

Code a switch

cable

cable Wire a switch

A Raspberry Pi Pico with 1 socket to socket jumper wire attached to the GND pin and 1 pin to socket attached to GP18.
Use 1 socket-to-socket jumper wire and 1 pin-socket jumper wire.

play_circle stop_circle
# Import the Switch component
from picozero import Switch
from time import sleep

# Set up Switch with correct pin number  
switch_1 = Switch(18)

# Check Switch state in a loop
while True:
    if switch_1.is_closed:
        print("Switch is closed")
    else:
        print("Switch is open")   
    sleep(0.1) # small delay

bug_report My Switch doesn't work

  • Check your connections.
  • Check the pin number in your code.
  • Check that your code is indented correctly.