Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Include Software Serial library to communicate with GSM
- #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;
- 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 1 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);
- //đếm số
- 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");
- noInterrupts();
- //nhắn báo số người
- if (SMSRequest()){
- 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
- at("so nguoi:",1000);// The SMS text you want to send
- at(xuat,100);
- SIM900.println((char)26);// ASCII code of CTRL+Z
- Serial.print("2");
- }
- interrupts();
- }
- // put your main code here, to run repeatedly:
- boolean SMSRequest() {
- unsigned long currentMillis1 = millis;
- //chờ tin nhắn tới
- if(SIM900.available() >0) {
- incomingChar=SIM900.read();
- if((incomingChar==1)&&(currentMillis1 - previousMillis3 >= wait)) {
- Serial.print(incomingChar);
- incomingChar=SIM900.read();
- previousMillis3=currentMillis1;
- }
- }
- }
- void at(String _atcm,unsigned long _dl){
- SIM900.print(_atcm+"\r\n");
- delay(_dl);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement