Introduction: Remote Relay Using Particle Photon
Particle (formally Spark) have released their new line of affordable WiFi enabled microcontroller platforms: The Photon. This is the successor to the Spark Core and measures in at a tiny 37mm x 21mm footprint. I have created a few garden watering devices using Raspberry Pi, Arduino, and Spark Core. This time I will create just a remote relay and enable it using IFTTT.
You must claim your Photon before using it. The process is so simple that Particle has create an iPhone and Android application for it.
Step 1: Required Items
The parts list is pretty straightforward:
- Particle Photon
- Relay module
I've sourced my relay modules from Banggood.com but you'll be able to find similar parts from eBay and many other sources. I've chosen to use an 8 relay module and will use all eight digital pins on the Photon.
Step 2: Prepare the Firmware
In the setup for the firmware, I define a Particle Cloud function named "parse". The intent is that I can send messages to my Photon coded with either "ENABLE" or "DISABLE" followed by a pin number that relates to the digital pins on the Photon. So sending "ENABLE1" will set D1 to HIGH and sending "DISABLE1" will set D1 to LOW.
The "parse" function simply extracts the pin number from the command message and issues the appropriate digitalWrite operation.
Step 3: Connecting With IFTTT
It couldn't be easier to control your remote relay than using IFTTT. There is a channel in IFTTT that will allow you to connect directly to your Photon and exposes the "parse" function. You can create a recipe in a few minutes that will enable or disable a relay port.
It is possible to create an IFTTT recipe to enable/disable a relay pin based on time of day, day of week or any other date/time combination. You can also react to Github, Twitter or even Life360 events. There are many channels that you can use to control your Photon.
It is even possible to use your Photon as a source of information such as creating Particle Cloud variables for sensors such as soil, humidity, or gas.
I have created a recipe that IF "time of day is 6am" THEN "use the parse function and send ENABLE7 on my Photon". The cool thing about D7 is that the Photon also has an LED on it so you can quickly ensure that it is working properly.