Arduino Intruder Alarm with Text Alert SMS

This tutorial shows you how to create an intruder alarm that sends you text message alerts. The HC-SR04 range sensor communicates the alert via wifi and goes through Temboo to access your Twilio account in order to send the text message. So you can leave the intruder detector at home, connected to your network, and still recieve the sms alerts, no matter where you are, as long as you have cell phone service.




//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 > 500) {
  Serial.println("Intruder Detected!");
  Serial.println("Sending text Notification...");
  delay(5000);
  Serial.println("Patrol Mode Initiated...");
  }//end if statement




}//ends loop



//WORKING TEXT CODE

#include <Bridge.h>
#include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information
#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(".....");
  if (inches < 20 || inches > 500) {
  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", "*******************************"); //  AUTH TOKEN 
    SendSMSChoreo.addInput("To", "+1**********"); // cell number that your want the text to go to 
    SendSMSChoreo.addInput("From", "+1**********"); // Twilio phone number 
    SendSMSChoreo.addInput("Body", "Intruder Detected!!!!!!"); // Message
    SendSMSChoreo.addInput("AccountSID", "*********************************"); // Account SID
    
    // 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



//Header File
//Save as TembooAccount.h

/*
IMPORTANT NOTE about TembooAccount.h

TembooAccount.h contains your Temboo account information and must be included
alongside your sketch. To do so, make a new tab in Arduino, call it TembooAccount.h,
and copy this content into it. 
*/

#define TEMBOO_ACCOUNT "*******"  // Your Temboo account name 
#define TEMBOO_APP_KEY_NAME "********"  // Your Temboo app key name
#define TEMBOO_APP_KEY "****************************"  // Your Temboo app key

/* 
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.  
Keeping your account information in a separate file means you can share the 
main .ino file without worrying that you forgot to delete your credentials.
*/

Parts

Hey !!!

about us (me).

My name is Matthew, I am 26, and I attend the University of Pittsurgh. Currently I am a junior, going for a bachelors in Information Science. I am always looking for someone that would like to embark on a new project or startup. I work as a food server when I am not at school, but would love something a little more technical, if anyone is hiring.

  • Pittsburgh, PA
  • MatthewHallberg@gmail.com

Drop us a line