Security System via IFTTT

With this project, we create a security device that employs a PIR Sensor to detect intruders or stray animals entering your home. In case of a breach, you will receive an email alert.

We’ll utilize Webhooks as the fundamental service. A POST request is sent to IFTTT’s service from UNO R4.

Required Components

In this project, we need the following components.

It’s definitely convenient to buy a whole kit, here’s the link:

Name

ITEMS IN THIS KIT

LINK

Elite Explorer Kit

300+

Elite Explorer Kit

You can also buy them separately from the links below.

COMPONENT INTRODUCTION

PURCHASE LINK

Arduino Uno R4 WiFi

-

Jumper Wires

BUY

PIR Motion Sensor Module

BUY

Wiring

../_images/03-ifttt_pir_bb.png

Schematic

../_images/03-ifttt_pir_schematic.png

Setting up IFTTT

IFTTT is a free service that offers various methods to link different data services together.

Let’s create an Applet that responds to a webhook (custom URL) sending data to IFTTT, which will then send you an email.

Please follow the steps below on IFTTT.

  1. Visit IFTTT to log in or create an account.

    ../_images/03_ifttt_1.png
  2. Click on Create.

    ../_images/03_ifttt_2.png
  3. Add an If This event.

    ../_images/03_ifttt_3.png
  4. Search for Webhooks.

    ../_images/03_ifttt_4.png
  5. Select Receive a web request.

    ../_images/03_ifttt_5.png
  6. Fill in the event name (e.g., SecurityWarning), and click Create trigger.

    ../_images/03_ifttt_6.png
  7. Add a Then That event.

    ../_images/03_ifttt_7.png
  8. Search for Email.

    ../_images/03_ifttt_8.png
  9. Choose Send me an email.

    ../_images/03_ifttt_9.png
  10. Enter the Subject and Body, then click Create action.

../_images/03_ifttt_10.png
  1. Click Continue to finish the setup.

../_images/03_ifttt_11.png
  1. Adjust the title name as needed.

../_images/03_ifttt_12.png
  1. You’ll be automatically redirected to the Applet details page, where you can see that the Applet is currently connected and you can toggle the switch to enable/disable it.

../_images/03_ifttt_13.png
  1. Now that we’ve created the IFTTT Applet, we also need the webhooks key, which can be obtained from Webhooks Settings to allow your device to access IFTTT.

../_images/03_ifttt_14.png
  1. Copy the webhooks key to “arduino_secrets.h” and fill in your SSID and password.

    #define SECRET_SSID "your_ssid"        // your network SSID (name)
    #define SECRET_PASS "your_password"        // your network password (used for WPA, or as a key for WEP)
    #define WEBHOOKS_KEY "your_key"
    

Run the Code

Note

  • You can open the file 03_ifttt_pir.ino under the path of elite-explorer-kit-main\iot_project\03_ifttt_pir directly.

  • Or copy this code into Arduino IDE.

Note

In the code, SSID and password are stored in arduino_secrets.h. Before uploading this example, you need to modify them with your own WiFi credentials. Additionally, for security purposes, ensure that this information is kept confidential when sharing or storing the code.

Warning

To prevent your mailbox from being flooded, please debug the PIR Motion Sensor Module beforehand before running the code for this project.

How it works?

  1. Include the necessary libraries and header files:

    • "WiFiS3.h": Used for managing Wi-Fi connections.

    • "arduino_secrets.h": Contains Wi-Fi network name and password to safeguard sensitive information.

  2. Define some global variables and constants:

    • ssid: Name of the Wi-Fi network.

    • pass: Wi-Fi network password.

    • status: Status of the Wi-Fi connection.

    • client: Client used for communicating with the Wi-Fi server.

    • server: Address of the IFTTT Webhook server.

    • event: Name of the IFTTT Webhook event.

    • webRequestURL: Constructed URL for sending HTTP requests, including the Webhook event name and key.

    • pirPin: Digital pin to which the PIR sensor is connected.

    • motionDetected: Flag variable to track motion detection.

  3. setup() function:

    • Initializes serial communication.

    • Checks for the presence of the Wi-Fi module and outputs its firmware version.

    • Attempts to connect to the Wi-Fi network, with retries if unsuccessful.

    • Sets the pin connected to the PIR sensor to input mode.

  4. readResponse() function:

    • Reads HTTP response data from the IFTTT server and prints it to the serial console.

  5. loop() function:

    • Calls the readResponse() function to read HTTP response data.

    • Checks for motion using the PIR sensor. If motion is detected and was not detected previously:
      • Prints “Motion detected!” to the console.

      • Calls the triggerIFTTTEvent() function to send an HTTP request to the IFTTT server, triggering the Webhook event.

      • Sets the motionDetected flag to true to indicate motion has been detected.

    • If no motion is detected, sets the motionDetected flag to false.

  6. triggerIFTTTEvent() function:

    • Establishes a connection with the IFTTT server.

    • Sends an HTTP GET request, including the URL of the Webhook event and other HTTP headers.

  7. printWifiStatus() function:

    • Outputs information about the connected Wi-Fi network, including SSID, IP address, and signal strength (RSSI) to the serial console.