Connect any sensor (motion sensor, light sensor, water sensor, or something else) to Particle Photon and use it to trigger any IFTTT action you specify (send a text message, turn on your lights, log data to a spreadsheet, etc.). Follow this guide to create a single program that reads from your sensor and connects it to a custom IFTTT applet.
Step 1: Set up your Photon- Using Your Computer: Go to particle.io/setup and follow the instructions to create an account and set up your Photon.
- Using Your Phone: Download the Particle Mobile App [iPhone | Android] to create an account and set up your Photon.
Connect your sensor to a digital or analog input on the Photon. Follow these examples for hooking up common sensors.
Motion Sensor (PIR)
Sensor Pin | Photon Pin
VCC | VIN
GND | GND
OUT | D0-D7 (any)
Light Sensor (Photoresistor)
Sensor Pin | Photon Pin
S | A0-A5 (any)
- | GND
unlabeled | VIN
Water Level Sensor
Sensor Pin | Photon Pin
S | A0-A5 (any)
+ | VIN
- | GND
Go to the Particle Web IDE at particle.io/build.
Make a new app and follow these code examples to read from common sensors and publish a Particle event. The Particle.publish() event will later act as an IFTTT trigger.
Motion Sensor
#define PIR_PIN D0 // Replace D0 with the pin you used
#define MIN_TIME_BETWEEN_TRIGGERS 2000 // Time (in milliseconds) of no motion before a new trigger can occur
void setup() {
pinMode(PIR_PIN, INPUT);
}
void loop() {
// PIR_PIN goes HIGH when motion is detected, stays HIGH for a few seconds
if (digitalRead(PIR_PIN)) {
Particle.publish("motion-detected");
// store current time in variable
unsigned long motionTime = millis();
// wait until no motion has been detected for MIN_TIME_BETWEEN_TRIGGERS milliseconds before a new trigger can occur
while(millis() - motionTime < MIN_TIME_BETWEEN_TRIGGERS) {
if (digitalRead(PIR_PIN)) motionTime = millis();
}
}
}
Light Sensor
#define LIGHT_PIN A0 // Replace A0 with your pin
#define LIGHT_LEVEL_THRESHOLD 800 // Replace with your own light level
#define THRESHOLD_SENSITIVITY 50 // higher number = lower sensitivity, lower number = higher sensitivity
void setup() {
}
void loop() {
// value decreases as brightness increases
int darkness = analogRead(LIGHT_PIN);
if (darkness >= LIGHT_LEVEL_THRESHOLD) {
Particle.publish("light-level-changed", "dark");
// Once dark is triggered, the threshold is temporarily shifted so that the state will not float between dark and bright when it's on the threshold. This is how street lights work.
while (analogRead(LIGHT_PIN) > LIGHT_LEVEL_THRESHOLD - THRESHOLD_SENSITIVITY);
} else {
Particle.publish("light-level-changed", "bright");
}
}
Water Sensor
#define WATER_LEVEL_PIN A0 // Replace A0 with your pin
#define WATER_LEVEL_THRESHOLD 100 // Replace with your own light level
#define THRESHOLD_SENSITIVITY 50 // higher number = lower sensitivity, lower number = higher sensitivity
void setup() {
}
void loop() {
int waterLevel = analogRead(WATER_LEVEL_PIN);
if (waterlevel >= WATER_LEVEL_THRESHOLD) {
Particle.publish("water-level-changed", "high");
// Once high is triggered, the threshold is temporarily reduced so that the state will not float between low and high when it's on the threshold.
while (analogRead(WATER_LEVEL_PIN) > WATER_LEVEL_THRESHOLD - THRESHOLD_SENSITIVITY);
} else {
Particle.publish("water-level-changed", "low");
}
}
Step 4: Flash to Photon2. Connect Particle to your IFTTT account.
3. Click your username in the top-right of IFTTT's website and then New Applet.
4. Click this in the "if this then that" formula. Search for Particle and select it.
5. Choose New event published for the trigger.
6. Type the Event Name to match the one in the Photon code (Step 3). The event name is the text between the first set of quotes inside Particle.publish("event-name"). Event Names from the examples are shown below.
- Motion Detector
Particle.publish("motion-detected");
Use motion-detected as the Event Name.
- Light Sensor
Particle.publish("light-level-changed", "dark");
Use light-level-changed as the Event Name.
- Water Sensor
Particle.publish("water-level-changed", "high");
Use water-level-changed as the Event Name.
7. If you are using a light sensor, water level sensor, or another sensor that publishes events for multiple states, fill out the Event Contents with the appropriate value (dark/bright, high/low).
If you are using a motion sensor or something similar, leave Event Contents blank.
When you are finished, click Create trigger.
8. Finish your applet by adding an action. Choose from hundreds of services. Follow the prompts to finish creating your first applet. When you are finished, make sure the applet is turned on and ready to use.
Trigger your sensor and see what happens!
Note: IFTTT applets usually take several seconds to run. If it looks like nothing has happened, give it a minute. If there's still a problem, go to the Particle Console, click on your Photon, and check the Event Logs.
Comments