In this particular scenario, my goal was to attach a motion sensing device to Raspberry Pi Zero W and have it send me alerts. Now that this basic functionality is achieved, I can modify and reuse it as I wish.
I used the following:
Hardware:
- Raspberry Pi Zero W
- PIR motion sensor (EMY 5 X HC-SR501 Adjust Ir Pyroelectric Infrared PIR Motion Sensor Detector)
Software:
- (Operating system: Debian)
- Programming Language: Node.js
- Communication medium: IFTTT.com
STEP ONE: ATTACHING THE PIR
This PIR component has three pins (Power, Output, Ground.) Using female-to-male cables, I attached as follows:
PIR PINS
|
RASPBERRY PI GPIO PINS
|
POWER
|
PIN 2 (5v)
|
OUTPUT
|
PIN 7
|
GROUND
|
PIN 6
|
STEP TWO:
- If you don't have one already, set up an account at ifttt.com . Personally, I do not recommend this site for confidential actions but it is fun to play with!
- Navigate to "My Applets" and click on "New Applet"
- Click the "Plus" image and you should be taken to a page "Choose a service"
- Search for "web" and choose "Maker Webhooks"
- Select "Receive a web request" as a trigger
- Enter the following tag: "motion_detected" to create a trigger
- You should be re-directed to a page that reads "If (webhook) then" Plus sign.
- Select the "SMS" service.
- Select "Send me an SMS"
- Enter your tag "motion_detected" to create an action and then add the phone number for SMS
- You should receive a special "key". Save this.
- Review changes and save.
STEP THREE: INSTALLING SOFTWARE ON PI:
- Create a folder for project and ensure internet is connected.
- Open a terminal window, type the following:
- Test to see if Node.js is installed)
Node –v
- If no version is returned or version is below v6, get latest:
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
- Once version is downloaded, then install:
sudo apt-get install –y nodejs
- Test to see if latest version of Node.js is installed:
Node –v
- Open code (pir_motion_trigger.js) in text editor. You will change the following lines of code to customize for your IFTTT applet:
// IFTTT data
var key = "enter key here"
var eventName = "motion_detected"
- Save code and close
- Once again, open a terminal window and navigate to your folder.
- Type the following:
sudo node pir_motion_trigger.js
- Wait a minute or two then wave your hand in front. Soon you should get a text message.
NOTE: This particular model of PIR has the ability to adjust sensitivity for motion delay and distance. You can manipulate by adjusting the two yellow/orange screws or programmatically.
No comments:
Post a Comment