Advertisement
dramaquinn

Untitled

Jul 21st, 2020
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. //Include Software Serial library to communicate with GSM
  2. #include <SoftwareSerial.h>
  3.  
  4. // Pin DHT is connected to
  5.  
  6.  
  7. // Configure software serial port
  8. SoftwareSerial SIM900(10,11);
  9.  
  10. // Create variable to store incoming SMS characters
  11. char incomingChar;
  12. String SDT="0901344386";
  13. const int sensor = 52;
  14. int count=0;
  15. int sensorstate=0;
  16. int lastsensorstate=0;
  17. int simstate =0;
  18. char msg;
  19. int xuat;
  20. #include <LCD.h>
  21. #include <LiquidCrystal.h>
  22. #include <LiquidCrystal_I2C.h>
  23. LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4 ,5 ,6, 7, 3, POSITIVE);
  24. unsigned long previousMillis1=0;
  25. unsigned long previousMillis2=0;
  26. unsigned long previousMillis3=0;
  27. long interval = 1000;
  28. // interval at which to blink (milliseconds)
  29.  
  30. long wait = 10;
  31. long tgian = 500;
  32. void setup() {
  33.  
  34. Serial.begin(9600);
  35. SIM900.begin(9600);
  36.  
  37. // Give time to your GSM shield log on to network
  38. delay(2000);
  39. Serial.print("SIM900 ready...");
  40.  
  41. // AT command to set SIM900 to SMS mode
  42. SIM900.print("AT+CMGF=1\r");
  43. delay(100);
  44. // Set module to send SMS data to serial out upon receipt
  45. SIM900.print("AT+CNMI=2,2,0,0,0\r");
  46. delay(100);
  47. at("AT",1000);
  48. at("AT+CMGF=1",1000);
  49. at("AT+CSCS=\"GSM\"",1000);
  50. at("AT+CMGS=\"" + SDT+"\"",2000);
  51. at("nhan phim 1 de xem so nguoi rua tay",1000);
  52. SIM900.write(26);
  53. SIM900.print("AT+CMGD=1,4");
  54. SIM900.print("AT+CNMI=2,2,0,0,0\r");
  55. delay(100);// ctlrZ
  56. Serial.begin(9600);
  57. Serial.println("ok");
  58. lcd.begin(16,2);
  59. lcd.backlight();
  60. lcd.setCursor(0,0);
  61.  
  62. lcd.print("so nguoi");
  63.  
  64.  
  65. }
  66.  
  67. void loop(){
  68. unsigned long currentMillis = millis();
  69. unsigned long currentMillis1 = millis();
  70.  
  71.  
  72. sensorstate=digitalRead(sensor);
  73. //đếm số
  74. if (sensorstate!=lastsensorstate){
  75. if (sensorstate==HIGH){
  76. count++;
  77. Serial.println("dang chay");
  78. Serial.println(count);
  79. lcd.setCursor(0,1);
  80. lcd.print(count);
  81. if (currentMillis - previousMillis1 >= tgian)
  82. {
  83. Serial.print("1");
  84. int num=count;
  85. }
  86. }
  87. else{
  88. Serial.println("off");
  89. }
  90. }
  91. lastsensorstate=sensorstate;
  92. String xuat =String(count);
  93. SIM900.println("AT+CNMI=2,2,0,0,0");
  94. noInterrupts();
  95. //nhắn báo số người
  96. if (SMSRequest()){
  97.  
  98.  
  99.  
  100. at("AT",1000);
  101. at("AT+CMGF=1",1000); //Sets the GSM Module in Text Mode // Delay of 1000 milli seconds or 1 second
  102.  
  103. at("AT+CSCS=\"GSM\"",1000);
  104. at("AT+CMGS=\"" + SDT+"\"",2000); // Replace x with mobile number
  105. at("so nguoi:",1000);// The SMS text you want to send
  106. at(xuat,100);
  107. SIM900.println((char)26);// ASCII code of CTRL+Z
  108.  
  109. Serial.print("2");
  110.  
  111. }
  112. interrupts();
  113.  
  114. }
  115.  
  116. // put your main code here, to run repeatedly:
  117.  
  118.  
  119. boolean SMSRequest() {
  120. unsigned long currentMillis1 = millis;
  121. //chờ tin nhắn tới
  122. if(SIM900.available() >0) {
  123. incomingChar=SIM900.read();
  124. if((incomingChar==1)&&(currentMillis1 - previousMillis3 >= wait)) {
  125.  
  126. Serial.print(incomingChar);
  127. incomingChar=SIM900.read();
  128. previousMillis3=currentMillis1;
  129. }
  130. }
  131. }
  132. void at(String _atcm,unsigned long _dl){
  133. SIM900.print(_atcm+"\r\n");
  134. delay(_dl);
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement