Introduction: Burglar Alarm With Sending SMS and Email From Your IoT Device

About: Pooja Baraskar is an Intel Software Innovator,author, speaker and a passionate Software Developer, who is always willing to learn and explore new technologies. Being a programmer, she always have a solution fo…

Phone notifications are a good way to get alerted about an
unusual activity. When we are developing an IoT solution it is always good to send SMS to user’s phone for certain activity as the smartphones are always within reach. It is not always possible for a user to monitor the data with a Mobile app or a website. If they get a notification about a certain activity or a sudden variation in data they will come to know this by time and can immediately check it with the mobile app and can take the further steps.

Earlier sending SMS with a microcontroller was a little clumsy process, you have to create an account on SMS service provider like Twilio and then you have to use some IoT channels like Thingspeak, Temboo, and IFTTT. Lots of work! But now as the IoT devices are getting powerful, there are some new revolutionary IoT Cloud services are immerging. They are aimed to take your data to cloud with an ease. One of the IoT cloud recently I am using in my projects is Ubidots. The best thing about Ubidots is, it is user-friendly. It won’t take much time to take your IoT solution to cloud. Ubidots visualize your data in a better way. You can even track the locations with its GPS widget, all you need is just to send the data with a simple API.

With Ubidots we can easily configure under what conditions an alert should be triggered. We can set any type of thresholds through simple "IF - THEN" statements. Once an event is triggered it will send an Email or SMS alerting someone about a specific event or you can perform any other task like trigger another action.

Let us create a simple project with a Burglar Alarm System with Intel Edison which will detect any intrusion and notify you with a SMS or an Email. I am using Ubidot’s Node.Js library and programming in Node.Js with Intel XDK IoT edition.

If you have an Intel Galileo board and programming using Arduino IDE or you want to know more about PIR sensor and its working have a look at another article of mine “Burglar Alarm with PIR motion sensor”.

Step 1: Requirements

Intel Edison module

Arduino expansion board

PIR sensor

Buzzer

An LED

USB cable

Power Supply

Jumper cables

Step 2: Making Connections and Programming

1. Connect your Edison to power supply and to your PC via USB cable.

2. It will take 15-20 seconds to boot up, after that stack the Grove Base Shield.

3. Connect the PIR motion Sensor to analog pin D2.

4. Connect the Buzzer to pin with PWM, I connected to D5.

5. Connect the LED to pin D3.

6. Open Intel XDK IoT edition, if it is not already installed in your PC get it from here. If you have flashed you Edison with the Flash Lite Tool Node.Js will be already installed on your board.

7. Connect IDE to your Edison board. It will ask you for username and password, default username is root with no password.

8. Select a blank Node.JS template and create a new project.

Step 3: Code for PIR Sensor

//Load Grove Motion module

var grove_motion =
require('jsupm_biss0001');

// Instantiate a Grove Motion
sensor on GPIO pin D2

var myMotionObj = new
grove_motion.BISS0001(2);

setInterval(function()

{

if
(myMotionObj.value())

{

BlinkLED();

melody();

v.saveValue(1);

console.log("Detecting moving
object");

}
else
console.log("No
moving objects detected");

v.saveValue(0);

}, 1000);

// Print message when exiting

process.on('SIGINT', function()

{

console.log("Exiting...");

process.exit(0);

});

Step 4: Sending Data to Ubidots

var ubidots = require('ubidots');  
var client = ubidots.createClient('YOUR-API-KEY');  
client.auth(function() {  
  this.getDatasources(function(err, data) {  
   console.log(data.results);  
});  
var ds = this.getDatasource('xxxxxxxx'); 
 ds.getVariables(function(err, data) { 
 console.log(data.results);  
});  
ds.getDetails(function(err,
details) {  
console.log(details); 
});  
var v = this.getVariable('xxxxxxx');  
v.getDetails(function(err,
details) {  
console.log(details);  

});

Step 5: Creating Triggers With Ubidots

1) Log in to your Ubidots account or you can create one here.

2) Select the “Sources” tab and then click on “Add Data Source” to create a new data source. Here I have added My Edison.

3) Once the data source is added we will add our PIR sensor. PIR motion sensor is a digital sensor, it will only detect the motion. It doesn’t detect the distance and number of people. Hence if a motion is detected I am sending 1 else 0 to Ubidots.

4) Click on the variable and copy the variable ID. Paste this in your code also get your API key My Profile -> API Keys.

5) Now we will create events. Select Event tab, click add Event.

6) Select the data source and Variable. In our case it is My Edison and PIR Sensor.

7) Now it will present you with a simple IF- Then statement. Here we have to select the value of PIR Sensor and the action to be triggered.

8) We are sending 1 if PIR sensor detects a motion, hence to trigger an action our value should be equals to 1. Press continue.

9) Now we have to add the trigger, we can send an SMS or an Email, can set another variable or can request a custom URL. Let us select SMS for now.

10) Enter the details like phone number and message to be send.

11) SMS event will be added with PIR sensor value equals to 1. Similar way you can add an Email trigger.

Now we have added an Email and a SMS triggers. Build, upload and run your code on Edison. You will notice data sending to Ubidots in the console. If any motion is detected by the PIR motion sensor it will blink the LED, play the buzzer and a SMS and an Email will be sent to your Phone.

Intel® IoT Invitational

Participated in the
Intel® IoT Invitational