yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
Raspberry Pi Pico 2📖
1. About Pico 2
  • Introduction to Raspberry Pi PICO 2
2. Development-python
  • 1. Flash the firmware
  • 2. Software environment configuration
  • 3. Download a program
3. Development-C
  • 1. Software environment configuration
  • 2. Download a program
4. Python course
  • 1. Flash the onboard LED light
  • 2. Onboard temperature sensor reading
  • 3. Button control LED light
  • 4. Buzzer
  • 5. PWM pin
5. C course
  • 1. Flash the onboard LED light
  • 2. Onboard temperature sensor reading
  • 3. Button control LED light
  • 4. Buzzer
  • 5. PWM pin
Download
  • C software
  • Python software
  • Official information
Download ZIP

Welcome to Raspberry Pi Pico 2 repository

3. Button control LED light

3. Button control LED light

1. Learning objectives

  1. Learn the basic use of the pins of the Raspberry Pi Pico 2 .
  2. Understand how to control the LED light with buttons.

2. Hardware construction

This course.

LED light*1

Button*1

220Ω resistor*1

The circuit wiring diagram is as follows:

image.png

3. Program analysis

Thonny programming

For the use of ThonnyIDE, please refer to the previous environment construction related courses.

​x
import machine
import utime
​
led_external = machine.Pin(15, machine.Pin.OUT)
button = machine.Pin(14, machine.Pin.IN)
​
while True:
    if button.value() == 1:
        led_external.value(1)
        utime.sleep(2)
    led_external.value(0)

import machine

The machine library contains all the instructions MicroPython needs to communicate with Pico and other MicroPython-compatible devices, extending the language of physical computing.

 

import utime

The "utime" library. This library handles everything to do with time, from measuring it to inserting delays into your program. The units are in seconds.

 

led_external = machine.Pin(15, machine.Pin.OUT)

Configure IO15 as an output pin.

 

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

Configure IO14 as an input pin.

 

button.value()

Get the value of the button pin.

 

led_external.value(1)

Set the LED light pin to a high level.

 

utime.sleep(2)

This calls the sleep function from the utime library, which will pause the program for any number of seconds you type - in this case, 2 seconds.

 

4. Experimental phenomenon

After the program is downloaded, press the button and the LED light will turn on for 2 seconds.

Onboard temperature sensor reading
Buzzer

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文