Skip to main content

Radio Motion Detector

This guide walks you through the Radio Motion Detector project. You'll work with the motion detector in Node-RED, and when it detects movement, the IFTTT service sends a push notification to your smartphone.

Block Diagram​

Block diagram: Radio Motion Detector Kit with the PIR Module linked by radio to the gateway, Node-RED and IFTTT

Requirements​

Firmware Upload​

You'll upload the firmware to the Core Module with HARDWARIO Playground.

Step 1: Connect the Core Module to your computer with a Micro USB cable​

Step 2: Flash the firmware​

Start HARDWARIO Playground, select the hardwario/twr-radio-motion-detector firmware on the Firmware tab and upload it to the Core Module.

warning

Flashing Core Module R1 and R2 The older Core Module 1 and the newer Core Module 2 are flashed differently; see Core Module R1 and R2 comparison in the Hardware section.

Step 3: Disconnect the Micro USB cable from the Core Module and the computer​

success

Your firmware is now uploaded.

Hardware Assembly​

Watch this short video for a simple step-by-step demonstration:

Playing the video loads it from YouTube (Google).

Step 1: Start with the Mini Battery Module​

warning

Check that there are no batteries in the Mini Battery Module.

Step 2: Plug the Core Module onto the Mini Battery Module​

Step 3: Plug the PIR Module onto the Core Module​

Playground Setup​

danger

If you use the new HARDWARIO Playground, open the Functions tab instead of http://localhost:1880/. Pairing now happens on the Devices tab, and you test communication on the Messages tab.

Step 1: Open Node-RED in your web browser​

http://localhost:1880/

Step 2: You should see an empty workspace with Flow 1​

Step 3: Import the following snippet into the flow (Menu >> Import) and click the Flow 1 tab​

[{"id":"2fc604fc.3b6abc","type":"inject","z":"dfc861b.b2a02a","name":"List all gateways","topic":"gateway/all/info/get","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":560,"y":460,"wires":[["a2c10833.24d5d8"]]},{"id":"1e4502b8.2f63fd","type":"inject","z":"dfc861b.b2a02a","name":"Start node pairing","topic":"gateway/usb-dongle/pairing-mode/start","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":570,"y":580,"wires":[["795ff5a7.8e266c"]]},{"id":"3d844ce2.932864","type":"inject","z":"dfc861b.b2a02a","name":"Stop node pairing","topic":"gateway/usb-dongle/pairing-mode/stop","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":560,"y":640,"wires":[["5967c452.c838bc"]]},{"id":"f202b253.2705b","type":"inject","z":"dfc861b.b2a02a","name":"List paired nodes","topic":"gateway/usb-dongle/nodes/get","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":560,"y":520,"wires":[["f0aca138.0b2c3"]]},{"id":"349f02fd.890f6e","type":"inject","z":"dfc861b.b2a02a","name":"Unpair all nodes","topic":"gateway/usb-dongle/nodes/purge","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":560,"y":700,"wires":[["2f1c5bb6.53d6f4"]]},{"id":"cf61d75d.4ad8f8","type":"mqtt in","z":"dfc861b.b2a02a","name":"","topic":"#","qos":"2","broker":"67b8de4a.029d3","x":530,"y":400,"wires":[["a5cb0658.f5d658"]]},{"id":"a5cb0658.f5d658","type":"debug","z":"dfc861b.b2a02a","name":"","active":true,"console":"false","complete":"false","x":790,"y":400,"wires":[]},{"id":"a2c10833.24d5d8","type":"mqtt out","z":"dfc861b.b2a02a","name":"","topic":"","qos":"","retain":"","broker":"717f7c18.ba0a24","x":770,"y":460,"wires":[]},{"id":"f0aca138.0b2c3","type":"mqtt out","z":"dfc861b.b2a02a","name":"","topic":"","qos":"","retain":"","broker":"717f7c18.ba0a24","x":770,"y":520,"wires":[]},{"id":"795ff5a7.8e266c","type":"mqtt out","z":"dfc861b.b2a02a","name":"","topic":"","qos":"","retain":"","broker":"717f7c18.ba0a24","x":770,"y":580,"wires":[]},{"id":"5967c452.c838bc","type":"mqtt out","z":"dfc861b.b2a02a","name":"","topic":"","qos":"","retain":"","broker":"717f7c18.ba0a24","x":770,"y":640,"wires":[]},{"id":"2f1c5bb6.53d6f4","type":"mqtt out","z":"dfc861b.b2a02a","name":"","topic":"","qos":"","retain":"","broker":"717f7c18.ba0a24","x":770,"y":700,"wires":[]},{"id":"67b8de4a.029d3","type":"mqtt-broker","z":"","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""},{"id":"717f7c18.ba0a24","type":"mqtt-broker","z":"","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""}]

It looks like this:

Imported Node-RED flow with inject buttons for the gateway commands, each wired to an MQTT node

info

The snippet adds buttons for the gateway and radio commands, which are sent over MQTT.

Step 4: Deploy the flow with the Deploy button in the top-right corner​

Step 5: Open the debug tab​

Node-RED editor with the debug tab highlighted in the right sidebar

info

The debug tab shows all MQTT messages.

Step 6: Click the List all gateways button. The debug tab should show a response like this​

Debug tab showing the gateway info response after clicking List all gateways

success

You now have working Node-RED, MQTT, HARDWARIO Radio Dongle and HARDWARIO Gateway.

Radio Pairing​

In this section, we'll establish a radio link between the Radio Dongle and the Radio Motion Detector. In Node-RED, follow these steps:

Step 1: Click the Start node pairing button​

Start node pairing button highlighted, with the pairing start confirmed in the debug tab

Step 2: Insert the batteries into the Radio Motion Detector to send the pairing request (the red LED on the Core Module should also light up for about 2 seconds)​

Step 3: Click the Stop node pairing button​

Stop node pairing button highlighted, with the pairing stop confirmed in the debug tab

success

You now have a radio link between the node (Radio Motion Detector) and the gateway (Radio Dongle).

Communication Test​

In Node-RED, follow these steps:

Step 1: Switch to the debug tab on the right​

Step 2: Wave your hand in front of the PIR Module to trigger a radio transmission​

You should then see messages like these:

Debug tab showing PIR event-count messages increasing as motion is detected

success

Radio communication is now verified.

Enclosure​

If you have a suitable enclosure, you can put the assembly into it.

info

You'll find enclosures for TOWER kits in the Enclosures category of the HARDWARIO Store.

Integration with IFTTT​

In this section, we'll create an Applet in the IFTTT service. An Applet is a rule that responds to an event with an action.

Step 1: Open a web browser and go to IFTTT​

IFTTT homepage with the Sign in button highlighted

Step 2: Sign in to IFTTT. You can also sign up with your Google or Facebook account​

IFTTT Discover page after signing in, with My Applets highlighted in the menu

Step 3: Go to My Applets in the menu and click the New Applet button​

My Applets page with the New Applet button highlighted

Step 4: Click +this in the if this then that sentence​

New Applet editor with +this highlighted in the if this then that sentence

Step 5: Search for the Webhooks service and select it​

Choose a service step with Webhooks typed in the search and the Webhooks tile highlighted

Step 6: Click Receive a web request​

Choose trigger step with the Receive a web request card highlighted

Step 7: Type motion in the Event Name field and click Create Trigger​

Trigger fields with motion typed as Event Name and the Create trigger button highlighted

Step 8: Click +that in the if this then that sentence​

New Applet editor with +that highlighted in the if this then that sentence

Step 9: Search for the Notifications action service and select it​

Choose action service step with Notifications searched and the Notifications tile highlighted

Step 10: Click Send a notification from the IFTTT app​

Choose action step with the Send a notification from the IFTTT app card highlighted

Step 11: Enter the text The motion detected on {{OccurredAt}} in the Notification field and click the Create action button​

Action fields with the motion notification text filled in and the Create action button highlighted

Step 12: Click the Finish button​

Review and finish step for the motion applet with the Finish button highlighted

Step 13: Click the Webhooks button​

Finished motion applet switched on, with the Webhooks icon highlighted

Step 14: Click the Documentation button​

Webhooks service page with the Documentation button highlighted

Step 15: Click the event field​

Webhooks documentation page showing your key, with the event placeholder in the trigger URL highlighted

Step 16: Enter motion in the event field and keep the window open​

Webhooks documentation page with motion entered in the event field of the trigger URL

Step 17: Install the app on your phone​

Install the IFTTT app on your smartphone and sign in with the account you used to create the applet. When the app asks, allow push notifications.

Step 18: Try it out​

Webhooks documentation page with the Test It button highlighted

Step 19: A push notification should arrive on your smartphone within a few seconds​

Step 20: Copy the URL to the clipboard; you'll need it later​

Webhooks documentation page with the full trigger URL for the motion event highlighted

success

You now have a working notification Applet in the IFTTT service.

Connect Node-RED to IFTTT​

In this section, we'll link the motion event on MQTT to an HTTP request to IFTTT, which triggers the push notification.

Step 1: Switch to your Node-RED flow​

Step 2: Import the following snippet into the flow (Menu >> Import)​

[{"id":"aa6e1255.ea79f","type":"mqtt in","z":"1683bd68.e7a7b3","name":"","topic":"node/motion-detector:0/pir/-/event-count","qos":"2","broker":"3db59913.baf0c6","x":580,"y":580,"wires":[["fd3ce751.8e9ba8"]]},{"id":"74e6dfc1.7c1dc","type":"http request","z":"1683bd68.e7a7b3","name":"","method":"POST","ret":"txt","url":"https://maker.ifttt.com/trigger/motion/with/key/YOUR_IFTTT_KEY","tls":"","x":910,"y":580,"wires":[[]]},{"id":"fd3ce751.8e9ba8","type":"change","z":"1683bd68.e7a7b3","name":"","rules":[{"t":"delete","p":"payload","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":710,"y":680,"wires":[["42aed05e.e145"]]},{"id":"42aed05e.e145","type":"delay","z":"1683bd68.e7a7b3","name":"","pauseType":"delay","timeout":"30","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":900,"y":680,"wires":[["74e6dfc1.7c1dc"]]},{"id":"3db59913.baf0c6","type":"mqtt-broker","z":"","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""}]

It looks like this:

Node-RED flow wiring the PIR event-count topic through change and delay nodes to an http request node

In the http request node, replace YOUR_IFTTT_KEY with the key shown on your Webhooks documentation page (step 15).

info

The snippet connects the MQTT topic node/motion-detector:0/pir/-/event-count to an HTTP request. Before the message goes to the HTTP request, we remove the payload parameter, because it would otherwise be used as the request body.

Step 3: Double-click the http request node and enter the IFTTT URL you got in the previous section​

Edit http request node dialog with the IFTTT trigger URL pasted into the highlighted URL field

Step 4: Save the URL with the Done button​

Step 5: Deploy the flow with the Deploy button in the top-right corner​

success

You should now get a push notification whenever motion is detected.