You can build a wireless remote control RGB LED NeoPixel color mixer using two Circuit Playground Bluefruit boards and some slide potentiometers. Using Bluetooth LE, the boards can communicate wirelessly with no need for a computer or mobile phone or tablet!

Thanks to the Adafruit Bluefruit Connect and BLE libraries in CircuitPython, setup and coding are incredibly simple. You can get started quickly and then extend this code to all sorts of other remote projects!

Parts

First of all, you'll need two Circuit Playground Bluefruit boards:

shot of a Black woman's neon-green manicured hand holding up a Circuit Playground Bluefruit glowing rainbow LEDs.
Circuit Playground Bluefruit is our third board in the Circuit Playground series, another step towards a perfect introduction to electronics and programming. We've...
$24.95
In Stock
2 x Circuit Playground Bluefruit BLE
ALPHA - Bluetooth Low Energy

To control the color settings, you'll need three slide potentiometers. These short ones work on a breadboard quite well, any longer and you'll need to come up with more involved solutions for mounting.

hand slowly sliding potentiometer back and forth - 35mm Long.
Slip slidin' away Slip slidin' away You know the nearer your resistance The more you're slip slidin' awayIf you're...
$1.95
In Stock
3 x Slide Potentiometer - 35mm Long
10KΩ with Plastic Cap
Half Size Breadboard and 78 Piece Jumper Wire in various lengths
This is a cute half-size breadboard with an assortment of small jumper wires, great for prototyping. The breadboard is 2.2" x 3.4" (5.5 cm x 8.5 cm) with a standard...
Out of Stock

Or, if you already have jumper wire:

Angled shot of half-size solderless breadboard with red and black power lines.
This is a cute, half-size breadboard with 400 tie points, good for small projects. It's 3.25" x 2.2" / 8.3cm x 5.5cm with a standard double-strip in the...
$4.95
In Stock
Group of Small Alligator Clip to Male Jumper Wires
When working with unusual non-header-friendly surfaces, these handy cables will be your best friends! No longer will you have long, cumbersome strands of alligator clips. These...
$3.95
In Stock

Optional

Top down view of a clear acrylic Adafruit Circuit Playground Express or Bluefruit Enclosure.
We've got nice cases for many of our beloved boards, but the Circuit Playground Express and
$4.95
In Stock
Fully Reversible Pink/Purple USB A to micro B Cable
This cable is not only super-fashionable, with a woven pink and purple Blinka-like pattern, it's also fully reversible! That's right, you will save seconds a day by...
$3.95
In Stock

Install or Update CircuitPython

Follow this quick step-by-step to install or update CircuitPython on your Circuit Playground Bluefruit.

Click the link above and download the latest UF2 file

Download and save it to your Desktop (or wherever is handy)

Plug your Circuit Playground Bluefruit into your computer using a known-good data-capable USB cable.

A lot of people end up using charge-only USB cables and it is very frustrating! So make sure you have a USB cable you know is good for data sync.

Double-click the small Reset button in the middle of the CPB (indicated by the red arrow in the image). The ten NeoPixel LEDs will all turn red, and then will all turn green. If they turn all red and stay red, check the USB cable, try another USB port, etc. The little red LED next to the USB connector will pulse red - this is ok!

If double-clicking doesn't work the first time, try again. Sometimes it can take a few tries to get the rhythm right!

(If double-clicking doesn't do it, try a single-click!)

You will see a new disk drive appear called CPLAYBTBOOT.

 

 

 

Drag the adafruit_circuitpython_etc.uf2 file to CPLAYBTBOOT.

The LEDs will turn red. Then, the CPLAYBTBOOT drive will disappear and a new disk drive called CIRCUITPY will appear.

That's it, you're done! :)

Libraries

Once you've gotten CircuitPython onto your Circuit Playground Bluefruit boards, it's time to add some libraries. You can follow this guide page for the basics of downloading and transferring libraries to the board.

From the library bundle you downloaded in that guide page, transfer the following libraries onto the CPB boards' /lib directories:

  • neopixel.mpy
  • adafruit_ble
  • adafruit_bluefruit_connect

Text Editor

Adafruit recommends using the Mu editor for using your CircuitPython code with the Circuit Playground Bluefruit boards. You can get more info in this guide.

Alternatively, you can use any text editor that saves files.

Central

Next we'll code the CPB that will act as the Central/client device. This is the one that will have the slide pots on it and will send out RGB color data packets to the peripheral device.

Copy the code below and paste it into Mu. Then, save it to your CPB as code.py.

# SPDX-FileCopyrightText: 2019 John Edgar Park for Adafruit Industries
#
# SPDX-License-Identifier: MIT

"""
Demonstration of a Bluefruit BLE Central/client. Connects to the first BLE UART peripheral it finds.
Sends Bluefruit ColorPackets, read from three potentiometers, to the peripheral.
"""

import time

import board
from analogio import AnalogIn

#from adafruit_bluefruit_connect.packet import Packet
# Only the packet classes that are imported will be known to Packet.
from adafruit_bluefruit_connect.color_packet import ColorPacket

from adafruit_ble import BLERadio
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
from adafruit_ble.services.nordic import UARTService

