Guest User

Untitled

a guest
Dec 14th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.56 KB | None | 0 0
  1. /*
  2.  
  3. -Cody Singer-
  4. -9/2012-
  5.  
  6. ---(NWRA ALARM AUTODIALER 2012 V1.3)---
  7.  
  8. --When the alarm is triggered it closes a relay that connects LOW (-) to pin 4.
  9. - this calls for the function DialVoiceCall(); to dial out to a phone number.
  10.  
  11. --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
  12. -will disable the fog system of the alarm system. This funtion also triggers the function SendTextMessageFogDisarm() that sends a confirmation SMS to cody.
  13.  
  14. --Test switch is to test the system witout disturbing dan. When the switch is activated it triggers TestDevice() function that sets
  15. --the "ledPin" to HIGH and LOW (blink) then sends a text message to cody.
  16. */
  17.  
  18. #include <SoftwareSerial.h>
  19. #include <String.h>
  20.  
  21. //software serial port for the GSM sheild to communicate with the Arduino
  22. SoftwareSerial mySerial(7, 8);
  23.  
  24. char dan[]="AT + CMGS = \"+15092706606\"";
  25. char cody[]="AT + CMGS = \"+15098501985\"";
  26.  
  27. //Trigger pin from the relay of the alarm
  28. int triggerPin = 4;
  29. //Pin that activates the relay opening the fog circuit
  30. int fogkillPin = 10;
  31. //Testpin is a switch that when activated sends a SMS to cody to ensure the device is communicating
  32. int testPin = 11;
  33. //Pin for the LED for visual reference of activation of the fogKill function, also activates with the TestDevice() function
  34. int ledPin = 13;
  35.  
  36.  
  37. char inchar;
  38.  
  39.  
  40. // used to count the number of 'rings' received by the GSM module
  41. int numring=0;
  42. // this is the number of rings to wait for until calling the function doSomething();
  43. int comring=3;
  44.  
  45. //Tracking variable to tell if the pin is (+) or (-)
  46. int val;
  47. int test;
  48. //store mySerial.read info
  49. char c = 0;
  50. //store sms strings for if statements
  51. String line = "";
  52.  
  53. void setup() {
  54.  
  55. //The GPRS baud rate
  56. mySerial.begin(19200);
  57. //The GPRS baud rate
  58. Serial.begin(19200);
  59. delay(500);
  60.  
  61.  
  62. //Set the trigger pin as input
  63. pinMode(triggerPin, INPUT);
  64. //Set the fogkillPin as output
  65. pinMode(fogkillPin, OUTPUT);
  66. //set the testPin as input
  67. pinMode(testPin, INPUT);
  68. //set ledPin as output
  69. pinMode(ledPin, OUTPUT);
  70.  
  71.  
  72. //Internal pull up resistor to keep TriggerPin and testPin (+) until it receives a (-) signal from the alarm
  73. digitalWrite(triggerPin, HIGH);
  74. digitalWrite(testPin, HIGH);
  75.  
  76. Serial.print("Welcome to DIY alarm trigger by Cody Singer");
  77. }
  78.  
  79. void loop() {
  80.  
  81. //Set Val variable (TriggerPin)
  82. val = digitalRead(triggerPin);
  83. delay(100);
  84. if (val == LOW) {
  85. Serial.print("Alarm triggered");
  86. DialVoiceCall();
  87. delay(100);
  88. }
  89.  
  90. //Set test to variable (testPin)
  91. test = digitalRead(testPin);
  92. delay(100);
  93. if (test == LOW) {
  94. Serial.print("TEST");
  95. TestDevice();
  96. }
  97.  
  98. else {
  99.  
  100. if (mySerial.available() > 0) { //read incoming data from GSM module
  101. c = mySerial.read();
  102. while ((c != '\n') && (c != '\r')) { //look for new lines from SIM900
  103. line = line + c; //write incoming sms data to "line"
  104. c = mySerial.read();
  105. }
  106.  
  107. if ((line == "RING")) {
  108. line = ""; //clear "line"
  109. delay(10);
  110. numring++;
  111. if (numring==comring)
  112. {
  113. numring=0; // reset ring counter
  114. Serial.print("RING received 3 times");
  115. mySerial.println("ATH");
  116. KillFog();
  117. }
  118. }
  119. }
  120. }
  121. }
  122.  
  123. //Send SMS function
  124. void SendTextMessage(who, what)
  125. {
  126. //Send the SMS in text mode
  127. mySerial.print("AT+CMGF=1\r");
  128. delay(100);
  129. mySerial.println(who);
  130. delay(100);
  131. mySerial.println(what);
  132. delay(100);
  133. //The ASCII code of the ctrl+z is 26
  134. mySerial.println((char)26);
  135. delay(100);
  136. mySerial.println();
  137. }
  138.  
  139.  
  140.  
  141. //DialVoiceCall
  142. void DialVoiceCall()
  143. {
  144. //Dial the number
  145. mySerial.println(cody);
  146. delay(100);
  147. mySerial.println();
  148. delay(20000);
  149.  
  150. }
  151.  
  152. void TestDevice()
  153. {
  154. digitalWrite(ledPin, HIGH);
  155. delay(500);
  156. digitalWrite(ledPin, LOW);
  157. delay(500);
  158.  
  159. }
  160.  
  161. void KillFog()
  162. {
  163. digitalWrite(fogkillPin, HIGH);
  164. delay(500);
  165. digitalWrite(ledPin, HIGH);
  166. //SendTextMessage(cody,"FOG DISARMED!!!");
  167. }
  168.  
  169. void LedBlink()
  170. {
  171. digitalWrite(ledPin, HIGH);
  172. delay(500);
  173. digitalWrite(ledPin, LOW);
  174. delay(500);
  175. digitalWrite(ledPin, HIGH);
  176. delay(500);
  177. digitalWrite(ledPin, LOW);
  178. delay(500);
  179. digitalWrite(ledPin, HIGH);
  180. delay(500);
  181. digitalWrite(ledPin, LOW);
  182. delay(500);
  183. }
Add Comment
Please, Sign In to add comment