Advertisement
dramaquinn

Untitled

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