Introduction: Christmas Tree Controlled From Phone: No Coding Required Mains Switch Using Particle Photon and IFTTT DO

A mains switch powered by a particle photon and IFTTT. Operate any device (christmas tree!) in your house from your phone! Or from twitter! or based on the weather in your location! With no coding and minimal soldering skill required.

This instructable uses both the Particle Cloud and IFTTT, so if you haven't already, you will need to sign up for the Particle cloud here and for IFTTT here. Furthermore, minimal soldering is required, if you haven't soldered before, look up a good instructable tutorial on how to solder.

Having said that: let's get making!

Step 1: Stuff and Tools

You will need the following stuff:

  • Particle Photon
  • mini bread board (sparkfun or floris.cc)
  • as small as possible USB charger. I used a knock-off samsung, see photo above.
  • a few breadboard connectors
  • a few inches of electrical wire thick enough for your load ("normal" electrical wire for house appliances)
  • a few inches of thin electrical wire for the 3.3V side.
  • two small pushbuttons
  • a case with both a male and a female mains plug that will hold all the electronics. I found mine at a local shop in Haarlem. A quick Google-search found this one for the european market.

and

  • relay that switches at 3.3V and can handle the load you are putting on it. Mine is a capable of switching 230V and 5A, for a total of 1150W. More than enough for my christmas tree lights.
  • one 1 kilo-Ohm resistor
  • one NPN transistor. I used the BC547

or, of you want to keep it really simple, in stead of the three items above:

  • this ready-to-go relay shield from SeeedStudio. (Make sure you have the v1.2, which can switch at 3.3V, the V1.1 only works at 5V and the Photon does not!)

You will need the following tools:

  • Dremel, or other tool of very precise destruction, to carefully remove the housing from the USB charger.
  • soldering iron
  • hot glue
  • wire cutter
  • strip pliers (or teeth... at your own risk)
  • Multi-meter

Step 2: Destroy the Charger

Using the Dremel, or your preferred tool of precise destruction, remove the housing from the charger. Identify where the mains connect and where the GND and 5V from the USB cable connect. Solder thick wires to the mains connection. Cut a breadboard wire in half and solder the open ends to the GND and 5V (for color-correctness I cut both a black for GND and a red one for 5V). Place the charger inside the enclosure and solder the other end of the thick wires to the mains connection. Soldering onto the mains connector can be a bit tricky. If you have it, use a big, extra hot soldering iron, bigger than you would use for fine electronics. For easy soldering, I put a wire connector in between the mains and the charger.

Step 3: The Circuit

Before you press the Photon in the breadboard: solder half a breadboard wire to the "setup" patch on the back of the Photon. Press the Photon in the breadboard and hook everything up as shown in the schematic. For the pushbuttons and the wires that go to the relay coil: cut the end of breadboard wires and solder the open ends to the buttons and the relay respectively. Hot-glue the pushbuttons to the outside of the enclosure. You may have to make a little extra hole to feed the wires through.

Place the relay in the enclosure, about where you want to place it. Solder one of the incoming mains onto the relays "com" (usually between the coil connections: be careful that the coil and the mains do not touch!). Solder the "normally open" connector of the relay to the outgoing mains connector. Directly solder the other incomming main connector to the other outgoing main connector.

At this point, before closing the enclosure hook up the photon to power using a USB cable. Check if it powers up. Check if it resets when you push the reset button. Than, check if the LED of the photon changes color to blinking blue when you hold the setup button. If that all works, remove the USB cable and carefully close the enclosure, making sure not to put any force on wires.

So much for the hardware: the rest is just settings!

Step 4: No Programming: Setting Up the Photon

Power everything up by inserting it in a wall socket. The Photon should start blinking green, assuming it is a new Photon. If it is, press the setup button until it blinks blue. Than, follow the steps at particle.io/start to set it up for the first time. Stop as soon as it is "breathing cyan". During this process, you have to give it a name. Make it one you can remember!

Step 5: No Programming: Controlling With IFTTT DO

Open the IFTTT DO app. The app can be downloaded from the app store or Google Play. After sending yourself an email (if this is the first time using DO), you can create your own recipe. Add a recipe by clicking on the settings icon in the lower right corner (on iOS). Choose a free spot . You now get suggestions on existing recipes, but we want to add our own. Click the big plus on iOS or the "channels" tab on Android. Search for the "particle" channel and click it. Choose the "call a function" Action. Give the recipe a good title (mine is called "christmas tree ON"), than in the "Function Name"-dropdown menu, select the "digitalWrite" function on the name of the Photon that you just choose.

In the "with input (Function Input)" field, remove all text and replace it with "D7,HIGH" (no quotation marks, no spaces, all caps). This will make the value of pin D7 high (ie. 3.3V) every time you press the button in the app. Press "add" to finish making this recipe.

Now add another recipe, give it a different name ("christmas tree OFF"), call the same function on the same Photon, but now give it input "D7,LOW". You now have two buttons: one to turn your christmas tree on, one to turn it off. Switch buttons by swiping horizontally in the app. Give it a try!

Step 6: Spice It Up! Make It Your Own!

That is it! control your christmas tree (or any other device) using your phone.

If you want to take this further: in stead of using the DO button, you can use anything available in IFTTT. For example: make a warning light that turns on when the temperature drops below freezing? Easy, use the "weather channel" on IFTTT as a trigger and the same Particle action as we just made in DO. See this recipe as an example. You can use any trigger you like from IFTTT, for example:

The Photon runs the "tinker" firmware that it comes with out of the box. If you do want to write some software, you can reprogram it over the air. The programming language is basically the Arduino language, extended with some specific, easy to use, cloud functions. Some great examples can be found in the tutorials here. Programming is done in the online IDE here.

Good luck: happy making!

Tech Contest

Participated in the
Tech Contest