Ramji Patel
Published © GPL3+

Raspberry Pi Pico and Button

Interfacing a button to raspberry Pi Pico and controlling your devices such as an LED Using Button.

BeginnerProtip1 hour12,386
Raspberry Pi Pico and Button

Things used in this project

Hardware components

Solderless Breadboard Full Size
Solderless Breadboard Full Size
×1
PTS 645 Series Switch
C&K Switches PTS 645 Series Switch
×1
LED (generic)
LED (generic)
×1
Through Hole Resistor, 330 ohm
Through Hole Resistor, 330 ohm
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×1
Raspberry Pi Pico
Raspberry Pi Pico
×1

Software apps and online services

Thonny

Story

Read more

Schematics

Button test schematic pdf

Button test schematic pdf

Raspberry pi pico and button schematic pdf

Code

Read the button

MicroPython
from machine import Pin
import time

button = Pin(14, Pin.IN, Pin.PULL_UP)

while True:
    if button.value() == 0:
        print('Button is pressed')
    else:
        print('Button is not pressed')
    time.sleep(0.1)

Control LED with button

MicroPython
from machine import Pin
import time

button = Pin(14, Pin.IN, Pin.PULL_UP)
led = Pin(15, Pin.OUT)

while True:
    if button.value() == 0:
        led.value(1)
    else:
        led.value(0)
    time.sleep(0.1)

Toggle LED with button

MicroPython
from machine import Pin
import time

button = Pin(14, Pin.IN, Pin.PULL_UP)
led = Pin(15, Pin.OUT)

while True:
    if button.value() == 0:
        led.toggle()
        time.sleep(0.5)

Credits

Ramji Patel

Ramji Patel

26 projects • 18 followers
Myself Ramji Patel. I am an Engineering student and pursuing my B-Tech from Institute of engineering and rural Technology Prayagraj, India.

Comments