This experiment is a nice example how you could make a security detector. You can place the PIR sensor in a room but also in a closet to protect valuable things you care about and get email notifications on demand.
This is a project built with SmartLiving.io an end-to-end IoT solution (Much like an open mashup of Xively and IFTTT) that's built for makers and developers.
Schematic
- Grove PIR sensor
- Grove LED
- Arduino & Grove shield
- SmartLiving IoT Web App
Ingredients
Basic knowledge how to work with an Arduino is a must have, if you've never used an Arduino before we suggest the SmartLiving getting started guide.
- Arduino ethernet
- USB2serial board
- USB Cable
- Grove Shield
- Grove PIR sensor
- Grove LED
- SmartLiving Account
If you stumbled across this page you can get all this hardware and equipment in the SmartLiving IoT Starter Kit: Arduino Edition.
The Experiment
Building Plan
- Attach Grove shield on the Arduino Ethernet
- Connect the Grove PIR sensor to the D2 Grove connector on the shield
- Connect the Grove LED to the D8 grove connector on the shield
- Connect the ethernet cable to your Arduino
- Connect the power supply to the mains and your Arduino board
- Connect the Arduino to your computer using the USB2Serial adapter and USB cable
Create Your Device
An Arduino is represented as a device in the SmartLiving Cloud.
- Log in to the SmartLiving Web App
- Click on the Devices icon in the Left menu
- Click on the “+” sign on the right side of the window to create a new device
- Enter a valid Device name, your Arduino device is now created
Click on the circle on the righthand side of the device to see an overview.
Currently your device has no assets. The assets, in this experiment include a PIR sensor and actuator LED, which will be created automatically by the sketch on the Arduino starts up.
On the right side of the screen, you will see Device Id, Client Id and Client Key which you will need to be entered in your Arduino sketch.
The Device Id is unique for each of your devices, this is used together with your Client Id and Client Key in your code to access and identify your device securely and safely
Upload the Arduino sketch
A sketch is a program that runs on the Arduino and uses an Arduino IDE editor on your computer. You can find the Arduino_Motion_Sensor sketch in the experiments folder from the arduino-client repo found on Github. If you have already downloaded the arduino-client check out the experiments folder. Otherwise download the GitHub repo (https://github.com/allthingstalk/arduino-client).
- Ensure your Arduino is connected to your computer using the USB2serial & USB cable, and that you're seeing blinking LED's on the board.
- Open the sketch in your Arduino IDE
Adjust the sketch for your account, replace the text between the quoted placeholders with your Device Id, ClientId and ClientKey that was seen when you created your device in the SmartLiving Web App
- Adapt the MAC address in the sketch with the Arduino's (This can be found on a sticker on the back of your Arduino)
Once you've updated your Id's and MAC address you can now validate and run your sketch.
In the setup method, you'll notice the assets for the PIR sensor and LED actuator, these are created with the “Device.AddAsset()” function provided from the library. The SensorName, SensorId, ActuatorName, and ActuatorId are used to define the asset which will be created in the SmartLiving Web App. You don't need to edit any of these details but, ensure the sensor/actuator Id’s are unique in your sketch.
After the sketch has compiled and uploaded you should now see the assets created under your device in the SmartLiving Web App.
Test your Arduino
It’s time to test the first part of the experiment.
- Click on the LED asset in the SmartLiving Web App
You should see a widget representing a toggle. When you change the position of the toggle button the LED will now turn ON and OFF.
You can do the same for the PIR sensor, except when the motion is triggered, by waving your hand in front of the PIR sensor for example, the toggle button will switch position, returning the boolean value of the sensor.
Configure an automation rule between the PIR sensor and the LED actuator
Now to setup an automation rule between the PIR sensor and the LED actuator. The rule will trigger the LED when the PIR sensor is activated.
For this we are going to use the rule manager in the SmartLiving Web App. The rule manager allows us to configure condition based logic triggers between assets and services. Time to set up the rule:
- Select Rules from the SmartLiving Web App menu
- Select Create
Rules are setup in three steps, a simple wizard will guide you through the process.
In the first step configure the WHEN trigger.
- Select your Arduino device
- Select the PIR sensor asset
- Configure it as ‘==’ constant True
- Click on create trigger
In the second step configure the THEN action.
- Select your Arduino device
- Select the LED asset
- Configure it as constant and select True
- Click on create Action
In the third click on the ELSE action.
- Select your Arduino device
- Select the LED asset
- Configure it as constant and select False
- Click on create Action
Finally we can Create and Activate the rule we have defined.
Test the first part of the experiment
It’s time to test the experiment. Activate the motion sensor (Just wave your hand over it, or do a dance), this should trigger the LED on the Arduino.
Did it work? Yes? Great! You just made a Smart device!
If it didn't work, too bad, go over each step again and test each part carefully (Failing that you can check out the Help & Support).
Receive a notification rule
Now lets setup a second rule using the email-me service to notify us when there is movement.
This can for example be used as a security system to detect if someone enters a restricted area or secret room when you're not around.
Setup the email-me service
email-me is one of the services available through the SmartLiving Cloud which can be used in your automation rules.
The email-me service is an easy-to-use notification service which sends an e-mail to the mail address that you used when you signed up. We made it so simple that you don’t have to configure anything for the mail service itself. You just have to choose it in the rule!
Setup a rule for the email service
Similar to the PIR sensor and the LED in the experiment above, we are going to setup a rule between the PIR sensor and the email-me service.
Set up the rule:
- Select rules in the menu on the left in the SmartLiving Web App
- Select Create
In the first step configure the WHEN trigger.
- Select your Arduino device
- Select the PIR sensor asset
- Configure it with an equals operator(‘==’) and a constant of True
- Click on create Trigger
In the second step configure the THEN action.
- Select the email-me service
- Enter a string in the text box
- Click on create action
We don't need an else action so click on the Create and Activate button
Test the experiment
It’s time to test the experiment. Let's trigger the motion sensor (wave your hand over it). Give it a moment and you should now receive an e-mail notifying you that there was movement!
Did it work? Yes? You've now got a Smart device talking to an email service!
If it didn't work, go over each step again and test each part carefully.
Comments