loading

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

www.build.particle.io..

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

CAUTION

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.

Relay

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.

LED (DC)

  • 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

To program the core, go to build website.

  1. Click code
  2. Create a new app and name it.
  3. Copy paste the following code
  4. Click verify
  5. Click flash

once the program has flashed successfully, the project is ready.

Step 5: IFTTT Recipe Setup

First create IFTTT account(its free)

  1. create new recipe
  2. click "this" (pic 1)
  3. search for "weather" in select channel (pic 2)
  4. click "sunset" or what ever trigger is desired (pic 3)
  5. click "create trigger" (pic 4)
  6. click "that" (pic 5)
  7. search for "particle" in select channel (pic 6)
  8. click "call a function" (pic 7)
  9. 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

  1. login in with ifttt account
  2. tap "+" (pic 1)
  3. go to channels, and click particle (pic2)
  4. tap "create a new recipe" (pic 3)
  5. tap "call a function" (pic 4)
  6. name the recipe, select the fucntion from the drop down and enter "toggle" for the input(pic 5)
  7. the recipe is successfully created (pic 6) and pressing the spark symbol will turn on or off the relay(pic 7)

Step 7: Demo

<p>Great project! How long did it take you to build?</p><p>Have a great day! :-)</p>
It took half a day. It would have been faster if I realized the relay i used operates at 5v not 3.3v

About This Instructable

3,627views

64favorites

License:

More by radrajith:IoT controlled Smart Lamp/Outlet using spark core and IFTTT How to change remote's button function for raspberry pi(raspbmc) 
Add instructable to: