Introduction: Christmas Tree IoT (Internet of Trees) Using Arduino/WiFI Shield
Sometimes I forget to turn off my christmas tree at night or when I leave the house, so I thought: "Why not connecting my tree to the internet so I can turn it on/off from anywhere I am in the world?"
And here is the end result, the first IoT christmas tree in the world.
It is powered by an Arduino UNO using a WiFi shield to connect to the internet, the Arduino is running a web server in it which can receive commands from the terminal and from an iPhone app.
Enough Intro, let's dive into it
-Arduino UNO ($24.95)
-Arduino WiFi Shield ($49.90)
-A/C adapter for Arduino ($5.95)
I forgot where I got mine from, but here's another seller
-Jumper Wires ($6.00)
These will do, but get the flat ones if you can.
-One 180Ω Resistor
-Two 1kΩ Resistors
-1 Lightbulb with socket (For testing purposes)
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Building the Circuit
Step 2: Putting All the Hardware Together
In this video I demonstrate how all the hardware components are connected together.
Step 3: The Arduino Code
You can download the code for the Arduino from my Github.
Make sure to replace the name of you WiFi network along with the password.
Step 4: Setting Up the Network
We need to open up a port on our home router so that we can access our Arduino from the Internet. This step will most likely be the most confusing one in the entire tutorial for most of you since we all have different routers at home.
NOTE: I currently have an Apple Time Capsule at home and the instructions on how to setup the network will be based on that device. If you have a router other than the time capsule all you need to do is figure out the instructions to do the following on your own router:
1. Give the Arduino a static IP using the MAC address that is on top your Arduino WiFi Shield chip.
2. Setup Port Forwarding, ALL FOUR (public TCP, public UDP, private TCP and private UDP) must be set to 2200
Continue with these instructions if you have an Apple Time Capsule:
-Open the AirPort Utility on your mac (AirPort utility will look different on a Windows machine, you can still follow along though)
-Click on the time machine, and then press Edit
-Go to Network
Giving the Arduino a static IP:
-Once you're in the network tab you should be able to see a label that reads "DHCP Reservations" Click on the "+" button that is right under.
-In the Description field put any label you want, I used "Arduino UNO WiFi Shield"
-"Reserve Address by" should have the "MAC Address" option selected
-In MAC Address put the address that is on your Arduino WiFi Shield 101, it should contain both letters and numbers.
-Finally choose any IP number and write it down, in my case I used 10.0.1.30 but any will do. This will be your PRIVATE IP address, not the public one. Click Save
-After clicking save on the previous step, you should be back on the Network tab in Airport Utility
- Under "Port Settings" click that little button with the plus sign.
-Firewall Entry Type should be set to IPv4 Port Mapping
-In Description you can just type "Arduino 2200"
-Type 2200 in Public UDP Ports
-Type 2200 in Public TCP Ports
-In private IP address you should type the IP address you chose earlier (mine was 10.0.1.30, remember?)
-Type 2200 in Private UDP Ports
-Type 2200 in Private TCP Ports
Finally, click on update and wait a few seconds for your time machine to restart.
Step 5: Network Test
Now we're going to run a quick test to make sure your Arduino is setup properly.
Upload the code that I put on my github link to your Arduino, now from your terminal type this in:
You should be seeing something like this if your Arduino is setup correctly:
64 bytes from 10.0.1.30: icmp_seq=5 ttl=64 time=8.537 ms
Phew! Congrats if you made it this far.
Step 6: See It Work!
Up until this point you should have the circuit built, I'm also assuming the Arduino code is also uploaded and it runs fine. Remember that after uploading your code to the arduino you should open the Serial Monitor using CMD+Shift+M. Make sure your Serial Monitor is visible so you can see the incoming connections.
First we'll turn the Christmas tree on using our home network.
Open up your terminal and type the following:
curl 10.0.1.30:2200 -d 1
And Voilà! See that Christmas tree light on!
Now turn it off using:
curl 10.0.1.30:2200 -d 0
Perfect, now that we're sure that you can reach the Arduino using your local network, let's use your public IP so you can turn it on from wherever you are in the world.
In order to do this you need to get your public IP address
Type in "What is my ip" in Google and click on any link, you should see what your IPv4 is. Write it down because we'll use that in a moment!
Now that you know your public IP address type the following on your terminal:
curl 0.0.0.0:2200 -d 1Obviously you will type in your public IP instead of 0.0.0.0
Turn the tree off using
curl 0.0.0.0:2200 -d 0
Step 7: Optional
Optionally you can make an alias to make it even easier to turn ON/OFF the tree.
If you're on a mac or a linux machine type the following in your terminal
alias tON="curl 0.0.0.0:2200 -d 1"
alias tOFF="curl 0.0.0.0:2200 -d 0"
Now all you need to do is type in tON and tOFF to control your tree, how cool!
*Note: BASH is extremely sensitive when it comes to spaces make sure your spaces match EXACTLY as i have it here.
Step 8: Building IOS App
For this step you'll need two files that are in my Github repository for this project.
Participated in the
Arduino Contest 2016