💡 SignalBox: DIY Connected Lanterns with MQTT, Adafruit Feather

Faced with the tradition of family Christmas gift giving, I was thoroughly stumped. I knew I wanted to do something maker-related: I’m the only engineer in the family, which tends to amplify the wow factor of any techncal projects :)

After my fallback plan (a Chemex coffee maker) fell through, I knew I had to build these!

image

the finished product!

These are long-distance friendship lanterns. The idea is, sometimes you want to let a distant friend or family member know that you’re thinking of them, even if you don’t necessarily want to shoot them a text. The lanterns couldn’t be simpler to use: turning on your lantern also turns on your friends’ lantern, no matter where they are in the world.

Logic

This project has multiple boxes (one for each family member), all of which can send “thinking of you” messages to each other. For example, if I’m currently thinking about my dad, I can make his box light up from my box! But how does he know it’s me that’s thinking of him, and not someone else? To solve this, each box is assigned a color, which is associated with the box owner. So when I send a message to my dad, his box will become my color. To send a message, I can press the push button, which cycles through all the possible colors to send to. Not pressing the button for 2 seconds will send the message, lighting up the senders’ and receivers’ box for 2 hours. Confusing? I made a diagram.

image

Feather Board (image credit to Adafruit)

The Code

MQTT

I knew that MQTT would be a great fit for this project: it even bills itself as “The standard for IoT messaging”. It’s lightweight, bidirectional, and requires minimal infrastructure. Without getting too into the weeds, every message, or post, is published to a topic. Once a message is published to a topic, all other devices subscribed to the same topic receive the new message. By making a topic for each box, (i.e. the green box will receive any posts sent to the green topic), anyone’s post to that box’s topic will be interpreted as a message to turn that box on.

Of course, this system still requires a central server, called a broker, to make sure messages get to where they’re sent. Luckily, HiveMQ is one such server with a generous free tier that this project’s constraints fall well within. It also HAD a super neat tutorial for getting started on an Arduino, but the page seems to be broken. Either way, my implementation is based on their sample publish-receive code.

Arduino

Everyone and their mother knows that Arduino is the way to go for simple MCU programming. Abundant libraries handle all of the hard stuff, all you have to do is bring the logic. Besides some Linux issues (Manjaro didn’t seem to like my UDEV rules, solution here), everything was simple to set up.

As for libraries, I utilized FastLED to program simple light animations in the Neopixel strip. ESP8266WiFi is obviously needed to connect the device to the network, and other boilerplate libraries such as PubSubClient and LittleFS were used to authenticate with the HiveMQ server.

Parts Selection

image

Feather Board (image credit to Adafruit)

I am blessed to live within driving distance of Micro Center, a legendary PC superstore with a sizeable DIY/maker section. I knew I needed an Arduino board with wifi support, and Micro Center had the Adafruit Feather Huzzah in stock. This board’s specs are overkill for this application, but it definitely does the job. Also from the Micro Center haul was a strip of NeoPixels, and some push-button switches for control. Add in a clear case from the container store, and we’re ready to rock!

Does it work?

In short, yeah! The only issues I’ve run into are logging related. When I rolled these boxes out, I didn’t include any method of logging messages. This makes it very difficult to troubleshoot the boxes, since I simply don’t know what’s happening at any given time. Throw in the fact that I have no method of remotely updating the boxes, even small logic bugs are difficult to fix. But after being rolled out for 3 months, all the reported issues can be fixed just by power cycling the device, so I’d call this a win! If you find any issues with my programming, don’t hesitate to hit me with a pull request!