def scale(value):
    """Scale an value from 0-65535 (AnalogIn range) to 0-255 (RGB range)"""
    return int(value / 65535 * 255)

ble = BLERadio()

a4 = AnalogIn(board.A4)
a5 = AnalogIn(board.A5)
a6 = AnalogIn(board.A6)

uart_connection = None

# See if any existing connections are providing UARTService.
if ble.connected:
    for connection in ble.connections:
        if UARTService in connection:
            uart_connection = connection
        break

while True:
    if not uart_connection:
        for adv in ble.start_scan(ProvideServicesAdvertisement, timeout=5):
            if UARTService in adv.services:
                uart_connection = ble.connect(adv)
                break
        # Stop scanning whether or not we are connected.
        ble.stop_scan()

    while uart_connection and uart_connection.connected:
        r = scale(a4.value)
        g = scale(a5.value)
        b = scale(a6.value)

        color = (r, g, b)
        print(color)
        color_packet = ColorPacket(color)
        try:
            uart_connection[UARTService].write(color_packet.to_bytes())
        except OSError:
            pass
        time.sleep(0.3)

Peripheral

The second CPB will act as a peripheral device. It will receive the RGB color data packets from the client and update the NeoPixel color to match the data.

Copy the code below and paste it into a new document in Mu, then save it to your second CPB as code.py.

# SPDX-FileCopyrightText: 2019 John Edgar Park for Adafruit Industries
#
# SPDX-License-Identifier: MIT

"""
Used along with cpb_remote_color_client.py. Receives Bluefruit LE ColorPackets from a central,
and updates NeoPixels to show the history of the received packets.
"""

import board
import neopixel

from adafruit_ble import BLERadio
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
from adafruit_ble.services.nordic import UARTService

from adafruit_bluefruit_connect.packet import Packet
# Only the packet classes that are imported will be known to Packet.
from adafruit_bluefruit_connect.color_packet import ColorPacket

ble = BLERadio()
uart = UARTService()
advertisement = ProvideServicesAdvertisement(uart)

NUM_PIXELS = 10
np = neopixel.NeoPixel(board.NEOPIXEL, NUM_PIXELS, brightness=0.1)
next_pixel = 0

def mod(i):
    """Wrap i to modulus NUM_PIXELS."""
    return i % NUM_PIXELS

while True:
    # Advertise when not connected.
    ble.start_advertising(advertisement)
    while not ble.connected:
        pass

    while ble.connected:
        packet = Packet.from_stream(uart)
        if isinstance(packet, ColorPacket):
            print(packet.color)
            np[next_pixel] = packet.color
            np[mod(next_pixel + 1)] = (0, 0, 0)
        next_pixel = (next_pixel + 1) % NUM_PIXELS

Next we'll assemble the parts to use our color mixer!

I love using slide potentiometers (a.k.a. faders) for this type of project, because at a glance you can tell how much of each color is selected. One problem that can arise, however, when using slide pots, is that they don't usually fit easily on a breadboard or perma proto board. These adorable little 35mm faders solve this problem! Since the bottom pin that is labeled "3" is the ground pin, all of the faders can share the common ground rail on the breadboard!

Slide Pots

Each slide potentiometer will act as a voltage divider, with the Circuit Playground Bluefruit analog pins reading the wiper's varying output.

The pin assignments are as follows:

  • Pin 1 = 3.3VDC
  • Pin 2 = wiper (to analog input)
  • Pin 3 = ground

Insert the three slide potentiometers into the breadboard as shown. You want the pin 3 legs of all three pots to be placed into the ground rail (next to the blue line).

Insert pins 1 and 2 so there is a free row of breadboard pins above them, this is where you'll make the wired connections to the CPB.

 

Wiring to Voltage

Use three small jumper wires (sometimes called "staples") to connect the pin 1 of each slide pot to the red +V rail of the breadboard as shown here. Looking from the top down, pin 1 is the pin on the left at the top of each slide pot.

Connections to Circuit Playground Bluefruit

Now we can use alligator clip leads with male header pins to connect the sliders to the CPB.

Insert the red lead into the breadboard's top red +V rail.

Insert the black lead into the breadboard's bottom black ground rail.

Insert the yellow lead into the left slider's pin 2 column on the breadboard.

Insert the green lead into the middle slider's pin 2 column on the breadboard.

Insert the blue lead into the right slider's pin 2 column on the breadboard.

Now, you can connect the alligator clips to the associated pads on the Circuit Playground Bluefruit:

  • red to 3.3V
  • black to GND
  • yellow to A4
  • green to A5
  • blue to A6

Power

You can now power up the Circuit Playground Bluefruit boards -- here I've used 3.7VDC LiPoly batteries plugged into the battery JST-SH ports. You can also use AA or AAA battery packs, or power over the USB port.

Remote Color Mixing

After a moment, the two boards will start up, and the mixer CPB will begin sending Bluetooth LE packets containing RGB color data based on the slider positions. The other CPB will listen for those packets and light up its NeoPixels in accordance with the RGB values.

Here you can see each slider used individually for pure red, green, and blue values, and then a mix of partial red and blue for a pink color. Try different combinations to mix your own colors!

This guide was first published on Oct 22, 2019. It was last updated on Apr 18, 2024.