Persistence Of Vision Star Wars Lightsaber!

Made by bitluni

About the project

This project shows how to build a persistence of vision lightsaber using the ESP32, neopixels and a gyro.

Project info



Estimated time:

5 days


25th May 2018

Items used in this project

Hardware components

3S LiPO 11.1V x 1
DC-DC Converter 5V 10A or more x 1
Resistor 10K Ohm 1/4 Watt PTH - 20 pk x 1
SMD LED RGB WS2812B Strip of 10 x 1
Push-button Power Switch Breakout x 1
LED Tactile Button Breakout x 1
HUZZAH32 - ESP32 Feather Board x 1
Stereo 3.7W Class D Audio Amplifier x 1

Software app and online services

Arduino IDE

Hand tools and fabrication machines

Angle Grinder x 1
Solder station x 1
Crimp pliers x 1



The ESP32 is the core of this project controlling the system and stores the images which can be displayed. It receives over I²C angular velocity data from the gyro and estimates the current angle of the lightsaber.

From this angle, a line is cast on the current image which determines the pixel colors for the NeoPixel array.

These color values are sent to the array over I²S. Just the I²S data line is used to emulate high and low signals specific to the WS2812b timings.

For highest coolness factor also sound is added. The samples for turning on and off are stored as binary arrays. If needed these can be changed using bitluni's wavetable editor. The hum sound is synthesized on the fly and is also pitched by the angular velocity. The rendered audio samples are sent to the first internal DAC which creates the analog voltage for the audio amplifier. The amplifier drives the speaker.



Any major ESP32 board can be used as long as it allows access to the pins as seen in the schematic. The following steps are needed to upload to code and the data to the microcontroller:

  1.  Install Arduino IDE (if not present)
  2. Install ESP32 Arduino extension (if not present)
  3. Install Arduino ESP32 file system uploader (if not present)
  4. Upload the POVLightsaber sketch from the github repository
  5. Upload the data from the IDE Tools >  ESP32 Sketch Data Upload

The Arduino project folder POVLightsaber contains a data folder where the binary images are placed. To replace the image the Converter tool can be used. The converter tool can be found in the code repository in the subdirectory Converter. The Converter.html can be opened with any modern Browser. Selecting an image will convert it to binary file image0.bin. Which can be stored from the link shown:

The file can be renamed tome image1.bin etc and placed in the data folder of the Arduino project replacing the corresponding image.

Full video tutorial


When the switch is turned on the ESP is powered up. While this is done the Lightsaber has to be held still for one second while it's taking reference samples from the gyro. From this point on holding the push button for 3 seconds will turn the Lightsaber on, holding it another 3 seconds turns it off. 

Currently, 3 images can be uploaded, but this can be increased in the code. Pressing the button shortly will jump to the next image cycling around on multiple presses. This currently only works after the Lightsaber is powered up and not yet turned on. It's a quirk of the internal ESP32 system. Trying to switch the image after it was turned on it will reboot jumping to the first image again.

While wielding the angular velocity is used to accumulate the angle. This is never perfect so there will be a drift. When the Lightsaber is held still again it will detect this and recalculate the absolute angle from the accelerometer and the gravity.




Contains Code, Tools, Models



I'm a maker and the host of the YouTube channel bitluni's lab

Leave your feedback...