Hello tech adventurers! 
If you're here, you're probably itching to light up the world, or at least your room, with some rainbow colors! And how? By combining a motion sensor (IMU), a tiny powerhouse microcontroller, and some shiny NeoPixels.
Buckle upβit's going to be fun and flashy (literally)!
Β
What You'll Need
Let's kick off by grabbing all the cool gear for this project. Make sure your toolbox is stocked with:
1. Seeed Studio Xiao nRF52840 Sense
This tiny microcontroller is a superstar! Itβs Bluetooth-capable, runs on a Cortex-M4 processor, and isΒ small enough to get lost in your pocket! Not that you'd want that...
2. NeoPixel LED Panel
Β
3. IMU (Inertial Measurement Unit)
4. Jumper Wires, Soldering Kit, and USB-C Cable
Get PCBs for Your Projects Manufactured
Β
You must check outΒ PCBWAYΒ for ordering PCBs online for cheap!
You get 10 good-quality PCBs manufactured and shipped to your doorstep for cheap. You will also get a discount on shipping on your first order. Upload your Gerber files ontoΒ PCBWAYΒ to get them manufactured with good quality and quick turnaround time. PCBWay now could provide a complete product solution, from design to enclosure production. Check out their online Gerber viewer function. With reward points, you can get free stuff from their gift shop. Also, check out this useful blog on PCBWay Plugin for KiCad fromΒ here.Β Using this plugin, you can directly order PCBs in just one click after completing your design in KiCad.
Step 1: Flashing the Xiao nRF52840 Sense
Getting it Talking!
Start by setting up your development environment. Youβll want to upload the code to your Xiao, but first, you need toΒ flash the microcontrollerΒ with the right firmware.
Install the necessary tools:Β Head toΒ Seeed StudioΒ and grab their official setup guide for the Xiao nRF52840 Sense. Youβll needΒ Arduino IDEΒ and Xiao's board libraries. Piece of cake, right?
Pro Tip: When uploading code, if your microcontroller throws a tantrum and doesnβt show up on your PC, double-tap the reset button to enter bootloader mode. Itβs like giving it a calming tea break.
Step 2: Wiring it up
Time to bring these components together like a superhero team-up!
Connect the NeoPixel to the Xiao:
VoilΓ , youβve wired up your light show! Now, donβt plug it in just yet. Patience, young padawan.
Step 3: Code Time!

Weβre diving into the fun partβthe code! This is where the Xiao's IMU will tell the NeoPixels how to light up depending on the motion.
Setting Up Libraries:
Make sure you have these libraries installed in your Arduino IDE:
#include <Adafruit_NeoPixel.h>
#include <LSM6DS3.h>
#include <Wire.h>
#define PIN 0
#define NUMPIXELS 64
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
LSM6DS3 myIMU(I2C_MODE, 0x6A); // I2C device address 0x6A
float aX, aY, aZ, gX, gY, gZ;
const float accelerationThreshold = 2.5; // threshold of significant in G's
const int numSamples = 119;
int samplesRead = numSamples;
void setup() {
Serial.begin(9600);
while (!Serial);
pixels.begin();
pixels.show(); // Initialize all pixels to 'off'
// Call .begin() to configure the IMU
if (myIMU.begin() != 0) {
Serial.println("Device error");
} else {
Serial.println("aX,aY,aZ,gX,gY,gZ");
}
}
void loop() {
// wait for significant motion
while (samplesRead == numSamples) {
// read the acceleration data
aX = myIMU.readFloatAccelX();
aY = myIMU.readFloatAccelY();
aZ = myIMU.readFloatAccelZ();
// sum up the absolutes
float aSum = fabs(aX) + fabs(aY) + fabs(aZ);
// check if it's above the threshold
if (aSum >= accelerationThreshold) {
// reset the sample read count
samplesRead = 0;
break;
}
}
// check if all the required samples have been read since
// the last time the significant motion was detected
while (samplesRead < numSamples) {
// read the acceleration and gyroscope data
aX = myIMU.readFloatAccelX();
aY = myIMU.readFloatAccelY();
aZ = myIMU.readFloatAccelZ();
gX = myIMU.readFloatGyroX();
gY = myIMU.readFloatGyroY();
gZ = myIMU.readFloatGyroZ();
samplesRead++;
// print the data in CSV format
Serial.print(aX, 3);
Serial.print(',');
Serial.print(aY, 3);
Serial.print(',');
Serial.print(aZ, 3);
Serial.print(',');
Serial.print(gX, 3);
Serial.print(',');
Serial.print(gY, 3);
Serial.print(',');
Serial.print(gZ, 3);
Serial.println();
// Visualize the IMU data on the NeoPixel matrix
visualizeIMU(aX, aY, aZ, gX, gY, gZ);
if (samplesRead == numSamples) {
// add an empty line if it's the last sample
Serial.println();
}
}
}
void visualizeIMU(float aX, float aY, float aZ, float gX, float gY, float gZ) {
// Map the acceleration and gyroscope data to colors
uint8_t red = map(fabs(aX) * 100, 0, 250, 0, 255);
uint8_t green = map(fabs(aY) * 100, 0, 250, 0, 255);
uint8_t blue = map(fabs(aZ) * 100, 0, 250, 0, 255);
// Set all pixels to the mapped color
for (int i = 0; i < NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(red, green, blue));
}
pixels. Show();
}
What's Happening in the Code?
Β
Step 4: Test, Shake, and Dance!
Once your code is uploaded, unplug the USB and plug it back in (just to give your Xiao a little reset!). Now the magic begins.
Testing the Tilt:
If everything worked out, congrats, youβre now officially aΒ NeoPixel DJ!
Want to sync it with music and start a rave? Go ahead! The only limit is your creativity (and the brightness tolerance of your neighbors...
).
Step 5: Going Wireless with Bluetooth!
Now letβs take it one step further. What if you could control this with your phone? Hereβs where theΒ BluetoothΒ capability of the Xiao nRF52840 Sense comes into play.
UsingΒ Bluetooth Low Energy (BLE), you can send motion data directly from your Xiao to an app on your phoneβor even control the colors remotely! The Xiao makes it super easy to set up BLE communication, and you can find libraries in Arduino to help with this.
Conclusion: Welcome to the Sparkle Party!

