Project
Reading Button Presses with KY-004 on Raspberry Pi Pico
Overview
Learn how to use the KY-004 push button module with a Raspberry Pi Pico. This project is useful for manual controls, reset buttons, menu navigation, and simple input projects.
Instructions
Step by step
1. Connect the KY-004 VCC pin to 3.3V.
2. Connect the KY-004 GND pin to GND.
3. Connect the KY-004 S pin to GP14.
4. Run the code and open the Serial/console output.
5. Click or toggle the KY-004 button in the simulator.
6. When the button is pressed, the output should print "Button pressed".
7. When the button is released, the output should print "Button released".
Code
Source code
from machine import Pin
import utime
button = Pin(14, Pin.IN, Pin.PULL_UP)
while True:
if button.value() == 0:
print("Button pressed")
else:
print("Button released")
utime.sleep(0.5)
Related