Raspberry Pi Pico RGB LED Magic Light Ball

At first glance, using a microcontroller for a simple fancy light project is overkill. However, the existing design can be modified later without additional hardware. Often a few extra code lines will suffice for that expansion.

This is an idea for a RGB LED Magic Light Ball using a Raspberry Pi Pico.

Hardware Setup

The schematic is quite simple. The entire setup is powered from a 1S (3.7V) Lithium-Polymer battery. A common-cathode RGB LED is used as the light source. And a set of three GPIOs of Raspberry Pi Pico (GP13-14-15) is used to drive the RGB LED. You can see that the RGB drive signals are also available for panoptic applications. You can use them to handle light emitting diodes/incandescent lamps thru a suited multichannel lamp driver circuitry. I hope you can follow this!

Note that, VSYS is the main system input voltage which can vary in the advocated 1.8V to 5.5V range and is used by the on-board power circuitry to generate 3.3V for the RP2040 and its GPIOs.

The key parts required at this time are:

  • U1: Raspberry Pi Pico x1
  • LED1: 5mm/10mm RGB LED (Common-Cathode) x1
  • R1: 100Ω ¼ W Resistor
  • R2: 47Ω ¼ W Resistor
  • R3: 47Ω ¼ W Resistor
  • S1: Slide Switch (SPDT) x1
  • BAT: 1S Lithium-Polymer Battery (3.7V/500mAh) x1

An RGB LED, capable of displaying thousands of color combinations, contains three LEDs in one package – Red, Green, and Blue. Significantly, there’re two RGB LED types – the common-anode and the common-cathode.

Below is the pinout of a generic common-cathode RGB LED.

First, I tested my RGB LED using a Chinese LED tester independently and measured the forward voltage (VF) of each LED segment at a constant forward current (IF) of 20mA. These are the results.

RED ~1.8V
BLUE ~3.0V

Thus, I roughly finalized the values ​​of the series resistors (R1-R2-R3). If the resistance values ​​suggested above do not match the RGB LED of your choice, you can certainly try other fitting resistance values ​​to build your prototype.

There’re a few other “Pico” things to consider as well. You’ll get all relevant details straight from the official source through this link https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf.

Code Example

I’ve borrowed some code snippets from the fastidious examples found on the Maker Portal site (https://makersportal.com/) to ornament my raw code. However, playing with the code below and building the project is at your own risk. Check all connections at least twice before applying power!

import time

from machine import Pin,PWM

pwm_pins = [13,14,15]

pwms = [PWM(Pin(pwm_pins[0])),PWM(Pin(pwm_pins .)[1])),

PWM(Pin(pwm_pins .)[2]))]]

[pwm.freq(1000) for pwm in pwms]

step_val = 64

range_0 = [ii for ii in range(0,2**16,step_val)]

range_1 = [ii for ii in range(2**16,-step_val,-step_val)]

while True:

for pwm in pwms:

for ii in range_0+range_1:



After uploading the code and powering the hardware up, you’ll see the RGB LED changing the color smoothly in real-time. If you want to make something more complex, now is the time to think about more RGB LEDs to fill up the light bar with rich colors, and/or to add some extra piece of hardware to make a sound-reactive light ball. The example code could be easily tweaked to fulfil your elaboration dreams.

Enclosure Theme

Finding the right enclosure for this project can be a bit daunting, but you can try a ready-made or 3D printed translucent ball as you wish. You may also find beautiful acrylic diamond crystal balls (see below) at your nearest store.

Power Drive!

Now you can do many things with your prototype. There are cheap RGB LED Strips based on SMD5050LEDs. Each of these chips contains a red, a green and a blue LED. Depending on which colors are active, the result is a mixed colour. If a specific color is set, typically the entire LED-Strip takes that one colour.

As mentioned before, the RGB outputs from Raspberry Pi Pico can be used to drive external lamps, but only thru a befitted 3-channel lamp driver circuit. This however does not require much effort and even laymen should do it. I’ve already posted a lot of tutorials explaining how to control RGB LED Strips with 5V/3.3V microcontrollers.

Recall, a quick solution to this is logic-level N-Channel MOSFETs. You can of course use BJTs, but MOSFETs are better in my opinion. As you can see below it’s rather simple.

Note at this point that A logic-level MOSFET is designed to turn on fully from the logic level of a microprocessor. You may consider the FQP30N06L MOSFET for your next Rpi Pico projects (https://www.onsemi.com/pdf/datasheet/fqp30n06l-d.pdf).

What’s Next?

Recently I collected several Chinese LED party/disco lights to try out some funny hack ideas. The first trick is to drive the LED assembly inside the lamp through my Raspberry Pi Pico setup while holding the orbing mechanism and power supply section of the lamp intact.

I’ll keep working on it but if anyone has some suggestions, I would be very grateful.

Finally, I hope you liked this little tutorial. Should there be any question or remark, feel free to leave a comment here. I am open to all feedback!

Leave a Comment