PIR Sensor with IFTTT Integration: Trigger Anything in Your Smart Home

Project Overview

This project connects a PIR sensor to IFTTT (If This Then That), allowing you to trigger thousands of smart home actions. When motion is detected, you can turn on lights, send notifications, log data to spreadsheets, control smart plugs, or trigger security cameras.

Difficulty: Intermediate
Estimated time: 1-2 hours
Estimated cost: $15-25

How It Works

An ESP32 detects motion from a PIR sensor and sends an HTTP request to IFTTT’s Webhooks service. IFTTT then triggers any action you have configured. Since the ESP32 uses Wi-Fi, it needs to be within range of your network, but the IFTTT integration works from anywhere.

Materials Needed

  • ESP32 or ESP8266 (1)
  • HC-SR501 PIR sensor (1)
  • Jumper wires
  • Power supply (5V USB)
  • IFTTT account (free)

IFTTT Setup

  1. Create an account at ifttt.com
  2. Click Create → If This
  3. Search for and select Webhooks
  4. Select Receive a web request
  5. Enter an event name (e.g., motion_detected) → Create trigger
  6. Click Then That and choose your desired action (Philips Hue, Smart Life, Email, SMS)
  7. Configure the action (e.g., turn on living room light)
  8. Click Continue → Finish
  9. Go to Webhooks service page → Documentation to get your API key

Circuit Diagram

Connection Table

VCC

3.3V

GND

GND

OUT

GPIO 4

Arduino Code

// PIR Sensor with IFTTT Integration
#include <WiFi.h>
#include <HTTPClient.h>

const char* ssid = "YourWiFiSSID";
const char* password = "YourWiFiPassword";

const char* iftttKey = "YourIFTTTKey";
const char* eventName = "motion_detected";

const int pirPin = 4;

unsigned long lastTriggerTime = 0;
const unsigned long minInterval = 10000;

void setup() {
  Serial.begin(115200);
  pinMode(pirPin, INPUT);
  
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) delay(500);
  
  delay(60000);
}

void triggerIFTTT() {
  if (WiFi.status() == WL_CONNECTED) {
    HTTPClient http;
    String url = "http://maker.ifttt.com/trigger/" + String(eventName) + "/with/key/" + String(iftttKey);
    http.begin(url);
    int httpCode = http.GET();
    http.end();
  }
}

void loop() {
  bool motion = digitalRead(pirPin) == HIGH;
  
  if (motion && (millis() - lastTriggerTime > minInterval)) {
    lastTriggerTime = millis();
    triggerIFTTT();
  }
  
  delay(100);
}

Enhanced Version with Data

void triggerIFTTTWithData(int sensorId) {
  if (WiFi.status() == WL_CONNECTED) {
    HTTPClient http;
    String url = "http://maker.ifttt.com/trigger/" + String(eventName) + "/with/key/" + String(iftttKey);
    http.begin(url);
    http.addHeader("Content-Type", "application/json");
    String payload = "{\"value1\":\"" + String(sensorId) + "\",\"value2\":\"" + String(millis()) + "\"}";
    http.POST(payload);
    http.end();
  }
}

Low-Power Battery Version with p

#include <esp_sleep.h>

void setup() {
  esp_sleep_enable_ext0_wakeup((gpio_num_t)pirPin, 1);
}

void loop() {
  triggerIFTTT();
  delay(5000);
  esp_deep_sleep_start();
}

Installation Steps

  1. Set up IFTTT account and create Webhooks trigger
  2. Create desired actions (lights, notifications, etc.)
  3. Get IFTTT API key from Webhooks documentation
  4. Update code with Wi-Fi credentials and IFTTT key
  5. Upload to ESP32 and test with hand motion
  6. Verify IFTTT triggers in activity log
  7. Place sensor in desired location

Popular IFTTT Actions for PIR Sensors

  • Send SMS via Twilio
  • Send push notification via IFTTT app
  • Send email to yourself or family
  • Turn on Philips Hue lights
  • Activate TP-Link Kasa smart plug
  • Control Sonos speakers
  • Add row to Google Sheets
  • Log to Google Drive

Conclusion

This IFTTT integration opens up countless possibilities for your PIR sensor. With minimal coding, you can connect your sensor to virtually any smart home device or online service.

Leave a Reply

Your email address will not be published. Required fields are marked *

Component Pin ESP32 Pin
PIR Sensor PIR Sensor PIR Sensor