Β
Now that you've brought your NeoPixels to life with motion-sensing IMU data, it's time to celebrate! This project opens up a world of possibilitiesβfrom creating interactive lighting for your room, and costumes, or even building motion-reactive wearables.
The only thing left is to challenge yourselfβcan you use this setup to control music lights at a party? Sync with game controllers? Make a dancing robot? The worldβs your oyster, and the lights are your magic wand!

Happy making, and may your LEDs forever shine bright!
Β
What You'll Need
Let's kick off by grabbing all the cool gear for this project. Make sure your toolbox is stocked with:
1. Seeed Studio Xiao nRF52840 Sense
This tiny microcontroller is a superstar! Itβs Bluetooth-capable, runs on a Cortex-M4 processor, and isΒ small enough to get lost in your pocket! Not that you'd want that...
- Why this one?Β It's packed with an onboard microphone, IMU (Inertial Measurement Unit), and Bluetooth LE, which means weβre going wireless, baby!


2. NeoPixel LED Panel
- These are individually addressable RGB LEDs that can light up in any color your heart desires. Weβll be using these bad boys to visualize our IMU's data. Theyβre essentially the party piece of this project!

Β
3. IMU (Inertial Measurement Unit)
- Already built into the Xiao nRF52840 Sense! This sensor detects motion, so you can do cool stuff like control your NeoPixels based on tilts and shakes. Think of it like aΒ magic wandΒ for LEDs.
4. Jumper Wires, Soldering Kit, and USB-C Cable
- You know the drill. We need these to hook up everything without too much of a spaghetti mess on your desk.
Get PCBs for Your Projects Manufactured
Β
You must check outΒ PCBWAYΒ for ordering PCBs online for cheap!
You get 10 good-quality PCBs manufactured and shipped to your doorstep for cheap. You will also get a discount on shipping on your first order. Upload your Gerber files ontoΒ PCBWAYΒ to get them manufactured with good quality and quick turnaround time. PCBWay now could provide a complete product solution, from design to enclosure production. Check out their online Gerber viewer function. With reward points, you can get free stuff from their gift shop. Also, check out this useful blog on PCBWay Plugin for KiCad fromΒ here.Β Using this plugin, you can directly order PCBs in just one click after completing your design in KiCad.
Step 1: Flashing the Xiao nRF52840 Sense
Getting it Talking!
Start by setting up your development environment. Youβll want to upload the code to your Xiao, but first, you need toΒ flash the microcontrollerΒ with the right firmware.
Install the necessary tools:Β Head toΒ Seeed StudioΒ and grab their official setup guide for the Xiao nRF52840 Sense. Youβll needΒ Arduino IDEΒ and Xiao's board libraries. Piece of cake, right?
Pro Tip: When uploading code, if your microcontroller throws a tantrum and doesnβt show up on your PC, double-tap the reset button to enter bootloader mode. Itβs like giving it a calming tea break.
Step 2: Wiring it up
Time to bring these components together like a superhero team-up!
Connect the NeoPixel to the Xiao:
- Power:Β Connect theΒ VCCΒ pin of the NeoPixel to theΒ 3.3VΒ pin of the Xiao.
- Ground:Β GND to GND (itβs like their secret handshake
).
- Data:Β Hook theΒ DINΒ (data in) pin from the NeoPixel toΒ Pin D6Β on the Xiao.
VoilΓ , youβve wired up your light show! Now, donβt plug it in just yet. Patience, young padawan.
Step 3: Code Time!
Weβre diving into the fun partβthe code! This is where the Xiao's IMU will tell the NeoPixels how to light up depending on the motion.
Setting Up Libraries:
Make sure you have these libraries installed in your Arduino IDE:
- Adafruit NeoPixelΒ (to control those flashy lights)

