IoT Christmas Tree
Things have been a little crazy around here, so this might be a little late for this year’s Christmas, but since this is IoT, you can take the teachings and hopefully it will inspire you to start your own project. Also make sure that you tag your project as IoT so we can find it!
I gave a talk about IoT at an Open Source Meet up that was hosted on SAP’s Palo Alto campus. The talk was a brief overview of IoT and how SAP sees IoT, then I talked about how we have prototyped different IoT projects using Open Source devices such as Arduino, Raspberry Pi, and BeagleBone Blacks. As a demo of what you could do, my boys (5 & 7) and I built an IoT Christmas Tree that I showed off at the event. When the event was done, I received many requests of how I did it and what was needed to purchase to build it, both the hardware and software. So here is the write up that should help you out to build an IoT Christmas Tree.
A Couple of Notes:
- Below is how I did it. I am in no way saying that I did a good job, or that this is the way that you should do it, but it worked and worked well.
- On the electronics side, a lot of decisions were dictated by what I had around the house from other projects.
- A good example of the above is that I had a lot of 9V batteries around, so I could build 4 light circuits
- Be careful as you add in the BBB into the mix, namely do not inadvertently connect a 9V to it, you will see a small puff of smoke and it will not work. (I am still rather mad at myself for that one)
- I tend to do a lot of testing of everything, where I get one thing working and then expand it. For example, I got the lights working on a breadboard first, and then soldered them to longer wires. So if you have some experience, just skip ahead.
- I grouped the lights into two sets of two. The two are series and the groups are in parallel. This was done to save wires and space on the bread board. Having the two LEDs in series will not drop the brightness down (having four will). Really they should have all been in parallel, but as I said I was running out of wires.
Put lights on a Christmas tree that can be controlled by a BeagleBone Black. Then add some other sensors such as a temperature sensor and a buzzer just to make sure that the electronics don’t get too hot. And send all of this data to a server (in my case, naturally the server the SAP HCP).
- BeagleBone Black Rev C
- LEDs- I used 4 reds, 4 blues, 3 yellows, and 3 greens (I burned out the 4th yellow and ran out of female wires for the 4th green)
- 8 330 Ohm resistors (two for each color)
- 4 relays (had them lying around) or transistors
- lots of jumper wires
- soldering kit, although if you have female jumper wires you can use those
- Christmas tree, I got a glitter one. It was similar to this, but with glitter. It worked out well because it was hallow inside, but the glitter got everywhere as it fell off.
- Temperature sensor
- Piezo (buzzer)
- Any other sensors or items you want to add. Example: add a motion detector, so it is only on when people are around. Add a USB speaker to play music. Add a button so people can turn off the music.
Step one: Hook up the LEDs to the breadboard to make sure that everything works.
- As you can see from the wiring diagram, things can get confusing, just hook up one thing at a time and you will be fine.
- Because I am putting 4 batteries on the breadboard, I divided the board into four, but remember the board is actually only divided in two. This means that the positive and negative rails are for two of the batteries. You will have to make two other “rails”.
- Place the resistor in the breadboard, I used 330 ohms.
- Place the LED where the shorter end (negative or ground) is in the same row as one of the resistors pins.
- The positive end of the LED (longer wire) should be in its own row.
- Connect the other end of the resistor to negative rail
- Connect the positive end of the LED to the positive rail
- Connect the 9V battery’s negative terminal to the negative rail
- Connect the 9V battery’s positive terminal to the positive rail
- The LED will light up
- Place a second LED in the same rows as the first (positive to positive and negative to negative)
- Both will light up.
- Repeat by adding a new resistor and hooking them up in the same way.
- All four should be lit.
Before moving on, I would do the same thing with another color. In the drawing above, I did red and blue.
Step two: Soldering the lights
- Soldering kits are pretty cheap and you will want to do this. It just makes everything stronger.
- Solder the LED’s to long wires
- I used black for all ground wires and used the color of the LED for the positive wires.
- If you don’t have a soldering iron, buy a lot of female jumper wires and then connect them to the LEDs. If possible I would use shrink tubing or electrical tape to make sure that they don’t move or come loose.
You now can replace the lights on the breadboard with the ones that you just created. The wires I used to solder the lights were stiffer than the jumper wires (standard 22 gauge wires), so I taped each pair of wires together and then taped the set together, just to make them more manageable. Then I added a female to male jumper wire to the end so that the connection to the breadboard was easier. Also, connected two lights together (in serial, so red to black) this way only one set of wires was going to each resistor.
Part Two: Adding Relays
Right now you have a Christmas tree with some lights, which is great, but you can’t turn each color on and off independently. You can only turn all of the lights on or off. To do this we need to add some transistors or a relay. A relay is really over kill because they are designed to handle 110 to 220 V and a lot of amps, more than we will need to power our lights, but I have one laying around so I just figured that I would use it.
A relay is just a switch, and when you send a signal line to it, it toggles.
Part Three: Bringing Them Together
So we have our lights in our tree and our transistors all ready. Now we need to hook up the four sets of negative/positive wires from the second breadboard to the one with all of our lights hooked up, and then connect the signal wires to the BBB.
For me, I used pin P8_11 for red and P8_12 for blue, see the code for the others.
Part Four: The Code
The code is in python, because BBBs have it installed already. I think that the code is pretty straightforward. The basic thing is that you just send a high or low to the pin and that will trip the transistor and flip it between on and off.
To make this truly an IoT device, I do send the data to a server, where we can monitor it. Since BBB have Node.js, you can run your own server and control the tree from the web or any connected device.
Part Five: Final Step
So now everything is wired up and ready to go. But it is just a large collection of wires sticking out of a tree, which doesn’t look good. Well all you need to do is find a shoebox and wrap it up the bottom part as a present. Then flip the box over and then cut a hole in the top, in the center, for the wires, but not bigger than the base of the tree. Then carefully unhook one wire and run the wire through the hole and hook it back up. Do this one at a time.
Finally put the box over the BBB and the wires and your are done.
Since you have all of this stuff working, why not just continue? I added a temperature sensor and when the temperature goes over 40 C it makes a noise. This is to tell me that the box is getting too hot. The next step would be to have it turn itself off.
You could add a proximity sensor so that it blink more the closer you get. Or have it tweet. Hook up some USB speakers and play music. Add anything that you want.
SAP IoT- www.sap.com/iot
SAP IoT on YouTube
Another example about getting data into SAP HANA via a number of different platforms (RPi, BBB, Tessel,…)
HCP: An example on using a Raspberry Pi and HCP by Rui Nogueira
BBB getting started- go here: http://beagleboard.org/
Adafruit– They sell a lot of devices and sensors and have a lot of great examples