Advertisement
illwill

Robbed.ino

Feb 18th, 2014
453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.81 KB | None | 0 0
  1. // http://www.ebay.com/itm/SIMCOM-SIM900-Quad-band-GSM-GPRS-Shield-Development-Board-for-Arduino-Iduino-/200953716109 $30
  2. // http://www.ebay.com/itm/2012-Version-Board-ATmega328P-UNO-R3-ATmega16U2-Free-USB-Cable-for-Arduino-/331036182607   $13.50
  3.  
  4. #include <SoftwareSerial.h>
  5. #include <String.h>
  6.  
  7. SoftwareSerial mySerial(7, 8);
  8. const int buttonPin = 2;
  9. int buttonState = 0;
  10. int buttonPrevState = 0;
  11. const int ledPin =  13;
  12.  
  13. void setup()
  14. {
  15.   powerUpOrDown();
  16.   pinMode(buttonPin, INPUT);   // software powerUp so we dont have to press the button to turn on shield
  17.   mySerial.begin(19200);      // the GPRS baud rate  
  18.   Serial.begin(19200);       // the GPRS baud rate
  19.   delay(500);
  20. }
  21.  
  22. void loop()
  23. {
  24.    buttonState = digitalRead(buttonPin);
  25.    if ((buttonState == HIGH) && (buttonPrevState == LOW))
  26.    {        
  27.      SendTextMessage();            // send sms
  28.      digitalWrite(ledPin, LOW);   // turn LED on:
  29.    }
  30.      else {digitalWrite(ledPin, HIGH);
  31.    }
  32.    buttonPrevState = buttonState;  
  33.    delay(100);
  34. }
  35.  
  36. void SendTextMessage()
  37. {
  38.   mySerial.print("AT+CMGF=1\r");                     //Because we want to send the SMS in text mode
  39.   delay(100);
  40.   mySerial.println("AT + CMGS = \"+1XXXXXXXXXX\""); //send sms message, be careful need to add a country code before the cellphone number
  41.   delay(100);
  42.   mySerial.println("You're getting robbed!");      //the content of the message
  43.   delay(100);
  44.   mySerial.println((char)26);                     //the ASCII code of the ctrl+z is 26
  45.   delay(100);
  46.   mySerial.println();
  47. }
  48.  
  49. void powerUpOrDown()
  50. {
  51.   pinMode(9, OUTPUT);
  52.   digitalWrite(9,LOW);
  53.   delay(1000);
  54.   digitalWrite(9,HIGH);
  55.   delay(2000);
  56.   digitalWrite(9,LOW);
  57.   delay(3000);
  58. }
  59.  
  60. void ShowSerialData()
  61. {
  62.   while(mySerial.available()!=0)
  63.     Serial.write(mySerial.read());
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement