KevsRobots Learning Platform
80% Percent Complete
By Kevin McAleer, 3 Minutes
Page last updated June 15, 2025
Now that you’ve written a program and sent it to your Raspberry Pi Pico, it’s time to interact with the real world using the Pico’s GPIO pins.
GPIO stands for General Purpose Input/Output — these are the physical pins on your Pico that can send or receive digital signals.
⚠️ Be sure to connect the long leg (anode) of the LED to the GPIO pin, and the short leg (cathode) to GND through the resistor.
You can use the mnemonic - ‘long is live’ to remember that the long leg is positive (anode) and connects to the GPIO pin.
The Raspberry Pi Pico has 26 usable GPIO pins (0–28, skipping 23–24).
Each pin can be configured as:
Here’s the simplest GPIO example — we’ll just turn a pin HIGH, wait a bit, then turn it LOW.
#include "pico/stdlib.h"
int main() {
const uint LED_PIN = 15;
gpio_init(LED_PIN);
gpio_set_dir(LED_PIN, GPIO_OUT);
while (true) {
gpio_put(LED_PIN, 1); // HIGH
sleep_ms(1000);
gpio_put(LED_PIN, 0); // LOW
sleep_ms(1000);
}
}
Replace
15
with the GPIO pin number you connected your LED to.
gpio_init(pin)
sets up the pin for usegpio_set_dir(pin, GPIO_OUT)
makes the pin an outputgpio_put(pin, value)
sends a HIGH (1
) or LOW (0
) signalsleep_ms(ms)
pauses the program for the given millisecondssleep_ms()
valuestrue
and false
instead of 1
and 0
You now know how to:
In the next lesson, you’ll combine all of this into the classic blinking LED project using your own circuit.
Next up: Blinking an LED
You can use the arrows ← →
on your keyboard to navigate between lessons.