Project tutorial
Intruder Alarm with Text Message Notification

Intruder Alarm with Text Message Notification © CC BY-NC-SA

This intruder alarm detects motion and sends a text message alert to your phone via WiFi, so you can receive the text anywhere.

  • 29,635 views
  • 13 comments
  • 56 respects

Components and supplies

Ard yun
Arduino Yun
×1
Tens70
9V battery (generic)
×1
11026 02
Jumper wires (generic)
×1
range sensor hc-sro4
×1

Apps and online services

About this project

This is very easy to do and requires no soldering or advanced skills.

Here's how it works:

Range sensor detects interruption in pings --->

Calls to Temboo via WIFI --->

Tells Twilio API to send text!

This tutorial shows you how to create an intruder alarm that sends you text message alerts when motion is detected. This may sound complicated but I am pretty confident any beginner with electronics should be able to do this just fine. The range sensor senses motion and tells your Arduino board to send the text . So you can leave the intruder detector at home, connected to your network, and still receive the SMS alerts, no matter where you are, as long as you have cell phone service.

This is a pretty quick and easy project, it takes maybe 45 minutes to complete. Parts can be had on Amazon for about $80-$90, or about $50 if you don't mind waiting from AliExpress.com. The main cost is an Arduino board with WIFI capabilities, however once you have that it can be used in tons of other projects and much more fun can be had...

Parts you will NEED:

-HC-SRO4 Range sensor

-Arduino Yun board or Leonardo with a WIFI shield

-4 jumper wires

-A mini breadboard (if you want)

-A 9V battery

-A 9V battery box with barrel plug and on/off switch

Links to parts and code can be found here:

Parts Links and Code

Step 1: Make these connections and test!

Connect your range sensor to your board as shown in the diagram here.

First we are going to test our range sensor and make sure its working.

Go to the first block of code here http://wirebeings.com/arduino-intruder-alarm.html

and copy/paste it into the Arduino IDE.

Plug in your board and upload the sketch.

Pull up the serial monitor and make sure it is on 9600 BAUD.

You will see a string of numbers being printed

(this is the distance the closest object is away from the sensor in inches)

Anytime a large enough difference in pings is detected by the sensor it will print out "Intruder Detected" to the serial monitor.

Step 2: Get your board connected to your WiFi network.

If you are using an Arduino Yun follow the instructions here:

https://www.arduino.cc/en/Main/ArduinoBoardYun

If you are using a Leonardo with an Iduino wifi shield follow the instructions here:

http://www.geeetech.com/wiki/index.php/Iduino_Yun_Shield

To test a make sure it is connected to the same network as your computer you can use the terminal and do a quick LAN scan of your network or download a free program that will do it for you.

I use a Mac so I downloaded LanScan from the Mac store.

Step 3: Adding the text message functionality.

Open the Arduino IDE and create a new sketch.

Copy and paste the second code block from here into the Arduino IDE:

http://wirebeings.com/arduino-intruder-alarm.html

Click the down arrow on the right side and hit create new tab.

Call it TembooAccount.h

Go back to the website above and copy and paste the last code block (the header file) into there.

Save it.

Now you need to create an Account on Temboo and on Twilio so you can add your information into the code.

Step 4: Add your Twilio and Temboo credentials to the sketch.

Navigate to account settings in your Twilio account to find your Account SID and Auth Token (click the lock button to display it)

Add these to the main sketch inside the quotes where appropriate "***********"

Go back to the Twilio homepage and hit Account again. Hit phone numbers and this will give you your "Sent From" phone number, add this to the code.

Finally, add the phone number that you want to receive the text, and customize the message if you want.

