Beginner’s Guide to Programming NeoPixel RGB LEDs with Pico & MicroPython
![]()
Table of Contents
Abstract
In this beginner-friendly tutorial, you’ll learn how to connect and program NeoPixel RGB LEDs using the Raspberry Pi Pico. With the help of MicroPython and Wokwi simulation, we’ll walk through step-by-step code examples to control colors, patterns, and simple animations. By the end, you’ll be ready to add vibrant lighting effects to your own projects with ease.
In this article, a comprehensive step-by-step guide to interface Analog data (Potentiometer) with Raspberry Pi Pico board using MicroPython. Raspberry Pi Pico has 4 different variants (Pico, Pico 2, Pico W, Pico 2W) supporting micro-python. This articles lays the foundation for more advanced embedded system and IoT projects.
Pre-Request
- OS : Windows / Linux / Mac / Chrome
- Thonny IDE.
- MicroPython firmware in Raspberry Pi Pico / Pico 2 / Pico W / Pico 2W.
- For step by step procedure click here .
Hardware Required
- Raspberry Pi Pico / Pico 2 / Pico W / Pico 2W.
- NeoPixel / WS2812B.
- BreadBoard.
- Micro USB Cable.
- Connecting wires.
- 5V DC power supply (optional)
| Components | Purchase Link |
|---|---|
| Raspberry Pi Pico | link |
| Raspberry Pi Pico 2 | link |
| Raspberry Pi Pico W | link |
| Raspberry Pi Pico 2W | link |
| NeoPixel | 16 LED : 8 LED |
| BreadBoard | large : small |
| Connecting Wires | link |
| Micro USB Cable | link |
Don't own a hardware
No worries,
Still you can learn using simulation.
check out simulation part .
Connection Table
| NeoPixel | GPIO | Remarks |
|---|---|---|
| GND | GND | |
| Vcc | +5 V | +5V of Board or External 5V DC Supply |
| Din | 21 | Any GPIO pin can be used. |
| Dout | -- | No Connection |
Note
- While using External 5 V supply, make sure ground pin of External Supply and Pico board is connected.

fig-Connection Diagram
Code
Code Explanation
Imports
timemodule for creating delay.neopixelmodule for interacting with WS2812 / NeoPixel LED.
Initialize NeoPixel LED.
- GPIO
21is connected toDinof NeoPixel LED. 16NeoPixel LED's are used in the strip (np = NeoPixel(pin, 16))
Initializing list of Color values.
- Color values are configured in RGB mode
- Each tuple represents a RGB color code
- (R, G, B)
- (255, 0, 0) --> Red 255, Green 0, Blue 0
- Each color value range from 0 to 255
Setting the color.
np.fill(<color_r_g_b>): fills the color to all the led.np[i]: Set the color to theiith LEDnp.write(): Usewritemethod to observe the effect on the LED.- Only after execution of the
writemethod, you can observe the changes in the LED color.
- Only after execution of the
forloop in the code is used to loop through the color on individual led in clockwise and anti-clockwise direction.
Simulation
Not able to view the simulation
- Desktop or Laptop : Reload this page ( Ctrl+R )
- Mobile : Use Landscape Mode and reload the page
Extras
Components details
- NeoPixel LED / WS2812B : Data Sheet
- Raspberry Pi Pico / Pico 2 : Pin Diagram
- Raspberry Pi Pico : Data Sheet
- Raspberry Pi Pico 2 : Data Sheet
- Raspberry Pi Pico W : Data Sheet
- Raspberry Pi Pico 2 W : Data Sheet
Modules / Libraries Used
- machine
machinemodule contains specific attributes and methods related to hardware on a particular board. Here classADCis imported to configure the Analog pins.- More Details
- time
timemodule provides functions related to date & time, measuring time intervals and generating delays.- More Details