- Wire.hΒ (for I2C communication)
- Seeed nRF52Β board libraries (to work with Xiao)
- Adafruit SensorΒ for handling IMU data.
#include <Adafruit_NeoPixel.h>
#include <LSM6DS3.h>
#include <Wire.h>
#define PIN 0
#define NUMPIXELS 64
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
LSM6DS3 myIMU(I2C_MODE, 0x6A); // I2C device address 0x6A
float aX, aY, aZ, gX, gY, gZ;
const float accelerationThreshold = 2.5; // threshold of significant in G's
const int numSamples = 119;
int samplesRead = numSamples;
void setup() {
Serial.begin(9600);
while (!Serial);
pixels.begin();
pixels.show(); // Initialize all pixels to 'off'
// Call .begin() to configure the IMU
if (myIMU.begin() != 0) {
Serial.println("Device error");
} else {
Serial.println("aX,aY,aZ,gX,gY,gZ");
}
}
void loop() {
// wait for significant motion
while (samplesRead == numSamples) {
// read the acceleration data
aX = myIMU.readFloatAccelX();
aY = myIMU.readFloatAccelY();
aZ = myIMU.readFloatAccelZ();
// sum up the absolutes
float aSum = fabs(aX) + fabs(aY) + fabs(aZ);
// check if it's above the threshold
if (aSum >= accelerationThreshold) {
// reset the sample read count
samplesRead = 0;
break;
}
}
// check if all the required samples have been read since
// the last time the significant motion was detected
while (samplesRead < numSamples) {
// read the acceleration and gyroscope data
aX = myIMU.readFloatAccelX();
aY = myIMU.readFloatAccelY();
aZ = myIMU.readFloatAccelZ();
gX = myIMU.readFloatGyroX();
gY = myIMU.readFloatGyroY();
gZ = myIMU.readFloatGyroZ();
samplesRead++;
// print the data in CSV format
Serial.print(aX, 3);
Serial.print(',');
Serial.print(aY, 3);
Serial.print(',');
Serial.print(aZ, 3);
Serial.print(',');
Serial.print(gX, 3);
Serial.print(',');
Serial.print(gY, 3);
Serial.print(',');
Serial.print(gZ, 3);
Serial.println();
// Visualize the IMU data on the NeoPixel matrix
visualizeIMU(aX, aY, aZ, gX, gY, gZ);
if (samplesRead == numSamples) {
// add an empty line if it's the last sample
Serial.println();
}
}
}
void visualizeIMU(float aX, float aY, float aZ, float gX, float gY, float gZ) {
// Map the acceleration and gyroscope data to colors
uint8_t red = map(fabs(aX) * 100, 0, 250, 0, 255);
uint8_t green = map(fabs(aY) * 100, 0, 250, 0, 255);
uint8_t blue = map(fabs(aZ) * 100, 0, 250, 0, 255);
// Set all pixels to the mapped color
for (int i = 0; i < NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(red, green, blue));
}
pixels. Show();
}
What's Happening in the Code?
- The IMU is your sensor. Weβre reading acceleration data on all three axes: X, Y, and Z.
- The NeoPixels are the output. We map the motion detected by the IMU into a color value (RGB).
- Mapping Motion to Color: We sum up the absolute values of the accelerations to determine how hard you shake or tilt the Xiao. More movement = crazier colors!

Β
Step 4: Test, Shake, and Dance!
Once your code is uploaded, unplug the USB and plug it back in (just to give your Xiao a little reset!). Now the magic begins.
Testing the Tilt:
- Pick up your Xiao nRF52840 and gently tilt it. Youβll see the NeoPixels lighting up in different colors.
- Shake it a bit moreβsee the color change? Now youβre in charge of the show!
If everything worked out, congrats, youβre now officially aΒ NeoPixel DJ!
Step 5: Going Wireless with Bluetooth!
Now letβs take it one step further. What if you could control this with your phone? Hereβs where theΒ BluetoothΒ capability of the Xiao nRF52840 Sense comes into play.
UsingΒ Bluetooth Low Energy (BLE), you can send motion data directly from your Xiao to an app on your phoneβor even control the colors remotely! The Xiao makes it super easy to set up BLE communication, and you can find libraries in Arduino to help with this.
Conclusion: Welcome to the Sparkle Party!
Β
Now that you've brought your NeoPixels to life with motion-sensing IMU data, it's time to celebrate! This project opens up a world of possibilitiesβfrom creating interactive lighting for your room, and costumes, or even building motion-reactive wearables.
The only thing left is to challenge yourselfβcan you use this setup to control music lights at a party? Sync with game controllers? Make a dancing robot? The worldβs your oyster, and the lights are your magic wand!
Happy making, and may your LEDs forever shine bright!