Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // http://www.ebay.com/itm/SIMCOM-SIM900-Quad-band-GSM-GPRS-Shield-Development-Board-for-Arduino-Iduino-/200953716109 $30
- // http://www.ebay.com/itm/2012-Version-Board-ATmega328P-UNO-R3-ATmega16U2-Free-USB-Cable-for-Arduino-/331036182607 $13.50
- #include <SoftwareSerial.h>
- #include <String.h>
- SoftwareSerial mySerial(7, 8);
- const int buttonPin = 2;
- int buttonState = 0;
- int buttonPrevState = 0;
- const int ledPin = 13;
- void setup()
- {
- powerUpOrDown();
- pinMode(buttonPin, INPUT); // software powerUp so we dont have to press the button to turn on shield
- mySerial.begin(19200); // the GPRS baud rate
- Serial.begin(19200); // the GPRS baud rate
- delay(500);
- }
- void loop()
- {
- buttonState = digitalRead(buttonPin);
- if ((buttonState == HIGH) && (buttonPrevState == LOW))
- {
- SendTextMessage(); // send sms
- digitalWrite(ledPin, LOW); // turn LED on:
- }
- else {digitalWrite(ledPin, HIGH);
- }
- buttonPrevState = buttonState;
- delay(100);
- }
- void SendTextMessage()
- {
- mySerial.print("AT+CMGF=1\r"); //Because we want to send the SMS in text mode
- delay(100);
- mySerial.println("AT + CMGS = \"+1XXXXXXXXXX\""); //send sms message, be careful need to add a country code before the cellphone number
- delay(100);
- mySerial.println("You're getting robbed!"); //the content of the message
- delay(100);
- mySerial.println((char)26); //the ASCII code of the ctrl+z is 26
- delay(100);
- mySerial.println();
- }
- void powerUpOrDown()
- {
- pinMode(9, OUTPUT);
- digitalWrite(9,LOW);
- delay(1000);
- digitalWrite(9,HIGH);
- delay(2000);
- digitalWrite(9,LOW);
- delay(3000);
- }
- void ShowSerialData()
- {
- while(mySerial.available()!=0)
- Serial.write(mySerial.read());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement