Project tutorial
KidGuard

KidGuard © GPL3+

Safeguard your kid with this.

  • 1,718 views
  • 0 comments
  • 5 respects

Components and supplies

Apps and online services

About this project

Introduction

Sometimes you don't want your little kids to go outside of your house by themselves or get into a room which has potential danger like your workarea without your knowledge. Here KidGuard can help to alert you if such a situation occurs using Walabot and Alexa.

How does it work? When a target, who is a kid approaching a safeguarded area, opens the door (detected with door switch). The alarm (buzzer) will go off because a kid is shorter than an adult (using Walabot to track the target's Y value). Then what is the role of Alexa? Alexa will be used here to turn on or off the KidGuard system. The buzzer will go off only if the KidGuard system is activated and there is a violation (kid opens the door).

Step 1. Setup Raspberry Pi

Follow this step to get your Raspberry Pi ready.

Step 2. Install Node-RED

Follow this step to install Node-RED.

Step 3. Install the Arduino node

Follow this step to install the Arduino node for Node-RED. I am using Firmata in this project. You need to upload the Standard Firmata to the Arduino Uno, follow this link to accomplish that.

Step 4. Install the Alexa Local

Follow this step to install the Alexa Local Node-RED module.

Step 5. Setup the Walabot

Follow the instructions here and here to complete this step. Checkout the Hello Walabot app here to verify you have setup Walabot successfully.

Step 6. Setup the Node-RED Flow

Import the Node-RED Flow (KidGuard Flow) from the code section below.

Walabot Service

Set Global Variables

KidGuard, Buzzer and Door Switch

Print Saved Variables Helper

.

Step 7. Write the Python code to get Walabot reading

Check out the Python code (KidGuardWalabot.py) from the code section below.

Demo Time

.

Demo #2

Why demo #2? Because demo #1 (see below) does not tell the whole story. Demo #1 tells you how to turn on and off the KidGuard. It shows you the result when there is a violation which will cause the buzzer to sound.

Demo #2 tells what will happen when a tall target open the door (disconnect the door switch) and the buzzer will sound.

.

How does the KidGuard know if a target is tall or short? When the target is lower than the center of a Walabot board, it will register a y value which is less than zero (y<0). When it is a taller target, the Walabot will register a positive y value (y>0).

.

Walabot with short target:

.

Walabot with tall target:

.

This video demos that when the KidGuard was turned on and a tall target opened the door, the buzzer did not sound. Here I standed in from of a Walabot board and disconnect the door switch. And the buzzer did not sounded.

KidGuard with tall target.

.

This is another video which demos that a short targer opened the door. In this scenerio, I squatted below the Walabot board's center to pretend as a kid. When I disconnected the door switch, the buzzer sounded and I needed to tell Alex to turn off the buzzer.

KidGuard with short target.

.

Demo #1

The following video shows how to activate KidGuard with Alexa by saying "Turn on KidGuard". There will be not a lot visualization in this video.

Turning on and off KidGuard

This video shows simulated demo where a violation (breaking the door switch connection) will trigger a buzzer. You will need to attend the situation by manually ask Alexa to turn off the buzzer.

KidGuard simulated demo.

.

.

Code

KidGuardWalabot.pyPython
from __future__ import print_function
from sys import platform
from os import system

import WalabotAPI as wlbt

import socket, sys

if __name__ == '__main__':
        wlbt.Init()  # load the WalabotSDK to the Python wrapper
        wlbt.SetSettingsFolder()  # set the path to the essetial database files
        wlbt.ConnectAny()  # establishes communication with the Walabot

        wlbt.SetProfile(wlbt.PROF_TRACKER)  # set scan profile out of the possibilities

        #wlbt.SetThreshold(35)
        #wlbt.SetArenaR(50,400,4)
        #wlbt.SetArenaPhi(-45,45,2)
        #wlbt.SetArenaTheta(-20,20,10)

        wlbt.SetDynamicImageFilter(wlbt.FILTER_TYPE_MTI)  # specify filter to use

        wlbt.Start()  # starts Walabot in preparation for scanning

        system('cls' if platform == 'win32' else 'clear')  # clear the terminal
        numOfTargetsToDisplay = 1
        if len(sys.argv) == 2:
                TCP_IP = '127.0.0.1'
                TCP_PORT = int(sys.argv[1])

                s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                s.bind((TCP_IP, TCP_PORT))
                s.listen(1)
                conn, addr = s.accept()
                while True:
                        wlbt.Trigger()  # initiates a scan and records signals
                        targets = wlbt.GetTrackerTargets()  # provides a list of identified targets

                        target = '{"target": ['
                        index = 0

                        for i, t in enumerate(targets):
                                if i < numOfTargetsToDisplay:
                                        index += 1
                                        print('Target #{}\nx = {}\ny = {}\nz = {}\n'.format(i+1, t.xPosCm, t.yPosCm, t.zPosCm))
                                        target += '{"x": "%s", "y": "%s", "z": "%s"}' % (t.xPosCm, t.yPosCm, t.zPosCm)

                        target += ']}'
                        conn.sendall(str.encode(target))
                conn.close()
                wlbt.Stop()  # stops Walabot when finished scanning
                wlbt.Disconnect()  # stops communication with Walabot
KidGuard FlowJSON
[{"id":"216d9d05.042b12","type":"arduino out","z":"3f44fcdf.307c44","name":"","pin":"7","state":"OUTPUT","arduino":"d4c6e849.844578","x":1270,"y":740,"wires":[]},{"id":"ae716057.e4571","type":"alexa-local","z":"3f44fcdf.307c44","devicename":"buzzer","inputtrigger":false,"x":203.10000610351562,"y":740,"wires":[["216d9d05.042b12"]]},{"id":"7300ed97.589464","type":"arduino in","z":"3f44fcdf.307c44","name":"door switch","pin":"3","state":"INPUT","arduino":"d4c6e849.844578","x":221.10000610351562,"y":634.2000122070312,"wires":[["95296c59.24881","af3799c0.4e39d8"]]},{"id":"32097bae.c00744","type":"debug","z":"3f44fcdf.307c44","name":"","active":false,"console":"false","complete":"false","x":850,"y":504,"wires":[]},{"id":"ad36c7d4.572048","type":"inject","z":"3f44fcdf.307c44","name":"start KidGuardWalabot","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":true,"x":245.10000610351562,"y":367,"wires":[["2162ed1f.a18e72"]]},{"id":"2162ed1f.a18e72","type":"exec","z":"3f44fcdf.307c44","command":"python","addpay":false,"append":"KidGuardWalabot.py 2000","useSpawn":"false","timer":"","oldrc":true,"name":"start KidGuardWalabot.py","x":550,"y":367,"wires":[["70d99112.4a917"],[],[]]},{"id":"d8ee745f.7094a8","type":"tcp in","z":"3f44fcdf.307c44","name":"","server":"client","host":"localhost","port":"2000","datamode":"stream","datatype":"buffer","newline":"","topic":"","base64":false,"x":233.10000610351562,"y":491,"wires":[["dbf05ea7.98ad1"]]},{"id":"dbf05ea7.98ad1","type":"function","z":"3f44fcdf.307c44","name":"set target y and covert to json","func":"raw = msg.payload.toString('UTF-8')\njson = JSON.parse(raw);\nvar m1 = { payload: raw };\nvar m2 = { payload: json };\n\n\nif (raw.length > 20)\n{\n    y = m2.payload.target[0].y;\n    global.set(\"y\", y);\n    var m3 = { payload: y };\n}\n\nreturn [  m1, m2, m3 ];  \n\n","outputs":"3","noerr":0,"x":570,"y":491,"wires":[[],[],["32097bae.c00744"]]},{"id":"95296c59.24881","type":"debug","z":"3f44fcdf.307c44","name":"","active":true,"console":"false","complete":"payload","x":513.1000366210938,"y":636,"wires":[]},{"id":"70d99112.4a917","type":"debug","z":"3f44fcdf.307c44","name":"","active":false,"console":"false","complete":"false","x":850,"y":353,"wires":[]},{"id":"7736213d.98133","type":"alexa-local","z":"3f44fcdf.307c44","devicename":"kid guard","inputtrigger":false,"x":209,"y":820,"wires":[["d881ae8b.9a0d8"]]},{"id":"d881ae8b.9a0d8","type":"function","z":"3f44fcdf.307c44","name":"set kid guard ","func":"global.set(\"kidguard\", msg.payload);\nreturn msg;","outputs":1,"noerr":0,"x":446.10003662109375,"y":820,"wires":[["ab7d78df.6edce8"]]},{"id":"ab7d78df.6edce8","type":"debug","z":"3f44fcdf.307c44","name":"","active":false,"console":"false","complete":"false","x":672.1000366210938,"y":820,"wires":[]},{"id":"398378a.38e5588","type":"inject","z":"3f44fcdf.307c44","name":"print saved variables","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":227.10000610351562,"y":907,"wires":[["3d9d0eaa.b5c1d2"]]},{"id":"3d9d0eaa.b5c1d2","type":"function","z":"3f44fcdf.307c44","name":"build msg","func":"msg.payload = { \"y\": global.get('y'), \"kidguard\": global.get('kidguard')}\nreturn msg;","outputs":1,"noerr":0,"x":439.10003662109375,"y":907,"wires":[["14e58dbb.03a242"]]},{"id":"14e58dbb.03a242","type":"debug","z":"3f44fcdf.307c44","name":"","active":true,"console":"false","complete":"payload","x":644.1000366210938,"y":906,"wires":[]},{"id":"af3799c0.4e39d8","type":"switch","z":"3f44fcdf.307c44","name":"check door switch","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"}],"checkall":"true","outputs":1,"x":472.10003662109375,"y":693,"wires":[["f3dd27d1.d39db8"]]},{"id":"f3dd27d1.d39db8","type":"switch","z":"3f44fcdf.307c44","name":"check kid guard","property":"kidguard","propertyType":"global","rules":[{"t":"eq","v":"on","vt":"str"}],"checkall":"true","outputs":1,"x":680.1000366210938,"y":693,"wires":[["c4b97926.b46d48"]]},{"id":"c4b97926.b46d48","type":"switch","z":"3f44fcdf.307c44","name":"check y","property":"y","propertyType":"global","rules":[{"t":"lt","v":"0","vt":"num"}],"checkall":"true","outputs":1,"x":847.1000366210938,"y":693,"wires":[["51985380.b6488c"]]},{"id":"51985380.b6488c","type":"function","z":"3f44fcdf.307c44","name":"set buzzer on","func":"msg.payload = 1;\nreturn msg;","outputs":1,"noerr":0,"x":1017.5000305175781,"y":693,"wires":[["216d9d05.042b12"]]},{"id":"d4c6e849.844578","type":"arduino-board","z":"","device":"/dev/ttyACM0"}]

Schematics

Raspberry Pi, Walabot and Arduino Uno
Pi walabot uno bb v2lsqef8k5

Comments

Similar projects you might like

Anna: Alexa Powered Interactive Light

Project tutorial by vincent wong

  • 2,000 views
  • 0 comments
  • 7 respects

Alexa Controlled LEDs Through Raspberry Pi

Project tutorial by vincent wong

  • 7,092 views
  • 6 comments
  • 29 respects

Saving Aquatic Life & Fighting Water Pollution with IoT & AI

Project tutorial by Madhur Gupta

  • 7,388 views
  • 2 comments
  • 23 respects

Email Home Automation

Project tutorial by Chirila Radu

  • 4,948 views
  • 0 comments
  • 15 respects

Alexa Smart Mailbox

Project tutorial by Team CodersCafe

  • 2,459 views
  • 4 comments
  • 16 respects

Child Assistant

Project tutorial by Md. Khairul Alam

  • 1,818 views
  • 0 comments
  • 19 respects
Add projectSign up / Login