(Keep the phone numbers in this format or it won't work "+1*******" )

Now go to the header file and add your Temboo account information. Login to your Temboo account and hit Applications to get all this information.

Save it and hit upload.

Power your board with the 9V battery pack (hit the on switch) and pull up the serial monitor to make sure its working!!!

It may take 20 seconds or so to connect.

Step 5: And....YOU'RE DONE!

If your having problems where its not working correctly. Change the range of numbers in this highlighted statement in the picture here.

This statement means you will send the message if the distance to the closest object is less than 20 or greater than 500. Depending on where its located in your house and what the closest object is, those values will need to be played with in order to make it work properly.

This is best done in the testing stage where the code does not actually send the text message (the first code block on the website), because you only get a limited number of free calls to Temboo and the Twilio API, so don't waste them! Don't worry though the code actually prevents you from sending more than 10 calls before the board has to be unplugged and restarted.

Hit me up with any questions I would be glad to help!

Code

IntruderDectectorTESTArduino
//TEST CODE 


#include <SoftwareSerial.h>

int trigPin = 2;
int echoPin = 4;
long duration, cm, inches;

void setup() {

  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  delay(5000);
  Serial.println("Patrol Mode Initiated...");
}

void loop()
{

  digitalWrite(trigPin, LOW);
  delayMicroseconds(1);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(2);
  digitalWrite(trigPin, LOW);

  pinMode(echoPin, INPUT);
  duration = pulseIn(echoPin, HIGH);

  inches = (duration / 2) / 74;
  Serial.println(inches);
  if (inches < 20 || inches > 1000) {
  Serial.println("Intruder Detected!");
  Serial.println("Sending text Notification...");
  delay(5000);
  Serial.println("Patrol Mode Initiated...");
  }//end if statement




}//ends loop
Full Code with Text FuntionalityArduino
#include <Bridge.h>
#include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information, as described below
#include <SoftwareSerial.h>

int numRuns = 1;   // Execution count, so this doesn't run forever
int maxRuns = 5;   // Maximum number of times the Choreo should be executed
int trigPin = 2;
int echoPin = 4;
long duration, cm, inches;

void setup() {
  Serial.begin(9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  // For debugging, wait until the serial console is connected
  delay(5000);
  Bridge.begin();
  Serial.println("Patrol Mode Initiated...");
}

void loop() {

  digitalWrite(trigPin, LOW);
  delayMicroseconds(1);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(2);
  digitalWrite(trigPin, LOW);

  pinMode(echoPin, INPUT);
  duration = pulseIn(echoPin, HIGH);

  inches = (duration / 2) / 74;
  Serial.println(inches);
  if (inches < 20 || inches > 1100) {
  Serial.println("Intruder Detected!");
  Serial.println("Sending text Notification...");

  if (numRuns <= maxRuns) {
    Serial.println("Running SendSMS - Run #" + String(numRuns++));
    
    TembooChoreo SendSMSChoreo;

    // Invoke the Temboo client
    SendSMSChoreo.begin();

    // Set Temboo account credentials
    SendSMSChoreo.setAccountName(TEMBOO_ACCOUNT);
    SendSMSChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
    SendSMSChoreo.setAppKey(TEMBOO_APP_KEY);
    
    // Set Choreo inputs
    SendSMSChoreo.addInput("AuthToken", "e684a4f37ee686636e2b1e24c12f4279");
    SendSMSChoreo.addInput("To", "+14125236422");
    SendSMSChoreo.addInput("From", "+14123608633");
    SendSMSChoreo.addInput("Body", "Intruder Detected!!!!!!");
    SendSMSChoreo.addInput("AccountSID", "ACf3be01a84d78829e5619c16b6e16a9e4");
    
    // Identify the Choreo to run
    SendSMSChoreo.setChoreo("/Library/Twilio/SMSMessages/SendSMS");
    
    // Run the Choreo; when results are available, print them to serial
    SendSMSChoreo.run();
    
    while(SendSMSChoreo.available()) {
      char c = SendSMSChoreo.read();
      Serial.print(c);
    }
    SendSMSChoreo.close();
  }

  Serial.println("Waiting...");
  delay(10000); // wait 10 seconds between SendSMS calls
  
  Serial.println("Patrol Mode Initiated...");
  
  }//end if statement 
  
}//ends loop

Schematics

Connections
Connections

Comments

Similar projects you might like

GSM Home Alarm V1.0

Project tutorial by Hugo Gomes

  • 28,045 views
  • 13 comments
  • 42 respects

Security Access Using RFID Reader

by Aritro Mukherjee

  • 260,272 views
  • 42 comments
  • 281 respects

Make a Gas Leak Monitor

Project tutorial by Jasper

  • 4,176 views
  • 3 comments
  • 15 respects

Android App-Based Home Automation System Using IOT

Project tutorial by Team Autoshack

  • 24,825 views
  • 17 comments
  • 75 respects

Entry Level Door Monitoring Alarm System

Project tutorial by Team Robodia Technology Solutions

  • 5,282 views
  • 1 comment
  • 16 respects
Add projectSign up / Login