Intro: IoT Controlled Smart Lamp/Outlet Using Spark Core and IFTTT
I wanted to have a night lamp that will turn on after sunset and turn off in the middle of the night. The timers available at homedepot or other hardware stores only allows to set a time. Since in USA there is daylight saving time, it had to be changed. To solve this, the outlet is connected to the internet to obtain the sunset timings daily. We will use IFTTT (https://ifttt.com/recipes) to get the information.
Step 1: Things Used
- Spark Core(now its called photon - https://store.particle.io/)
- Relay(I used SPDT relay - http://www.seeedstudio.com/depot/Grove-SPDT-Relay3...
- pull up resistor ( i used 10k)
- few jumper wires
- IFTTT account
Step 2: Hardware Setup
Setup up the Spark core by connecting to a wifi network. If you dont have previous experience refer to this website. (connecting to wifi instructions). After connecting to wifi, open up spark build on your browser by going to
Click devices (1) and make sure your device is listed with the cyan circle glowing on and off. (refer to pic 1 above). This confirms that the core is online.
Step 3: Connect the Relay to the Core
If you have prior experience working with AC electricity then use the outlet, if not use dc components like led or motor to test. Do not touch soldering joints on the back of the relay while the current is flowing.
In this project, the pin assignment are as follows
- The "sig pin" of the relay is connected to the "D3" of the core.
- "VCC" of the relay is connected to the "VIN" of the core
- "GND" of the relay is connected to the "GND" of the core.
- NC is not connected to anything.
- Connect neutral wire from the power source to the "COM" port of the relay("IN" port if you refer to the relay picture above).
- Connect another wire from "NO" of the relay("out" port if you refer to the relay picture above) to outlet.
(refer to outlet wiring picture if necessary)
Note: Make sure the Vin supplies 5v or higher if not the relay might not work since its rated to work with 5V. In this case IPad charger was used to supply the power to the core and the voltage at Vin was measured to be close to 6V. You could also connect the VCC of the relay to any 5v source directly like arduino etc.
- Connect anode(long leg) to resistor, the other end of the resistor to pin "D3"
- Connect the cathode(short leg) to "COM" of the relay("IN" port if you refer to the relay picture above).
- Connect "NO" of the relay("out" port if you refer to the relay picture above) to "GND" of the core.
Step 4: Coding
Step 5: IFTTT Recipe Setup
First create IFTTT account(its free)
- create new recipe
- click "this" (pic 1)
- search for "weather" in select channel (pic 2)
- click "sunset" or what ever trigger is desired (pic 3)
- click "create trigger" (pic 4)
- click "that" (pic 5)
- search for "particle" in select channel (pic 6)
- click "call a function" (pic 7)
- select the the function name(entered between the quotes when creating spark function during coding) from the dropdown and enter "on" for the input and "create action" (pic 8).
I wanted to turn off the light at 2am at night so i created another ifttt recipe with "time" channel and with input "off"(step 9).
Step 6: Controlling From Smart Phone
To control from smart phone, download DO button app for android or iphone.
open the DO button app
- login in with ifttt account
- tap "+" (pic 1)
- go to channels, and click particle (pic2)
- tap "create a new recipe" (pic 3)
- tap "call a function" (pic 4)
- name the recipe, select the fucntion from the drop down and enter "toggle" for the input(pic 5)
- the recipe is successfully created (pic 6) and pressing the spark symbol will turn on or off the relay(pic 7)