I’m working on a smiple LED mood light that changes colour based on its orientation to the local magnetic field and uses an accelerometer to switch the power on/off. The little contraption consists of a programmable NeoPixel strip, wired to a Flora micro controller, wired to a compass & accelerometer sensor, all powered by a LiPo battery. The electronics are stuffed into a pretty jam jar that keeps things together, and the frosted lamp helps to soften the crisp LED light. I made a fancy video of my work in progress.
Shaking the jar switches the lights on/off, and there’s a two second delay when the light switches off that I think might need adjusting.
The idea for this small project came to me last month while camping with a friend on Jekyll Island. Some of the campsites had beautiful LED lighting systems (eg – glowy puzzle lights) and I wanted to see if I could make something with the electronics I already had. I recently added 80’s lights to my bicycle bag with programmable LEDs, but I wasn’t really using the bag very often, so I took the pieces from that project and started making a jam jar light. I’m not sure if/how well it will function while camping yet, but I’ll get to take it on a “field test” next weekend, we’re camping again in south Georgia.
The code I wrote is similar to what I had used for the bicycle bag lights; I replaced the 80’s with a piecewise continuous function to control the colours based on the heading of the magnetometer sensor as it rotates:
The normalized magnetizations in the x and y directions are Mx,normalized and My,normalized. which are normalized so that their values range from -1 to 1. The heading in degrees, H, is then used to calculate the colour of the lights, C, based on a set of conditional statements that can be found in several of the adafruit libraries:
if 0 ≤ H ≤ 85, C = [255 – 3H, 3H, 0]
if 85 < H ≤ 170, C = [0, 255 – 3(H – 85), 3(H – 85)]]
if 170 < H ≤ 360, C = [3(H – 170), 0, 255 – 3(H – 170)]
The entire project only took me a few hours to code and assemble: adafruit components are extremely easy to work with. What do you think about this little project?