3. Security System via @IFTTT

With this project, we make a security device that uses a PIR Sensor to detect when a burglar or stray animal breaks into your home. You will receive an email alert if this is the case.

Webhook will be used as the most basic service. A POST request is sent to IFTTT’s service from Raspberry Pi Pico W. Using IFTTT, we will create an Applet to intercept the webhook and send an email.

1. Build the Circuit


Make sure your Li-po Charger Module is connected as shown in the diagram. Otherwise, a short circuit will likely damage your battery and circuitry.



IFTTT is a free service that provides a variety of ways to connect different data services together.

We’ll create an Applet that reacts to a webhook (custom URL) that sends data to IFTTT. IFTTT will then send an email for you.

Please follow the steps below on IFTTT.

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

  2. Click on Create.

  3. Add an If This event.

  4. Search for Webhooks.

  5. Tap Receive a web request.

  6. Fill in the event name (e.g. SecurityWarning), and click Create trigger.

  7. Add a Then That event.

  8. Search for Email.

  9. Click Send me an email.

  10. Fill in Subject and Body, then click on Create action.

  11. Click Continue to complete the configuration.

  12. Modify the title name and you’re finished.

  13. Now you will 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 start/close it.


3. Run the Script

  1. Now that we have created the IFTTT Applet, but we also need the API Key which can be obtained from the Webhooks Settings to allow Pico W to access IFTTT.

  2. Copy it to the secrets.py script in Raspberry Pi Pico W.



    If you don’t have do_connect.py and secrets.py scripts in your Pico W, please refer to 1. Access to the Network to create them.

    secrets = {
    'ssid': 'SSID',
    'password': 'PASSWORD',
  3. Open the 3_ifttt_mail.py file under the path of kepler-kit-main/iot, then click File -> Save as or press Ctrl+Shift+S.

  4. Select Raspberry Pi Pico in the popup window that appears.

  5. Set the file name to main.py. A prompt will appear if the same file already exists on your Pico W.

  6. You can now unplug the USB cable and use the Li-po Charger Module to power the Raspberry Pi Pico W. You will hear a buzzer tick when the script is running. The buzzer will keep sounding if the PIR module detects a person/creature passing by, and an email alert will be sent to you. The script can be restarted by pressing the button.

How it works?

The Raspberry Pi Pico W needs to be connected to the Internet, as described in 1. Access to the Network. For this project, just use it.

from do_connect import *

Reads data from the PIR module and calls the motion_detected() function if it detects someone passing by (data from 0 to 1).

import machine


sensor.irq(trigger=machine.Pin.IRQ_RISING, handler=motion_detected)

Next the Pico W sends data to IFTTT. As you can see, the message that you send to IFTTT is a url string. IFTTT identifies the sender by secrets['webhooks_key'], the triggered event is identified by event. So, make sure they are correct.

import urequests
from secrets import *


def motion_detected(pin):
    global warn_flag

When motion_detected() is called, the variable warn_flag is set to True, causing the buzzer to keep going.

while True:
    if warn_flag==True:

The purpose of the button here is to restart the script.


def reset_device(pin):

button.irq(trigger=machine.Pin.IRQ_RISING, handler=reset_device)