Raspberry Pi Pico - LED Module

The little green LED soldered on the Pico board is handy for a first test, but it is tiny and hidden under your wires once a project is built. When you want a status light that people can actually see from across the room, a 10mm LED module is an easy upgrade: it plugs into three Pico pins, and it needs no resistor and no thinking about LED legs.

In this guide, we will learn to set up and use the LED module with the Raspberry Pi Pico. We will cover the following details:

Raspberry Pi Pico and LED module

Hardware Preparation

1×Raspberry Pi Pico W
1×Raspberry Pi Pico Alternatively,
1×Micro USB Cable
1×LED Module
1×Breadboard
1×Jumper Wires
1×Recommended: Screw Terminal Expansion Board for Raspberry Pi Pico

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Buy Note: Use the LED Module for easier wiring. It includes an integrated resistor.

Overview of LED Module

This module is a 10mm diffused LED that already has its helpers on board. A 330Ω resistor limits the LED current, and a small transistor does the switching. The LED gets its power from the VCC pin. The Pico's IN signal only tells the transistor "on" or "off", through a 1KΩ resistor, so the GPIO pin gives almost no current. This matters on the Pico: its GPIO pins work at 3.3 volts and are made for small currents, but the LED still shines at full brightness because the transistor does the heavy work.

The board is 20mm x 20mm and comes in a pack of five colors: red, yellow, blue, green and white. Every color uses the same wiring and the same code.

LED Module
LED 10mm, round, diffused
Colors red, yellow, blue, green, white
Operating Voltage 3.3V to 5V DC
Logic active HIGH (IN = 1 means ON)
On-board Parts 330Ω LED resistor, 1KΩ input resistor, transistor
Header 3-pin, 2.54mm pitch, right-angle, presoldered
Board Size 20mm x 20mm

Pinout

The pins are printed on the board in this order: GND, VCC, IN.

  • GND pin: connect to GND (0 volts)
  • VCC pin: connect to VCC (3.3 volts or 5 volts). This pin powers the LED.
  • IN pin: connect to a Raspberry Pi Pico GPIO pin. Set it to 1 to light the LED, set it to 0 to turn it off. Send a PWM signal to change the brightness.
LED module pinout
image source: diyables.io

Compared with a bare LED, there is nothing to get wrong here. A bare LED has an anode and a cathode that must go the right way round, and it needs a series resistor (like the 220 ohm one in our blink LED tutorial). The module has labeled pins and the resistor is already on it.

Wiring Diagram

Only three wires are needed. Take power from the Pico's 3V3(OUT) pin, so the whole circuit stays at the same 3.3 volt level as the Pico's GPIO pins. For the IN pin we use GP13, the same pin as our other Pico LED tutorials. Like almost every Pico GPIO pin, GP13 can output PWM, so the same wiring works for both the blink code and the fade code.

The wiring diagram between Raspberry Pi and Pico LED module

This image is created using Fritzing. Click to enlarge image

LED Module Raspberry Pi Pico
GND GND
VCC 3V3(OUT)
IN GP13

Raspberry Pi Pico Code - Fade the LED Module

Because the module turns on when IN is HIGH, a PWM signal on IN changes how long the LED is on in each tiny cycle, and our eyes see that as brightness. The Pico sets PWM with duty_u16(), which takes a 16-bit number from 0 to 65535. To make the code easier to read, the script below works in percent (0 to 100) and converts it in a small helper function.

""" This Raspberry Pi Pico MicroPython code was developed by newbiely.com This Raspberry Pi Pico code is made available for public use without any restriction For comprehensive instructions and wiring diagrams, please visit: https://newbiely.com/tutorials/raspberry-pico/raspberry-pi-pico-led-module """ from machine import Pin, PWM from time import sleep # The Raspberry Pi Pico pin GP13 connected to the IN pin of the LED module LED_MODULE_PIN = 13 led_module = PWM(Pin(LED_MODULE_PIN)) led_module.freq(1000) # 1kHz PWM is fast enough that the eye sees no flicker # Turn a brightness in percent (0-100) into the Pico's 16-bit duty value (0-65535) def set_brightness(percent): led_module.duty_u16(int(percent * 65535 / 100)) while True: # Fade in: 0% -> 100% for percent in range(0, 101, 5): set_brightness(percent) print("Brightness:", percent, "%") sleep(0.05) # Fade out: 100% -> 0% for percent in range(100, -1, -5): set_brightness(percent) print("Brightness:", percent, "%") sleep(0.05)

Detailed Instructions

The wiring stays the same, so only the code changes:

  • Stop the running script with the red Stop button in Thonny.
  • Copy the fade code above and paste it into the editor, replacing the blink code.
  • Save it to the Raspberry Pi Pico as main.py (this overwrites the blink script).
  • Click the green Run button (or press F5).
  • The LED module slowly gets brighter, then slowly dims, in a loop of about two seconds. The Shell shows each brightness step:
Shell x
>>> %Run -c $EDITOR_CONTENT
MPY: soft reboot Brightness: 0 % Brightness: 5 % Brightness: 10 % Brightness: 15 % ... Brightness: 95 % Brightness: 100 % Brightness: 95 % Brightness: 90 % ... Brightness: 5 % Brightness: 0 %
MicroPython (Raspberry Pi Pico) • Board CDC @ COM29 ≡

Want a slower "breathing" effect? Change sleep(0.05) to sleep(0.1). Want smoother steps? Change the step size 5 in both range() lines to 1 or 2.

Code Explanation

The comments inside both scripts explain each line. In short: the blink script writes 1 or 0 to GP13 with value(), and the fade script hands GP13 to the PWM class at 1kHz and changes the duty value step by step. If you want to see how the same PWM idea works with a plain LED and a resistor, read the Raspberry Pi Pico - Fade LED tutorial.

※ NOTE THAT:

Both scripts use sleep(), so the Pico does nothing else while it waits. That is fine for a simple light. If your project must also read buttons or sensors at the same time, see Raspberry Pi Pico - Blink LED Without Sleep.

Video Tutorial

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!