dramaquinn

Untitled

Jul 20th, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.52 KB | None | 0 0
  1. #include <SoftwareSerial.h>
  2.  
  3. // Pin DHT is connected to
  4.  
  5.  
  6. // Configure software serial port
  7. SoftwareSerial SIM900(10,11);
  8.  
  9. // Create variable to store incoming SMS characters
  10. char incomingChar;
  11. String SDT="0901344386";
  12. const int sensor = 52;
  13. int count=0;
  14. int sensorstate=0;
  15. int lastsensorstate=0;
  16. int simstate =0;
  17. char msg;
  18. int xuat;
  19. #include <LCD.h>
  20. #include <LiquidCrystal.h>
  21. #include <LiquidCrystal_I2C.h>
  22. LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4 ,5 ,6, 7, 3, POSITIVE);
  23. unsigned long previousMillis1=0;
  24. unsigned long previousMillis2=0;
  25. unsigned long previousMillis3=0;
  26. unsigned long previousMillis4=0;
  27. unsigned long previousMillis5=0;
  28. unsigned long previousMillis6=0;
  29. unsigned long previousMillis7=0;
  30.  
  31. long interval = 1000;
  32. // interval at which to blink (milliseconds)
  33.  
  34. long wait = 10;
  35. long tgian = 500;
  36. void setup() {
  37.  
  38. Serial.begin(9600);
  39. SIM900.begin(9600);
  40.  
  41. // Give time to your GSM shield log on to network
  42. delay(2000);
  43. Serial.print("SIM900 ready...");
  44.  
  45. // AT command to set SIM900 to SMS mode
  46. SIM900.print("AT+CMGF=1\r");
  47. delay(100);
  48. // Set module to send SMS data to serial out upon receipt
  49. SIM900.print("AT+CNMI=2,2,0,0,0\r");
  50. delay(100);
  51. at("AT",1000);
  52. at("AT+CMGF=1",1000);
  53. at("AT+CSCS=\"GSM\"",1000);
  54. at("AT+CMGS=\"" + SDT+"\"",2000);
  55. at("nhan phim STATE de xem so nguoi rua tay",1000);
  56. SIM900.write(26);
  57. SIM900.print("AT+CMGD=1,4");
  58. SIM900.print("AT+CNMI=2,2,0,0,0\r");
  59. delay(100);// ctlrZ
  60. Serial.begin(9600);
  61. Serial.println("ok");
  62. lcd.begin(16,2);
  63. lcd.backlight();
  64. lcd.setCursor(0,0);
  65.  
  66. lcd.print("so nguoi");
  67.  
  68.  
  69.  
  70. }
  71.  
  72. void loop(){
  73. unsigned long currentMillis = millis();
  74. unsigned long currentMillis1 = millis();
  75.  
  76.  
  77. sensorstate=digitalRead(sensor);
  78. if (sensorstate!=lastsensorstate){
  79. if (sensorstate==HIGH){
  80. count++;
  81. Serial.println("dang chay");
  82. Serial.println(count);
  83. lcd.setCursor(0,1);
  84. lcd.print(count);
  85. if (currentMillis - previousMillis1 >= tgian)
  86. {
  87. Serial.print("1");
  88. int num=count;
  89. }
  90. }
  91. else{
  92. Serial.println("off");
  93. }
  94. }
  95. lastsensorstate=sensorstate;
  96. String xuat =String(count);
  97. SIM900.println("AT+CNMI=2,2,0,0,0");
  98. if (SMSRequest()){
  99. if (currentMillis1 - previousMillis2 >= wait)
  100. {
  101. // REPLACE THE X's WITH THE RECIPIENT'S MOBILE NUMBER
  102. // USE INTERNATIONAL FORMAT CODE FOR MOBILE NUMBERS
  103.  
  104. // REPLACE WITH YOUR OWN SMS MESSAGE CONTENT
  105.  
  106. at("AT",1000);
  107. at("AT+CMGF=1",1000);
  108. at("AT+CSCS=\"GSM\"",1000);
  109. at("AT+CMGS=\"" + SDT+"\"",2000);
  110.  
  111. at("so nguoi rua tay",1000);
  112. SIM900.write((char)26);
  113. SIM900.print("AT+CMGD=1,4");
  114. SIM900.print("AT+CNMI=2,2,0,0,0\r");
  115. previousMillis2 = currentMillis1; // Remember the time
  116. }
  117. }
  118.  
  119.  
  120. delay(10);
  121.  
  122. }
  123.  
  124.  
  125. boolean SMSRequest() {
  126. unsigned long currentMillis2 = millis();
  127. unsigned long currentMillis3 = millis();
  128. unsigned long currentMillis4 = millis();
  129. unsigned long currentMillis5 = millis();
  130. unsigned long currentMillis6 = millis();
  131.  
  132.  
  133.  
  134. if(SIM900.available() >0) {
  135. incomingChar=SIM900.read();
  136. if(incomingChar=='S') {
  137. if (currentMillis2 - previousMillis3 >= wait)
  138. {
  139. previousMillis3 = currentMillis2;
  140. Serial.print(incomingChar);
  141. incomingChar=SIM900.read();
  142. if(incomingChar =='T') {
  143. if (currentMillis3 - previousMillis4 >= wait)
  144. {
  145. Serial.print(incomingChar);
  146. incomingChar=SIM900.read();
  147. previousMillis4 = currentMillis3;
  148.  
  149. if(incomingChar=='A') {
  150. if (currentMillis4 - previousMillis5 >= wait)
  151. {
  152. Serial.print(incomingChar);
  153. incomingChar=SIM900.read();
  154. previousMillis5 = currentMillis4;
  155.  
  156. if(incomingChar=='T') {
  157.  
  158. if (currentMillis5 - previousMillis6 >= wait)
  159. {
  160. Serial.print(incomingChar);
  161. incomingChar=SIM900.read();
  162. previousMillis6 = currentMillis5;
  163.  
  164. if(incomingChar=='E') {
  165. if (currentMillis6 - previousMillis7 >= wait)
  166. {
  167. Serial.print(incomingChar);
  168. Serial.print("...Request Received \n");
  169. return true;
  170. previousMillis7 = currentMillis6;
  171.  
  172. }
  173. }
  174. }
  175. }
  176. }
  177. }
  178. }
  179. }
  180. }
  181. }
  182. }
  183.  
  184. return false;
  185. }
  186. void at(String _atcm,unsigned long _dl){
  187. SIM900.print(_atcm+"\r\n");
  188. delay(_dl);
  189. }
Advertisement
Add Comment
Please, Sign In to add comment