Motion-Reactive Lightsaber Prop
Ignition, hum, swing and clash effects with an RP2040 Prop-Maker, NeoPixels and I2S audio.
Code
Printable parts
STL files coming soon.
Sound files
Sound files coming soon.
Docs
Overview
A motion-reactive RGBW lightsaber. The Feather RP2040 Prop-Maker's built-in LIS3DH accelerometer detects swings and hits, NeoPixels light the blade, and I2S audio plays the ignition, hum, swing and clash sounds - all housed in a 3D printed hilt.
- Blade ignition and retraction with sound
- Swing and clash detection from the on-board accelerometer
- Seven blade colours, cycled with a long press
- Adjustable motion sensitivity
Parts
- Adafruit Feather RP2040 Prop-Maker — main controller with built-in LIS3DH accelerometer and I2S amplifier
- NeoPixel strip (GRBW) — blade illumination, up to 100 pixels
- Speaker — hum, swing and clash sounds
- Pushbutton — on/off and colour cycle
- 3.7V 2200mAh LiPo battery — power
- 3D printed hilt — custom-designed lightsaber body
Wiring
Connections (all to the Prop-Maker board)
| From | To | Notes |
|---|---|---|
| D5 | NeoPixel strip DIN | blade data |
| I2S / speaker terminals | Speaker | audio out |
| EXTERNAL_BUTTON | Pushbutton to GND | control |
| VBAT / battery port | 3.7V LiPo (2200mAh) | power |
- The code switches on the Prop-Maker's EXTERNAL_POWER pin at start-up, which powers the NeoPixels and speaker.
Directions
- Insert the NeoPixel strip inside the blade tube.
- Mount the speaker in the base cap for resonance.
- Slide the RP2040 board and battery into the grip section.
- Route the button wiring through the body and secure it in the switch mount.
- Connect all components according to the wiring diagram.
- Install CircuitPython, then copy
code.py, the libraries and thesounds/folder to the board'sCIRCUITPYdrive. - Power on and enjoy your saber's ignition and sound effects!
Controls
| Action | Result |
|---|---|
| Short press | Toggle saber on/off |
| Swing motion | Plays swing sound |
| Tap (impact) | Plays clash sound |
| Long press | Cycle blade colour |
Sound files
Put the .wav files in a sounds/ folder on the CIRCUITPY drive. The code plays them in name order:
| File | Plays |
|---|---|
| 0.wav | Power on |
| 1.wav | Hum (looped) |
| 2.wav | Power off |
| 3-10.wav | Clash sounds |
| 11-18.wav | Swing sounds |
| 19.wav | Colour change tone |
Libraries
Taken from the imports in code.py - copy them from the Adafruit CircuitPython Library Bundle into CIRCUITPY/lib/.
- adafruit_debouncer.mpy
- adafruit_ticks.mpy (needed by the debouncer)
- adafruit_lis3dh.mpy
- neopixel.mpy
- simpleio.mpy
- adafruit_bus_device/ (folder)
Make it yours
HIT_THRESHOLD = 120/SWING_THRESHOLD = 130- smaller numbers = more sensitive to motionSABER_COLOR = 3- starting blade colour (index intoCOLORS)CLASH_COLOR = 6- colour flashed on a clash
Code
code.py Download
# Originally created by by Ruiz Brothers and Liz Clark
# Uploaded from Adafruit Learning Center
# SPDX-FileCopyrightText: 2023 Liz Clark for Adafruit Industries
#
# SPDX-License-Identifier: MIT
import time
import os
import random
import board
import pwmio
import audiocore
import audiobusio
from adafruit_debouncer import Button
from digitalio import DigitalInOut, Direction, Pull
import neopixel
import adafruit_lis3dh
import simpleio
# CUSTOMIZE SENSITIVITY HERE: smaller numbers = more sensitive to motion
HIT_THRESHOLD = 120
SWING_THRESHOLD = 130
RED = (255, 0, 0)
YELLOW = (125, 255, 0)
GREEN = (0, 255, 0)
CYAN = (0, 125, 255)
BLUE = (0, 0, 255)
PURPLE = (125, 0, 255)
WHITE = (255, 255, 255)
COLORS = [RED, YELLOW, GREEN, CYAN, BLUE, PURPLE, WHITE]
SABER_COLOR = 3
CLASH_COLOR = 6
# enable external power pin
# provides power to the external components
external_power = DigitalInOut(board.EXTERNAL_POWER)
external_power.direction = Direction.OUTPUT
external_power.value = True
wavs = []
for filename in os.listdir('/sounds'):
if filename.lower().endswith('.wav') and not filename.startswith('.'):
wavs.append("/sounds/"+filename)
wavs.sort()
print(wavs)
print(len(wavs))
audio = audiobusio.I2SOut(board.I2S_BIT_CLOCK, board.I2S_WORD_SELECT, board.I2S_DATA)
def play_wav(num, loop=False):
"""
Play a WAV file in the 'sounds' directory.
:param name: partial file name string, complete name will be built around
this, e.g. passing 'foo' will play file 'sounds/foo.wav'.
:param loop: if True, sound will repeat indefinitely (until interrupted
by another sound).
"""
try:
n = wavs[num]
wave_file = open(n, "rb")
wave = audiocore.WaveFile(wave_file)
audio.play(wave, loop=loop)
except: # pylint: disable=bare-except
return
# external button
pin = DigitalInOut(board.EXTERNAL_BUTTON)
pin.direction = Direction.INPUT
pin.pull = Pull.UP
switch = Button(pin, long_duration_ms = 1000)
switch_state = False
# external neopixels
num_pixels = 100
pixels = neopixel.NeoPixel(board.EXTERNAL_NEOPIXELS, num_pixels, auto_write=True)
pixels.brightness = 0.8
# onboard LIS3DH
i2c = board.I2C()
int1 = DigitalInOut(board.ACCELEROMETER_INTERRUPT)
lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)
# Accelerometer Range (can be 2_G, 4_G, 8_G, 16_G)
lis3dh.range = adafruit_lis3dh.RANGE_2_G
lis3dh.set_tap(1, HIT_THRESHOLD)
red_led = pwmio.PWMOut(board.D10)
green_led = pwmio.PWMOut(board.D11)
blue_led = pwmio.PWMOut(board.D12)
def set_rgb_led(color):
# convert from 0-255 (neopixel range) to 65535-0 (pwm range)
red_led.duty_cycle = int(simpleio.map_range(color[0], 0, 255, 65535, 0))
green_led.duty_cycle = int(simpleio.map_range(color[1], 0, 255, 65535, 0))
blue_led.duty_cycle = int(simpleio.map_range(color[2], 0, 255, 65535, 0))
set_rgb_led(COLORS[SABER_COLOR])
mode = 0
swing = False
hit = False
while True:
switch.update()
# startup
if mode == 0:
print(mode)
play_wav(0, loop=False)
for i in range(num_pixels):
pixels[i] = COLORS[SABER_COLOR]
pixels.show()
time.sleep(1)
play_wav(1, loop=True)
mode = 1
# default
elif mode == 1:
x, y, z = lis3dh.acceleration
accel_total = x * x + z * z
if lis3dh.tapped:
print("tapped")
mode = "hit"
elif accel_total >= SWING_THRESHOLD:
print("swing")
mode = "swing"
if switch.short_count == 1:
mode = 3
if switch.long_press:
audio.stop()
play_wav(19, loop=True)
print("change color")
mode = 5
# clash or move
elif mode == "hit":
audio.stop()
play_wav(random.randint(3, 10), loop=False)
while audio.playing:
pixels.fill(WHITE)
pixels.show()
pixels.fill(COLORS[SABER_COLOR])
pixels.show()
play_wav(1, loop=True)
mode = 1
elif mode == "swing":
audio.stop()
play_wav(random.randint(11, 18), loop=False)
while audio.playing:
pixels.fill(COLORS[SABER_COLOR])
pixels.show()
pixels.fill(COLORS[SABER_COLOR])
pixels.show()
play_wav(1, loop=True)
mode = 1
# turn off
elif mode == 3:
audio.stop()
play_wav(2, loop=False)
for i in range(99, 0, -1):
pixels[i] = (0, 0, 0)
pixels.show()
time.sleep(1)
external_power.value = False
mode = 4
# go to startup from off
elif mode == 4:
if switch.short_count == 1:
external_power.value = True
mode = 0
# change color
elif mode == 5:
if switch.short_count == 1:
SABER_COLOR = (SABER_COLOR + 1) % 6
pixels.fill(COLORS[SABER_COLOR])
pixels.show()
set_rgb_led(COLORS[SABER_COLOR])
if switch.long_press:
play_wav(1, loop=True)
pixels.fill(COLORS[SABER_COLOR])
pixels.show()
set_rgb_led(COLORS[SABER_COLOR])
mode = 1
Credits & licence
Based on the Adafruit Learning System lightsaber project by the Ruiz Brothers and Liz Clark (MIT License).
Released under the MIT License — Copyright (c) 2023 Liz Clark for Adafruit Industries
Custom modifications Copyright (c) 2025 Lark216. Free to use, modify and share.
