Board and part

Raspberry Pi Pico LED Simulator: Wiring, Code and a Live Circuit

This is a red LED with a 220 ohm resistor, wired to a Raspberry Pi Pico and blinking live in your browser. The serial monitor prints LED on and LED off as the pin changes.

  • 3.3 V logic
  • No library
  • Pin GP15 (physical pin 20)
  • 220 ohm resistor
Raspberry Pi Pico · LEDlive0.000 s 0.00x
Click to open it in the editor
The circuit itself, running on the simulator with the sketch below. Press what can be pressed; click anything else to open it in the editor.
Connections

Wiring the LED to the Raspberry Pi Pico

Two connections matter: the pin to the resistor and the resistor to the LED’s anode, then the cathode to ground. The pin is GP15 (physical pin 20) and the supply behind it is 3.3 V.

Every connection in the circuit above, with the board’s own pin names.

LED pinRaspberry Pi Pico pinWhy
A (anode)GP15 (physical pin 20)The long leg. Current flows in here, so it takes the signal, with the resistor in the way.
C (cathode)GNDThe short leg, on the flat side of the lens, goes to ground.
220 ohm resistorIn series with the anodeLimits the current. Without it the LED, the pin or both burn out.

Power

A red LED drops about 2 V, so with 220 ohm in series a 3.3 V pin pushes about 6 mA through it: bright enough to see and gentle on the pin. The resistor can sit on either side of the LED; what matters is that it is in the loop.

Pins to leave alone on the Raspberry Pi Pico

The numbers in the code are GP numbers, not the physical pin numbers printed beside the header: GP15 is pin 20. GP23 to GP25 are used on the board itself, and GP25 is the LED.

On a real bench

Solder headers on the Pico and press it into the breadboard across the center channel; the LED goes in beside it. GND pins sit every fifth pin down both sides (pins 3, 8, 13, 18 and so on), so there is always one close. The first upload needs BOOTSEL held while plugging in.

The sketch

The code, and what it does.

The sketch the circuit above runs. Open it in the editor, change a line and press Run: it compiles in your browser.

Blinking an LED on Raspberry Pi Pico GP15 (physical pin 20)
const int LED_PIN = 15;   // GP15 (physical pin 20), through a 220 ohm resistor to the LED

void setup() {
  Serial.begin(115200);
  pinMode(LED_PIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_PIN, HIGH);
  Serial.println("LED on");
  delay(500);
  digitalWrite(LED_PIN, LOW);
  Serial.println("LED off");
  delay(500);
}

pinMode(LED_PIN, OUTPUT) makes GP15 (physical pin 20) drive its level instead of listening to it. digitalWrite(LED_PIN, HIGH) puts 3.3 V on the pin, which pushes current through the resistor and the LED to ground, and LOW takes it away.

delay(500) holds each state for half a second, so the LED blinks once a second. While delay() waits the board does nothing else; a sketch that must also do other work times itself with millis() instead.

Serial.begin(115200) opens the serial monitor. Serial is the USB port at 115200 baud in this sketch; on a real Pico it appears once the board has enumerated.

Pitfalls

Common mistakes with the LED on the Raspberry Pi Pico

Putting the LED in backwards

An LED passes current one way only. Backwards it stays dark and nothing is damaged. If it never lights, swap its two legs: the long leg, the anode, faces the signal.

Leaving out the resistor

An LED has almost no resistance once it conducts, so the only limit on the current is the pin. At 3.3 V that is far more than the LED’s 20 mA rating. The simulator burns the LED out and shows it dark for good, as a real one goes.

Counting physical pins instead of GP numbers

The sketch says 15, which means GP15, and that is physical pin 20 on the header. Counting 15 pins down the side lands on a different GPIO, and the part never answers.

FAQ

Questions and answers

How do I connect an LED to a Raspberry Pi Pico?

Wire GP15 (physical pin 20) to a 220 ohm resistor, the resistor to the LED’s long leg, and the LED’s short leg to GND. In the sketch call pinMode(15, OUTPUT) and digitalWrite(15, HIGH).

What resistor value should I use?

Subtract the LED’s drop, about 2 V for red, from the pin’s 3.3 V and divide by the current you want. For 10 mA that is 130 ohm; 220 ohm is the common value because it is safe for any color.

Can I run an LED without a resistor on a pin?

No. The pin has no way to limit the current, so the LED or the pin is damaged. Always put a resistor in series.

Why does my LED stay dim?

Either the resistor is too large, or the pin is being driven with PWM at a low duty. A 220 ohm resistor with digitalWrite(HIGH) gives full brightness.

Build your own LED project

Open this circuit in the editor, change the wiring or the code, and keep your version in a free account.