Photon To IFTTT - toSvenson/intro-workshop GitHub Wiki
Connect an Internet Button to IFTTT
Prerequisites to complete is part of the workshop:
- A Photon Cloud Account
- A Photon Internet Button
- An IFTTT Account
Write sketch for the Photon
Open the online build environment of Particle.io on build.particle.io.
At the left-hand side you can see the vertical menu which you will use during the process. Hover you mouse over each item to get familiar with the different options:
FLASH VERIFY SAVE CODE LIBRARIES DOCS DEVICES SETTINGS
Let's get started!
- First we want to select the Photon we connected to our account in the previous step. From the menu, press
DEVICES - Check if your device is listed and select it by clicking the yellow star in front of the device name.
- From the menu, press
"< >" Codeto open the code editor - Press
CREATE NEW APPand enter a Title (e.g.PhotonIFTTT) - Again at the left-hand side press
Libraries(first item below"< >") - Select the Official Library:
InternetButton - Press
INCLUDE IN APP, select the app you just created (e.g. photon_temp) and pressADD TO THIS APP - Paste the code below in the
.inofile, replacing it's current content
// This #include statement was automatically added by the Particle IDE.
#include "InternetButton/InternetButton.h"
InternetButton b = InternetButton();
uint8_t button1 = 0;
uint8_t button2 = 0;
uint8_t button3 = 0;
uint8_t button4 = 0;
uint8_t buttonAll = 0;
int gaugeCount = 0;
// The code in setup() runs once when the device is powered on or reset. Used for setting up states, modes, etc
void setup() {
// Tell b to get everything ready to go
b.begin();
}
/* loop(), in contrast to setup(), runs all the time. Over and over again.
Remember this particularly if there are things you DON'T want to run a lot. Like Spark.publish() */
void loop() {
if(b.allButtonsOn()){
if(!buttonAll){
buttonAll = 1;
Particle.publish("allbuttons",NULL, 60, PRIVATE);
b.rainbow(10);
delay(100);
b.allLedsOff();
}
}
else {buttonAll = 0;}
if(b.buttonOn(1)){
if(!button1){
button1 = 1;
Particle.publish("button1",NULL, 60, PRIVATE);
b.ledOn(12,50,0,0);
delay(100);
b.ledOff(12);
}
}
else {button1 = 0;}
if(b.buttonOn(2)){
if(!button2){
button2 = 1;
Particle.publish("button2",NULL, 60, PRIVATE);
b.ledOn(3,0,50,0);
delay(100);
b.ledOff(3);
}
}
else {button2 = 0;}
if(b.buttonOn(3)){
if(!button3){
button3 = 1;
Particle.publish("button3",NULL, 60, PRIVATE);
b.ledOn(6,0,0,50);
delay(100);
b.ledOff(6);
}
}
else {button3 = 0;}
if(b.buttonOn(4)){
if(!button4){
button4 = 1;
Particle.publish("button4",NULL, 60, PRIVATE);
b.ledOn(9,30,30,30);
delay(100);
b.ledOff(9);
}
}
else {button4 = 0;}
}
Create IFTTT Recipies
Button to Email
- Log onto IFTTT and hit "Create Recipe"

- Select Particle as your Trigger Channel (IFTTT step 1)
If you have not already activated the Spark channel you’ll need to do so now. Use the same email address you use for your Spark login account (but note that it needs to be all lowercase here for some reason).
- Choose a "Trigger" (IFTTT step 2)
I want to use the part of my firmware that includes Particle.publish so I’m going to select “New Event Published”.
- Complete Trigger fields (IFTTT step 3)
| Field | Value |
|---|---|
| If (Event Name) | button2 (other options: allbuttons, button1, button3 or button4) |
| If (Event Contents) | "Milk" (optional, you can leave it blank) |
| Device Name or ID | Choose device from dropdown |
- Choose Action Channel (IFTTT step 4)
Let's send an email when the button is pressed. This email represents an order being placed to a retail supplier. You can also experiment with this recipe using other action channels.
Search for gmail and select the option.
- Choose an Action and configure settings (IFTTT step 5-7)
Choose the "Send an email" action.
Complete "TO address""Subject" and "Body" fields.
| Field | Value |
|---|---|
| To address | fill in a recipient email address |
| Subject | New order - {{EventContents}} |
| Body | Enter whatever body you like |
Finish the wizard by clicking "Create Recipe".