Introduction: Raspberry Pi Motion Sensor IFTTT

Hello. I am a 4th grader and today we are going to make a IFTTT motion sensor


1x little cardboard box

1x raspberry pi model b+ or a+

1x PIR sensor
(Various) jumper wires

1x smart lightbulb (optional)

Duct tape (optional)

ifttt account

Step 1: Cut:

Cut a small hole in the middle of the top of the box.

Step 2: Attaching the PIR Sensor:

Connect the PIR sensor’s pin labelled VCC to the 5V pin on the Raspberry Pi. This provides power to the PIR sensor.Connect the one labelled GND to a ground pin on the Pi (also labelled GND). This completes the circuit.Connect the one labelled OUT to any numbered GPIO pin on the Pi. In this example, we have chosen GPIO 4. The OUT pin will output a voltage when the sensor detects motion. The voltage will then be received by the Raspberry Pi.

Step 3: Setup Webhooks:

make a new applet, and then Select Webhooks. and then do the same with notifications.

Step 4: Code:

For python 3 or thonny

#! /usr/bin/python # Importsimport RPi.GPIO as GPIOimport timeimport requests # Set the GPIO naming conventionGPIO.setmode(GPIO.BCM) # Turn off GPIO warningsGPIO.setwarnings(False) # Set a variable to hold the GPIO Pin identitypinpir = 17 # Set GPIO pin as inputGPIO.setup(pinpir, GPIO.IN) # Variables to hold the current and last statescurrentstate = 0previousstate = 0 try: print("Waiting for PIR to settle ...") # Loop until PIR output is 0 while GPIO.input(pinpir) == 1: currentstate = 0 print(" Ready") # Loop until users quits with CTRL-C while True: # Read PIR state currentstate = GPIO.input(pinpir) # If the PIR is triggered if currentstate == 1 and previousstate == 0: print("Motion detected!") # Your IFTTT URL with event name, key and json parameters (values) r ='', params={"value1":"none","value2":"none","value3":"none"}) # Record new previous state previousstate = 1 #Wait 120 seconds before looping again print("Waiting 120 seconds") time.sleep(120) # If the PIR has returned to ready state elif currentstate == 0 and previousstate == 1: print("Ready") previousstate = 0 # Wait for 10 milliseconds time.sleep(0.01) except KeyboardInterrupt: print(" Quit") # Reset GPIO settings GPIO.cleanup()


"Can't Touch This" Family Contest

Participated in the
"Can't Touch This" Family Contest