Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "SoftwareSerial.h"//tải thư viện softwareserial về
- const int sensor = 52;
- int count=0;
- int sensorstate=0;
- int lastsensorstate=0;
- int simstate =0;
- char msg;
- int xuat;
- #include <LCD.h>
- #include <LiquidCrystal.h>//tải thư viện liquid crystal về
- #include <LiquidCrystal_I2C.h>//tải thư viện liquid crystal i2c về
- LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4 ,5 ,6, 7, 3, POSITIVE);
- SoftwareSerial sim808 (10,11); //Rx Tx
- boolean nhan;
- String SDT="0901344386";
- void setup() {
- // put your setup code here, to run once:
- pinMode (sensor,INPUT);
- sim808.begin(9600);
- // Test call
- at("AT",1000);
- at("ATD"+SDT+";",15000);
- at("ATH",1000);
- //test sms
- at("AT",1000);
- at("AT+CMGF=1",1000);
- at("AT+CSCS=\"GSM\"",1000);
- at("AT+CMGS=\"" + SDT+"\"",2000);
- at("nhan bat ki phim nao de xem so nguoi rua tay",1000);
- sim808.write(26);
- sim808.print("AT+CMGD=1,4");
- sim808.print("AT+CNMI=2,2,0,0,0\r");
- // Deletes all SMS saved in SIM memory
- delay(100);// ctlrZ
- Serial.begin(9600);
- Serial.println("ok");
- lcd.begin(16,2);
- lcd.backlight();
- lcd.setCursor(0,0);
- lcd.print("so nguoi");
- }
- void loop() {
- sensorstate=digitalRead(sensor);
- if (sensorstate!=lastsensorstate){
- if (sensorstate==HIGH){
- count++;
- Serial.println("dang chay");
- Serial.println(count);
- lcd.setCursor(0,1);
- lcd.print(count);
- delay(500);
- Serial.print("1");
- int num=count;
- }
- else{
- Serial.println("off");
- }
- }
- lastsensorstate=sensorstate;
- String xuat =String(count);
- sim808.println("AT+CNMI=2,2,0,0,0");
- noInterrupts();
- if (sim808.available()>0)
- {
- Serial.write(sim808.read());
- at("AT",1000);
- at("AT+CMGF=1",1000); //Sets the GSM Module in Text Mode // Delay of 1000 milli seconds or 1 second
- at("AT+CSCS=\"GSM\"",1000);
- at("AT+CMGS=\"" + SDT+"\"",2000); // Replace x with mobile number
- delay(100);
- at("so nguoi:",1000);// The SMS text you want to send
- at(xuat,100);
- sim808.println((char)26);// ASCII code of CTRL+Z
- delay(1000);
- Serial.print("2");
- }
- interrupts();
- // put your main code here, to run repeatedly:
- }
- void at(String _atcm,unsigned long _dl){
- sim808.print(_atcm+"\r\n");
- delay(_dl);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement