Use the Force to Spread Holiday Cheer!
by DqwertyC in Circuits > Wireless
1575 Views, 6 Favorites, 0 Comments
Use the Force to Spread Holiday Cheer!
This Instructable will show you how to build a desktop Christmas tree out of office supplies, add a micro controller and individually addressable LEDs, and then use the Sphero Force Band (Released with the second generation Sphero BB-8 droid) to turn the lights on and off. While I'll summarize the underlying technology here, most of the background information can be found in my previous Instructable, ESP8266 Voice Control with Google Assistant.
Materials:
The required materials are:
- Sphero Force Band (Normally $80, but look for Holiday sales!)
- Strand of WS2812B LEDs (Neopixels work, but are identical to and more expensive than others)
-
3x Male-to-Female jumper wires.
-
Soldering Iron
-
USB-A to USB-micro cable
-
Several pieces of 8.5" by 11" paper (NOT Cardstock)
-
Scotch Tape
-
Scissors
-
Android or iOS device with Bluetooth
-
A computer with a web-browser and the Arduino IDE
If you haven't yet, take a minute to review my previous Instructable, and then we'll get started!
Build the Tree!
You don't necessarily have to do this step first,but it's nice to have an overall structure to build onto later. You can also replace the tree with basically anything else you want - a wreath, a candelabra, or even a hat. I like the paper tree because it's simple to build, and the paper works well for diffusing the light from the LEDs.
At the core of our tree, we'll have a stiff cone of paper. This can be done by taking 4-5 pieces of paper, forming them into a long tube, then gently twisting the ends in opposite directions. I found that a cone with a base diameter of about three inches worked best. Once you get it into the shape that you want, tape the cone to itself on the top and bottom edges. Now use your scissors to make the wide end even, to that the cone can stand on its own.
For the exterior of the tree, you'll need 4 pieces of 8.5" by 11" paper. Fold them all in half lengthwise, then fold two adjacent corners in towards the center. Take two of these folded pieces of paper, lay them on top of each other so that the triangular flaps are touching, and tape the flaps together. Then, tape one flap to each of the main pieces of paper. Now, if you gently pull the flat ends of each piece apart from each other and refold along the original crease, you'll get a V shaped piece of overlapping paper. Gently push the long ends of this V together, allowing the center part to pop out. The final piece should have a plus-shaped cross section, with two of the legs significantly longer than the other two. Repeat this process with the other pieces of paper.
You should now have two pieces of paper that have a sort of kite shape when viewed from the side, and a plus shape when viewed from the top. Stack them on top of each other so that all four legs are the same length, and tape them together on the inside. You now have a miniature, albeit somewhat abstract, Christmas tree made entirely from printer paper and scotch tape!
Like I said earlier, this is just an option. Anything you can put the LEDs on will also work!
Connect the Lights!
Now that we have a tree, it's time to add some lights. I used 40 RGB LEDs from the strand because it seemed like a good length for the small desktop tree. You can use more or less, but note that if you use too many, you may not be able to supply enough power for all of them.
We'll start with a simple program that turns most of the lights green (to make the overall tree green), but changes the other lights to a new color every 3 seconds. You can find the code for this attached to this project.
The ESP8266 doesn't have support for the Timer0/Timer3 library that would normally be used for something like this, but it does have its own library, called Ticker, that allows tasks to be repeated at a regular interval. We use this and a switch statement to randomly choose between four colors every 5 seconds.
Even though I'm not using a NeoPixel branded light strand, I can still use the Adafruit NeoPixel library, which already has support for the ESP8266 and makes updating the lights . This can be installed from the library manager in the Arduino IDE.
To connect the lights to my ESP8266 breakout, I used three male-to-female jumper wires, soldering the male end directly to the strand of LEDs, and plugging the other end onto the pins of my breakout board. GND on the strand connects to ground, DI (data in) connects to D4 (though any output pin on the ESP8266 should work), and 5V connects to VIN, which allows the strand to draw power from the USB port without it having to go through the MCU first.
To connect the light strand to the tree, I spiraled the lights around the cone and taped it in place. I also mounted the cone to the bottom of a paper bowl to add a bit more support and a place to hold the microcontroller. Now all that's left is to connect our tree to the Force!
Downloads
Connect to the Internet!
Now we need to connect the tree to the Internet. This part is almost identical to steps 1 and 2 of my previous Instructable, found here. If you haven't already, follow those instructions to set up an Adafruit IO account and create the "onoff" feed to control your tree.
The updates to the code are fairly minimal. Most of the code for connecting to WiFi and to the Adafruit IO servers come from the examples included with their respective libraries. Code for handling the Adafruit IO changes has been added to the main loop, and a global variable to track the state of the light has been added. The source code for this part can be found attached to this project.
To test this part of the project, load the program and check the serial monitor. Once it says MQTT is connected, try moving the switch on your Adafruit IO dashboard to turn the lights on and off. Once that's working, all that's left is to connect your force band to Adafruit IO!
You should make sure that you're using ESP software version 2.0.0. Some people were having issues with my previous tutorial, but user PabloA52 found that this helped fix it.
Downloads
Use the Force!
At $80, the Sphero brand Force Band is a bit pricey, but if you can find it on sale for the holidays, it's a fun little gadget. One of the coolest things about the band is that Sphero added the option to connect it to the Internet of Things through IFTTT. This step requires a Force Band and the free Star Wars Force Band app from Sphero. If you don't have those, no worries! There are plenty of other triggers on IFTTT that can also be used, from Google Assistant or Alexa voice control, to smart home integration, or even reacting to the status of your pizza order!
If you don't already have an IFTTT account, create one using the same email that you used for you Adafruit IO account. Then, go to platform.ifttt.com to start building your custom applet.
The Force Band has three triggers: Force Push, Force Pull, and Force Stop. I decided to use Force Push to turn the lights on and Force Pull to turn them off, but you can use any combination you want. To make a new applet, go to your dashboard, and click the "New Applet" button. Under the "If This" section, start typing "Sphero", and select "Star Wars Force Band by Sphero" from the drop down menu. Then, choose the proper trigger for the action you're trying to make.
Under the "Then" section, choose Adafruit, then choose "Send Data to Adafruit IO." From there you can choose the name of the feed you want to update and the value you want to update them with (either "ON" or "OFF"). Add a name and a description, then save the applet. This applet will only be available to you unless you publish it, so feel free to change it up or experiment with it for a bit.
Once you save the applet, go back to your dashboard to enable it. If you haven't already, IFTTT will prompt you to connect your Adafruit IO and Force Band accounts.
The last step is to connect your Force Band to IFTTT through the Force Band app. Turn on your Force Band and open the app. Follow the on screen steps to connect the band and familiarize yourself with the controls. Under the main menu, select settings, then turn on Force Control with IFTTT. This will add a new item to the main menu, called Force Control. In this new menu, make sure your accounts are connected, then select "Use The Force". This will start tracking gestures and then show a dialog of all of the actions sent to IFTTT.
Everything should be connected at this point. All that should be left is testing the system as a whole!
Final Testing!
The system as a whole should now be working. The band will vibrate slightly and make a noise when it recognizes a gesture, and there is a fair bit of lag between this vibration and the reaction of the lights. However, this isn't too bad considering that the signal has to travel over Bluetooth from the band to your smart device, from there over WiFi or data to the IFTTT servers, from the IFTTT servers to the Adafruit IO servers, and finally from there to the ESP8266 over WiFi. The other main drawback is that the Force Band app has to be running in the foreground on whatever device you're using. That's the main reason I don't have a video of the final project yet, but hopefully that will be rectified soon.
While the Star Wars Christmas Special may have taught us that SciFi and the Holidays don't always go together, hopefully you can still have some fun spreading Yuletide cheer and showing off to your friends with the Force! Thanks for reading, and enjoy!