Programming a Jam Jar Light

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

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:

H = \arctan\Big(\frac{M_{y,normalized}}{M_{x,normalized}}\Big).

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?

The light uses a 30 LED programmable NeoPixel strip from AdaFruit.

The light uses a 30 LED programmable NeoPixel strip from AdaFruit.

This entry was posted in Electronics, Hobbies and tagged , , , , , , , . Bookmark the permalink.

3 Responses to Programming a Jam Jar Light

  1. Anna Picco says:

    OK. You call this a “small project”! My head hurts trying to understand the basic concepts behind your “invention”. You never cease to amaze me. Your childlike approach to life is amazing (and I mean this in the most positive way)! Watching my granddaughters take on the mysteries of life and how they interact with the “questions” has brought me back to my childhood wonderland.

    • gsmayer says:

      Thank you Anna for the kind words! I absolutely agree; exploring the world with experiments and questions is something anyone can enjoy.

  2. Pingback: Updating my Programmable Jam Jar Light for a Camping Trip | Greg Mayer

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s