Advertisement
dramaquinn

Untitled

May 27th, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. #include "SoftwareSerial.h"//tải thư viện softwareserial về
  2.  
  3.  
  4. const int sensor = 52;
  5. int count=0;
  6. int sensorstate=0;
  7. int lastsensorstate=0;
  8. int simstate =0;
  9. char msg;
  10. int xuat;
  11. #include <LCD.h>
  12. #include <LiquidCrystal.h>//tải thư viện liquid crystal về
  13. #include <LiquidCrystal_I2C.h>//tải thư viện liquid crystal i2c về
  14. LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4 ,5 ,6, 7, 3, POSITIVE);
  15.  
  16.  
  17. SoftwareSerial sim808 (10,11); //Rx Tx
  18. boolean nhan;
  19. String SDT="0901344386";
  20.  
  21. void setup() {
  22. // put your setup code here, to run once:
  23. pinMode (sensor,INPUT);
  24. sim808.begin(9600);
  25. // Test call
  26. at("AT",1000);
  27. at("ATD"+SDT+";",15000);
  28. at("ATH",1000);
  29.  
  30. //test sms
  31. at("AT",1000);
  32. at("AT+CMGF=1",1000);
  33. at("AT+CSCS=\"GSM\"",1000);
  34. at("AT+CMGS=\"" + SDT+"\"",2000);
  35.  
  36. at("nhan bat ki phim nao de xem so nguoi rua tay",1000);
  37. sim808.write(26);
  38. sim808.print("AT+CMGD=1,4");
  39. sim808.print("AT+CNMI=2,2,0,0,0\r");
  40.  
  41. // Deletes all SMS saved in SIM memory
  42. delay(100);// ctlrZ
  43. Serial.begin(9600);
  44. Serial.println("ok");
  45. lcd.begin(16,2);
  46. lcd.backlight();
  47. lcd.setCursor(0,0);
  48.  
  49. lcd.print("so nguoi");
  50. }
  51.  
  52. void loop() {
  53. sensorstate=digitalRead(sensor);
  54. if (sensorstate!=lastsensorstate){
  55. if (sensorstate==HIGH){
  56. count++;
  57. Serial.println("dang chay");
  58. Serial.println(count);
  59. lcd.setCursor(0,1);
  60. lcd.print(count);
  61. delay(500);
  62. Serial.print("1");
  63. int num=count;
  64. }
  65. else{
  66. Serial.println("off");
  67. }
  68. }
  69. lastsensorstate=sensorstate;
  70. String xuat =String(count);
  71. sim808.println("AT+CNMI=2,2,0,0,0");
  72. noInterrupts();
  73. if (sim808.available()>0)
  74. {
  75.  
  76. Serial.write(sim808.read());
  77. at("AT",1000);
  78. at("AT+CMGF=1",1000); //Sets the GSM Module in Text Mode // Delay of 1000 milli seconds or 1 second
  79.  
  80. at("AT+CSCS=\"GSM\"",1000);
  81. at("AT+CMGS=\"" + SDT+"\"",2000); // Replace x with mobile number
  82. delay(100);
  83. at("so nguoi:",1000);// The SMS text you want to send
  84. at(xuat,100);
  85. sim808.println((char)26);// ASCII code of CTRL+Z
  86. delay(1000);
  87.  
  88. Serial.print("2");
  89.  
  90. }
  91. interrupts();
  92. // put your main code here, to run repeatedly:
  93.  
  94. }
  95. void at(String _atcm,unsigned long _dl){
  96. sim808.print(_atcm+"\r\n");
  97. delay(_dl);
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement