Remotely Control Cloud-Enabled Christmas Tree Lights With cellular IoT

Xmas Special at Station F
Xmas Special

Xmas Special

Christmas is a time for connection, and since we’re always looking for ways to connect we sat down with our friends at Station F and FOCUS x UsineIO to come up with some new IoT use cases for the holiday. First up, the IoT Christmas Tree!

The classic Christmas tree string light is a perfect candidate for a simple IoT project, and we know a lot of maker types are already programming LED strips for fun and festive holiday displays. We’ll want to control our tree display remotely, so we’ll set up a cellular data connection for maximum flexibility and uptime.

Xmas Special at Station F

Xmas Special at Station F

Cellular connectivity enables data exchange both to and from connected devices, which lets us put together a hardware solution that can be programmed and connected anywhere (from the North Pole to Grandmother’s House — and grandmother can do it herself!) and remotely controlled to perform fun actions on holiday light strings.

For this project, we’re using the following hardware:

All the hardware you need for a Connected Tree (BYO lights)

All the hardware you need for a Connected Tree (BYO lights)

First, we’ll configure our Raspberry Pi Zero to connect using cellular data and set up our Soracom cellular connectivity service to enable communication.

Tutorials for both steps are available on Github as part of the Soracom IoT workshop Series (US, FR, UK):

For demo purposes, we’re using a test MQTT broker. Obviously you’ll want to use your own broker for anything you take into production.

Once the base setup has been done, we can move on to the fun part: wiring up our WS281x LED strip. The strip requires 5v Power, and a Raspberry Pi Zero will be able to supply enough power for 30 LEDs (about one meter).

Raspberry Pi GPIO

Raspberry Pi GPIO

In our case, we’ve wired the WS281x as follows:

  • Red wire to Raspberry Pi Zero pin 2 (+5v)
  • Black wire to Raspberry Pi Zero pin 6 (ground)
  • Blue wire to Raspberry Pi Zero pin 12 (GPIO 18)
Raspberry Pi Zero W with WS2811 LED Strip

Raspberry Pi Zero W with WS2811 LED Strip

Obviously, one meter of holiday lights won’t look very festive on a larger tree, so for maximum effect you’ll want to use an external 5V power supply. Not a problem! Just make sure there’s a common ground and control cable between your Raspberry Pi and your LED strip. You can find sample wiring here (Arduino-based but you get the idea).

Once wiring is complete, we can get to coding. For this project, we chose MQTT because it’s both convenient and secure for sharing instructions with your devices. Additionally, Soracom’s Beam functionality will save us some bandwidth usage by converting MQTT to MQTTs while maintaining end-to-end security.

We settled on NodeJS since both the NPM rpi-ws281x-native and MQTT libraries are already available to control WS281x LEDs strips and connect to a MQTT broker. On Raspbian for Raspberry Pi Zero, you can install NodeJS as follows:

cd ~
wget http://nodejs.org/dist/v8.4.0/node-v8.4.0-linux-armv6l.tar.gz
cd /usr/local
sudo tar xzvf ~/node-v8.4.0-linux-armv6l.tar.gz --strip=1
sudo apt-get remove --purge npm node nodejs
sudo npm install -g npm
cd ~
rm node-v8.4.0-linux-armv6l.tar.gz

Once NodeJS has been installed, you can get the sample code from our Github project at https://github.com/alexissusset/soracom-xmas-ws2811/

From the same directory, install and start the code as follows:

npm install
node app.js

The App will give you the IMSI for your SIM card, which you can then use to send commands. The application watches for commands on:

xmas/

The commands below will let you switch between different LED animations. We like MQTT.fx for this, since it’s a good MQTT client that runs on Windows, OS X and Linux:

ON (default mode, brightness rotation with Soracom colours)
SORA (Same as default mode, brightness rotation with Soracom colours)
USINEIO (Animation and brightness rotation with UsineIO colours)
ANIME (Animation of different coulours)
IF (Iteration with coloured strip)
IT (Iteration with additional LEDs off)
BR (brightness rotation)
OFF (Switches off the LEDs Strip, great when forgetting to switch things off before leaving)
MQTT.fx client to send commands

MQTT.fx client to send commands

That’s it! You now have a Cellular connected Xmas tree

Cellular connected Xmas Tree

Cellular connected Xmas Tree

Please feel free to send us Github pull request with new LED Animations, we’ll keep updating the project with your creations

If you’d like to learn more about Soracom and IoT in general or otherwise come test out code with us, please feel free to join our online community at https://community.soracom.io/.

You can follow us on social networks and MeetUp groups to get updated on our latest news and events:
Twitter: @SoracomIoT and @alexis_susset
LinkedIn: Soracom
Facebook: Soracom
Bay Area MeetUp: Soracom SV-IoT
Paris MeetUp: Soracom IoT-WS
London MeetUp: Soracom IoT-WS London