The Adafruit Sparkle Motion Stick has an IR Receiver built-in for all of your remote controlling needs. The Adafruit CircuitPython IRRemote library makes it easy to decode the signals sent to the receiver. This example will get you started by demonstrating how to use one of our mini remote controls to change the color and brightness of a connected strip of NeoPixels.
The IR Receiver is connected with the pin alias board.IR
. This example assumes the NeoPixel strip will be plugged in to the terminal blocks for pin board.D21
.
Necessary Hardware
You can use any IR remote with basic NEC codes that are supported by the Adafruit CircuitPython IRRemote library, and any NeoPixel strip that you like. The following items are the ones depicted on this page.


NeoPixels
- terminal block - to GND on the NeoPixel strip. (black wire)
- terminal block + to 5V on the NeoPixel strip. (red wire)
- terminal block 21 to DIN on the NeoPixel strip. (green wire)
CircuitPython Usage
To use with CircuitPython, you need to first install a few libraries, into the lib folder on your board. Then you need to update code.py with the example script.
In the example below, click the Download Project Bundle button below to download the necessary libraries and the code.py file in a zip file. Extract the contents of the zip file, open the directory Sparkle_Motion_Examples/CircuitPython_Sparkle_Motion_IR_Remote/ and then click on the directory that matches the version of CircuitPython you're using.
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-FileCopyrightText: 2025 Tim Cocks for Adafruit Industries # SPDX-License-Identifier: MIT """CircuitPython Adafruit Sparkle Motion IR remote control NeoPixels example.""" import time import board import pulseio from rainbowio import colorwheel import neopixel import adafruit_irremote pulsein = pulseio.PulseIn(board.IR, maxlen=120, idle_state=True) decoder = adafruit_irremote.NonblockingGenericDecode(pulsein) IR_CODE_UP = (0, 253, 160, 95) IR_CODE_DOWN = (0, 253, 176, 79) IR_CODE_RIGHT = (0, 253, 80, 175) IR_CODE_LEFT = (0, 253, 16, 239) t0 = next_heartbeat = time.monotonic() pixel = neopixel.NeoPixel(board.D21, 8) brightness = 1 pixel.brightness = brightness / 10 color_number = 160 pixel.fill(colorwheel(color_number)) while True: for message in decoder.read(): print(f"t={time.monotonic() - t0:.3} New IR Message") if isinstance(message, adafruit_irremote.IRMessage): if message.code == IR_CODE_UP: brightness = min(brightness + 1, 10) elif message.code == IR_CODE_DOWN: brightness = max(brightness - 1, 0) elif message.code == IR_CODE_RIGHT: color_number = (color_number + 32) % 256 elif message.code == IR_CODE_LEFT: color_number = (color_number - 32) % 256 pixel.brightness = brightness / 10 pixel.fill(colorwheel(color_number)) print("Decoded:", message.code) print("Brightness: ", brightness/10, " Color: ", hex(colorwheel(color_number))) elif isinstance(message, adafruit_irremote.NECRepeatIRMessage): print("NEC repeat!") elif isinstance(message, adafruit_irremote.UnparseableIRMessage): print("Failed to decode", message.reason) print("----------------------------")
In the editor window in your browser, click the Open button to view the file dialog. Then, click the Upload button and select Upload Folders.
After the upload finishes, you can open the lib folder to view the two library files required for the NeoPixel examples.
Your CIRCUITPY/lib folder should contain the following folders:
- adafruit_irremote.mpy
- adafruit_pixelbuf.mpy
- neopixel.mpy
In the editor window in your browser, click the Open button to view the file dialog. Then, click the Upload button and select Upload Files.
You'll be asked if you want to overwrite the previous code.py with the new code.py file from the Project Bundle. Click OK.
This example utilizes the NeoPixel output terminal blocks for pin D21
. It starts by initializing PulseIn
and the IR Decoder instance. Then the NeoPixel instance. Inside of the main while True:
loop it reads any incoming messages from the decoder. When the up or down commands are received it raises or lowers the brightness of the NeoPixels, when the right or left commands are received it changes the color of the NeoPixels.
Page last edited May 20, 2025
Text editor powered by tinymce.