Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- -Cody Singer-
- -9/2012-
- ---(NWRA ALARM AUTODIALER 2012 V1.3)---
- --When the alarm is triggered it closes a relay that connects LOW (-) to pin 4.
- - this calls for the function DialVoiceCall(); to dial out to a phone number.
- --Other feature is when an authorized number dials the device and lets it ring (3) set by "comring" times it will trigger the function KillFog() triggering a relay to OPEN which
- -will disable the fog system of the alarm system. This funtion also triggers the function SendTextMessageFogDisarm() that sends a confirmation SMS to cody.
- --Test switch is to test the system witout disturbing dan. When the switch is activated it triggers TestDevice() function that sets
- --the "ledPin" to HIGH and LOW (blink) then sends a text message to cody.
- */
- #include <SoftwareSerial.h>
- #include <String.h>
- //software serial port for the GSM sheild to communicate with the Arduino
- SoftwareSerial mySerial(7, 8);
- char dan[]="AT + CMGS = \"+15092706606\"";
- char cody[]="AT + CMGS = \"+15098501985\"";
- //Trigger pin from the relay of the alarm
- int triggerPin = 4;
- //Pin that activates the relay opening the fog circuit
- int fogkillPin = 10;
- //Testpin is a switch that when activated sends a SMS to cody to ensure the device is communicating
- int testPin = 11;
- //Pin for the LED for visual reference of activation of the fogKill function, also activates with the TestDevice() function
- int ledPin = 13;
- char inchar;
- // used to count the number of 'rings' received by the GSM module
- int numring=0;
- // this is the number of rings to wait for until calling the function doSomething();
- int comring=3;
- //Tracking variable to tell if the pin is (+) or (-)
- int val;
- int test;
- //store mySerial.read info
- char c = 0;
- //store sms strings for if statements
- String line = "";
- void setup() {
- //The GPRS baud rate
- mySerial.begin(19200);
- //The GPRS baud rate
- Serial.begin(19200);
- delay(500);
- //Set the trigger pin as input
- pinMode(triggerPin, INPUT);
- //Set the fogkillPin as output
- pinMode(fogkillPin, OUTPUT);
- //set the testPin as input
- pinMode(testPin, INPUT);
- //set ledPin as output
- pinMode(ledPin, OUTPUT);
- //Internal pull up resistor to keep TriggerPin and testPin (+) until it receives a (-) signal from the alarm
- digitalWrite(triggerPin, HIGH);
- digitalWrite(testPin, HIGH);
- Serial.print("Welcome to DIY alarm trigger by Cody Singer");
- }
- void loop() {
- //Set Val variable (TriggerPin)
- val = digitalRead(triggerPin);
- delay(100);
- if (val == LOW) {
- Serial.print("Alarm triggered");
- DialVoiceCall();
- delay(100);
- }
- //Set test to variable (testPin)
- test = digitalRead(testPin);
- delay(100);
- if (test == LOW) {
- Serial.print("TEST");
- TestDevice();
- }
- else {
- if (mySerial.available() > 0) { //read incoming data from GSM module
- c = mySerial.read();
- while ((c != '\n') && (c != '\r')) { //look for new lines from SIM900
- line = line + c; //write incoming sms data to "line"
- c = mySerial.read();
- }
- if ((line == "RING")) {
- line = ""; //clear "line"
- delay(10);
- numring++;
- if (numring==comring)
- {
- numring=0; // reset ring counter
- Serial.print("RING received 3 times");
- mySerial.println("ATH");
- KillFog();
- }
- }
- }
- }
- }
- //Send SMS function
- void SendTextMessage(who, what)
- {
- //Send the SMS in text mode
- mySerial.print("AT+CMGF=1\r");
- delay(100);
- mySerial.println(who);
- delay(100);
- mySerial.println(what);
- delay(100);
- //The ASCII code of the ctrl+z is 26
- mySerial.println((char)26);
- delay(100);
- mySerial.println();
- }
- //DialVoiceCall
- void DialVoiceCall()
- {
- //Dial the number
- mySerial.println(cody);
- delay(100);
- mySerial.println();
- delay(20000);
- }
- void TestDevice()
- {
- digitalWrite(ledPin, HIGH);
- delay(500);
- digitalWrite(ledPin, LOW);
- delay(500);
- }
- void KillFog()
- {
- digitalWrite(fogkillPin, HIGH);
- delay(500);
- digitalWrite(ledPin, HIGH);
- //SendTextMessage(cody,"FOG DISARMED!!!");
- }
- void LedBlink()
- {
- digitalWrite(ledPin, HIGH);
- delay(500);
- digitalWrite(ledPin, LOW);
- delay(500);
- digitalWrite(ledPin, HIGH);
- delay(500);
- digitalWrite(ledPin, LOW);
- delay(500);
- digitalWrite(ledPin, HIGH);
- delay(500);
- digitalWrite(ledPin, LOW);
- delay(500);
- }
Add Comment
Please, Sign In to add comment