This is the Arduino source code for controlling a Christmas tree covered in Neopixel LED light strips. The project was created for a Christmas IoT popup shop that showcased various uses of IoT technology with a holiday theme. The Arduino connects to the Losant IoT platform in order to receive commands. If you're interested in the actual components used to build the tree, please check out the related blog article.
Losant is an IoT platform that is currently free to use for a limited number of devices. Losant is used to facilitate communication between the tree's website and the Arduino via MQTT. If you're interesting in learning more about Losant and keeping up-to-date with product announcements, please follow us at @LosantHQ.
The Arduino subscribes to Losant device messages to control what animation to run and the animation options. The messages should be JSON strings and the various commands are defined below.
Causes the tree to fade from a color to another color over a specified duration.
{
"animation" : "fade",
"options" : {
"to" : { "r" : 0, "g" : 0, "b" : 255 },
"from" : { "r" : 255, "g" : 0, "b" : 0 },
"duration" : 5000
}
}
The above example animations the tree from solid blue to solid red over 5 seconds.
Runs an animation that kind of looks like the warp core from Star Trek: the Next Generation.
{
"animation" : "warpcore",
"options" : {
"duration" : 15000
}
}
The above example will run the warp core animation for 15 seconds.
Runs an animation that looks like a firework.
{
"animation" : "firework",
"options" : {
"duration" : 15000
}
}
The above example will run the firework animation for 15 seconds.
The tree can also be controlled by POSTing JSON data to the Losant webhook URL. The webhook triggers a workflow that simply passes the data directly to the device using the above mechanism. The same payloads apply.
POST: https://triggers.losant.com/webhooks/zzplbKb8yJH6ajWWdGL6HOKxndm1
We created a website at http://led-tree.christmasiot.com that can be used to control the tree. The website also live-streams the tree so you can see your changes as well as what others are doing to the tree.