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.

  • 65 respects

Components and supplies

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

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 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

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:

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

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:

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!



#include <SoftwareSerial.h>

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

void setup() {

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

void loop()

  digitalWrite(trigPin, LOW);
  digitalWrite(trigPin, HIGH);
  digitalWrite(trigPin, LOW);

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

  inches = (duration / 2) / 74;
  if (inches < 20 || inches > 1000) {
  Serial.println("Intruder Detected!");
  Serial.println("Sending text Notification...");
  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() {
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  // For debugging, wait until the serial console is connected
  Serial.println("Patrol Mode Initiated...");

void loop() {

  digitalWrite(trigPin, LOW);
  digitalWrite(trigPin, HIGH);
  digitalWrite(trigPin, LOW);

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

  inches = (duration / 2) / 74;
  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

    // Set Temboo account credentials
    // 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
    // Run the Choreo; when results are available, print them to serial;
    while(SendSMSChoreo.available()) {
      char c =;

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




Similar projects you might like

GSM Home Alarm V1.0

Project tutorial by Hugo Gomes

  • 61 respects

Security Access Using RFID Reader

by Aritro Mukherjee

  • 499 respects

Arduino and AC Devices - Automatic Lights

Project tutorial by Ahmed Hamdy Mahmoud Hassanein

  • 74 respects

Ultrasonic Map-Maker using an Arduino Yun

Project tutorial by Satyavrat Wagle

  • 195 respects

Arduino Dynamic Web Control

Project tutorial by phpoc_man

  • 180 respects

Cheap DIY LASER ALARM - Multi Functional!

Project tutorial by Danny van den Brande

  • 13 respects
Add projectSign up / Login