Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SoftwareSerial.h>
- // Pin DHT is connected to
- // Configure software serial port
- SoftwareSerial SIM900(10,11);
- // Create variable to store incoming SMS characters
- char incomingChar;
- String SDT="0901344386";
- 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>
- #include <LiquidCrystal_I2C.h>
- LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4 ,5 ,6, 7, 3, POSITIVE);
- unsigned long previousMillis1=0;
- unsigned long previousMillis2=0;
- unsigned long previousMillis3=0;
- unsigned long previousMillis4=0;
- unsigned long previousMillis5=0;
- unsigned long previousMillis6=0;
- unsigned long previousMillis7=0;
- long interval = 1000;
- // interval at which to blink (milliseconds)
- long wait = 10;
- long tgian = 500;
- void setup() {
- Serial.begin(9600);
- SIM900.begin(9600);
- // Give time to your GSM shield log on to network
- delay(2000);
- Serial.print("SIM900 ready...");
- // AT command to set SIM900 to SMS mode
- SIM900.print("AT+CMGF=1\r");
- delay(100);
- // Set module to send SMS data to serial out upon receipt
- SIM900.print("AT+CNMI=2,2,0,0,0\r");
- delay(100);
- at("AT",1000);
- at("AT+CMGF=1",1000);
- at("AT+CSCS=\"GSM\"",1000);
- at("AT+CMGS=\"" + SDT+"\"",2000);
- at("nhan phim STATE de xem so nguoi rua tay",1000);
- SIM900.write(26);
- SIM900.print("AT+CMGD=1,4");
- SIM900.print("AT+CNMI=2,2,0,0,0\r");
- 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(){
- unsigned long currentMillis = millis();
- unsigned long currentMillis1 = millis();
- sensorstate=digitalRead(sensor);
- if (sensorstate!=lastsensorstate){
- if (sensorstate==HIGH){
- count++;
- Serial.println("dang chay");
- Serial.println(count);
- lcd.setCursor(0,1);
- lcd.print(count);
- if (currentMillis - previousMillis1 >= tgian)
- {
- Serial.print("1");
- int num=count;
- }
- }
- else{
- Serial.println("off");
- }
- }
- lastsensorstate=sensorstate;
- String xuat =String(count);
- SIM900.println("AT+CNMI=2,2,0,0,0");
- if (SMSRequest()){
- if (currentMillis1 - previousMillis2 >= wait)
- {
- // REPLACE THE X's WITH THE RECIPIENT'S MOBILE NUMBER
- // USE INTERNATIONAL FORMAT CODE FOR MOBILE NUMBERS
- // REPLACE WITH YOUR OWN SMS MESSAGE CONTENT
- at("AT",1000);
- at("AT+CMGF=1",1000);
- at("AT+CSCS=\"GSM\"",1000);
- at("AT+CMGS=\"" + SDT+"\"",2000);
- at("so nguoi rua tay",1000);
- SIM900.write((char)26);
- SIM900.print("AT+CMGD=1,4");
- SIM900.print("AT+CNMI=2,2,0,0,0\r");
- previousMillis2 = currentMillis1; // Remember the time
- }
- }
- delay(10);
- }
- boolean SMSRequest() {
- unsigned long currentMillis2 = millis();
- unsigned long currentMillis3 = millis();
- unsigned long currentMillis4 = millis();
- unsigned long currentMillis5 = millis();
- unsigned long currentMillis6 = millis();
- if(SIM900.available() >0) {
- incomingChar=SIM900.read();
- if(incomingChar=='S') {
- if (currentMillis2 - previousMillis3 >= wait)
- {
- previousMillis3 = currentMillis2;
- Serial.print(incomingChar);
- incomingChar=SIM900.read();
- if(incomingChar =='T') {
- if (currentMillis3 - previousMillis4 >= wait)
- {
- Serial.print(incomingChar);
- incomingChar=SIM900.read();
- previousMillis4 = currentMillis3;
- if(incomingChar=='A') {
- if (currentMillis4 - previousMillis5 >= wait)
- {
- Serial.print(incomingChar);
- incomingChar=SIM900.read();
- previousMillis5 = currentMillis4;
- if(incomingChar=='T') {
- if (currentMillis5 - previousMillis6 >= wait)
- {
- Serial.print(incomingChar);
- incomingChar=SIM900.read();
- previousMillis6 = currentMillis5;
- if(incomingChar=='E') {
- if (currentMillis6 - previousMillis7 >= wait)
- {
- Serial.print(incomingChar);
- Serial.print("...Request Received \n");
- return true;
- previousMillis7 = currentMillis6;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- return false;
- }
- void at(String _atcm,unsigned long _dl){
- SIM900.print(_atcm+"\r\n");
- delay(_dl);
- }
Advertisement
Add Comment
Please, Sign In to add comment