You all know how this goes, right? You get an Arduino, you’re super excited, but all that you end up doing with it is that first tutorial, “Blink”. Then you wrap it up, because you’re satisfied of your achievement but too tired to learn about resistances tonight. And that’s all you’ll ever do with it. (Although, on a second thought, “Blink” allows you to make The IT Crowd’s “Internet”!)

Looking at LED strips on Amazon got me to go beyond Blink. I wanted to find a LED strip where each LED would be individually addressable, making playing with colors easy. Adafruit makes these kind of things. They have a series of tutorials and make it so easy for anyone to play with light and Bluetooth. If you want to get into these kind of projects, I do recommend you go have a look at their website. It’s like porn to me.

I got one of their LED rings and played with it on my Arduino. I propped it under a mason jar, filled with water and a tiny bit of milk, mixed it around, and had this cool looking jar.

Mason jar filled with an underlying LED ring.

That’s cool, it does little color thingies, but it gets old pretty fast. I was wondering if I could make the light react to something. I could do many things: hook it up to some sensors and making it do some light in function of that, like a blue light when it’s cold and a reddish light when it’s warm. Many possibilities.

At that time at Fitbit I was working on phone notifications for our Fitbit Blaze, Charge 2 and Flex 2 trackers. Seeing some of our trackers blink a LED upon notification receipt got me thinking and ultimately pushed me to making a notification-driven Halloween costume. I thought of different things, but needed to come up with something that would bounce off light easily, and wouldn’t be too weird to be lit up or looking bizarre with wires all around. An astronaut costume matched that description perfectly.

Adafruit Bluefruit soldered to an Arduino Uno in protective casing

Part 1 : Das Helmet

I shopped for an astronaut suit, helmet, waterproof addressable LED strip and why not, EL-wire. I glued the EL-wire around the edges of the helmet and on the stripes on top. The LED strip was glued in the interior of the helmet and connected to an Arduino to which I had soldered a Bluetooth Low Energy shield (I used an Adafruit Bluefruit LE shield for this).

Arduino & Bluetooth Low Energy

Using a BTLE shield on an Arduino is surprisingly easy. The IDE contains access to a repository containing multiple libraries, including the one for talking to the Bluetooth shield. These also come with examples to give you a great head start.

About Bluetooth LE: I could go on for hours. But long story short, every BTLE device exposes a set of services, which all contain multiple properties called characteristics. Characteristics come in multiple flavors. Some are readable, some writable and you can also get notified. That’s already a lot of use cases for a home IoT project!

My use case was easy: I just needed to write to a characteristic. I came up with a “Helmet Service” containing the different characteristics I could write to:

“Das Helmet”-service (0xFF10)

Light mode (0xFF11) : 1-byte characteristic representing “Pulse” (0), “Rotate” (1), “Rotate Dark” (2) and “Rainbow” (3). Anything above that will be replaced by a randomized number between 0 and 3.

: 1-byte characteristic representing “Pulse” (0), “Rotate” (1), “Rotate Dark” (2) and “Rainbow” (3). Anything above that will be replaced by a randomized number between 0 and 3. Brightness (0xFF12) : 1-byte characteristic (0xFF13), going from 0 (off) to 255 (full on). Brightness is something we want to control as we don’t want to kill our batteries over this when it’s not necessary. If you want to push it even further, you could mount a light sensor in the helmet and have it managed for you.

: 1-byte characteristic (0xFF13), going from 0 (off) to 255 (full on). Brightness is something we want to control as we don’t want to kill our batteries over this when it’s not necessary. If you want to push it even further, you could mount a light sensor in the helmet and have it managed for you. Color characteristic (0xFF13) : 3-byte array representing red, green and blue, going from 0 to 255 each.

Setting up the BTLE device and its services and characteristics is done in my Arduino code through the following AT-commands:

The first command sets up the Generic Access Profile name, the second adds our service for controlling the helmet, followed by 3 characteristics (mode, brightness and color) and their constraints and default values. Then we add all of that to the advertising data of our device so this service becomes discoverable to our phone or other BTLE device that decides to connect to the helmet.

In our Arduino code, every time our loop() method gets called, the characteristic for mode, brightness and color are read. It uses AT-commands similar to the ones listed above to achieve this. Later on it then decides to do something based on this new information.

At it’s core, the Arduino code can be summed up to this:

I made each method configurable, so I can make changes to things like duration or times a cycle is repeated.

The function for rotating colors is also fairly straightforward. We do not really need to keep track off which LED is on when. We just need to alter two LEDs per cycle!

And then we loop again! Done!

Android

One of the fun things to play around with on Android is the NotificationListenerService, that allows you to listen to incoming notifications. This is where we want to intercept notifications and write to the characteristics of our bluetooth device based on that. Once we get a new notification, we parcel it and send it to our Bluetooth-service that will take care of communicating with the helmet.

When a notification comes in, what should we do? We can do several things. We can check which package this comes from and push a color. Or we can have a special kind of animation when a particular kind of content comes in. I did a mix of both.

One of the other cool APIs in Android is Palette. It is part of the design-compat package but takes in a bitmap, and returns a “palette” of colors to you based on that image. In order to obtain a color for a notification, you just need to do this in your service’s onNotificationPosted() method:

The next thing we do is parcel over an intent to our service running our Bluetooth connection to tell it what color mode we want and what we want to display.

The Android app I wrote for this also allows you to control the lights manually, so you don’t need to wait for a notification in order to get your lights going.

While I made an Android app for this, you actually don’t really need to. Sure it helps if you want notifications, but for debugging you can first write your Arduino Bluetooth LE code and debug it by using an app like Nordic’s nRF Connect, available on Android and iOS.

Android app for helmet control

Part 2 : Heart-rate guided star suit

The astronaut suit needed an extra touch. I had another set of LED lights that I thought I could maybe wear underneath. I connected this to an Arduino and wrote a little algorithm for generating star animations. The speed at which the stars animate is guided by a heart rate monitor which is clipped to my ear.

Using live heart rate from a sensor is something that isn’t the easiest to do: that thing goes fast. Most of the time faster than a second! If you want to have something nice and not look like a christmas tree, you could divide heart rates in “levels” and have some sort of animation going with it. In my case, this is how I sort of did it:

Level 0 : BPM 55 to 75, lights up 1 in 7 lights.

Level 1 : 75 to 95, lights up 1 in 5 lights.

Level 2 : 95 to 125, lights up 1 in 3 lights.

Level 3 : 145 to 165, lights up 1 in 2 lights.

Level 4 : 165 and up, lights up all lights.

Working like this allows us to save memory. We do not need to have an array the size of the number of LEDs we have to track which one is on. When we transition between phases, we also know which LED is on in both phases (example: LED 6 will be on in phase 2, 3 and 4). Where we see a difference, we do a smooth “dim off” transition for the LEDs we don’t need anymore and “dim on” those that are part of the new level.

The lights and their transition as used under the suit.

Still confused? Let’s look at an example where we transition between level 0 and 1 on a LED-strip with 50 LEDs:

Level 0 (multiplier 7) will light up LED 0, 7, 14, 21, 28, 35, 42 and 49.

Level 1 (multiplier 5) will light up LED 0, 5, 10, 15, 20, 25, 30, 35, 40 and 45.

The code will determine which LEDs can stay on, dim or need to light on, which give it a smooth transition:

Staying on : LEDs 0 and 35

Going off : LEDs 7, 14, 21, 28, 42 and 49.

Jumping on: LEDs 5, 10, 15, 20, 25, 30, 40 and 45.

And this is what it looks like in code on our Arduino:

Conclusion

This project was really fun to work on and was months in the making. I don’t know what I will do with this costume after Halloween, but I thought I’d write a little article to share as I got a lot of questions from this costume.

The source code for everything Arduino related to this project can be found on my github: Das Helmet and Stars.