Hi am working on a project which will send sms to my mobile phone when the threshold is met but sometime the sms come before the threshold. am using sim800l module.
below are my code
#include <SoftwareSerial.h>
SoftwareSerial sim800l(12, 11); // RX,TX for Arduino and for the module it's TXD RXD, they should be invertedM800L Tx & Rx is connected to Arduino #8 & #9
const int total_height = 25; // Tank height in MM
const int hold_height = 19;// Fuel hold height in MM
const int transmitter =2;//TRIG
const int reciever =3; //Echo
//const int buzzer = 8; //buzzer to arduino pin 8
long Time;
int distanceCM;
int resultCM;
int tnk_lvl = 0;
int sensr_to_fuel = 0;
int counter1=0;
int counter2=0;
int counter3=0;
void setup(){
Serial.begin(9600);//Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
sim800l.begin(9600); //Module baude rate, this is on max, it depends on the version
pinMode(reciever, INPUT);
pinMode(transmitter, OUTPUT);
}
void loop()
{
measure();
delay(50);
if (resultCM ==4){
counter2=0;
counter3=0;
counter1=counter1+1;
if (counter1==1){
//tone(buzzer, 200); //set 200Hz sound signal
//delay(1000);
//noTone(buzzer); // for 1 sec
full();
}
}
if (resultCM ==11){
counter1=0;
counter3=0;
counter2=counter2+1;
if (counter2==1){
// tone(buzzer, 300); //set 300Hz sound signal
//delay(1000);
//noTone(buzzer); // for 1 sec
half();
}
}
if (resultCM==18){
counter2=0;
counter1=0;
counter3=counter3+1;
if (counter3==1){
//tone(buzzer, 600); //set 2KHz sound signal
//delay(1000);
//noTone(buzzer); // for 1 sec
low();
}
}
}
void measure(){
digitalWrite(transmitter, LOW);
delay(2);
digitalWrite(transmitter, HIGH);
delay(20);
digitalWrite(transmitter, LOW);
Time = pulseIn(reciever, HIGH);
distanceCM = Time * 0.034;
resultCM = distanceCM / 2;
Serial.print("Fuel Level Distance = CM");
Serial.println(resultCM);
}
void full(){
delay(1000);
sim800l.print("AT+CMGF=1\r"); //Set the module to SMS mode
delay(1000);
sim800l.print("AT+CMGS="0244862281"\r"); //Phone number to receive SMS
delay(1000);
sim800l.print("Fuel Level is Full"); //This is the text to send to the phone number.
delay(1000);
sim800l.print((char)26);// (required according to the datasheet)
}
void half(){
delay(1000);
sim800l.print("AT+CMGF=1\r"); //Set the module to SMS mode
delay(1000);
sim800l.print("AT+CMGS="0244862281"\r"); //Phone number to receive SMS
delay(1000);
sim800l.print("You have half tank of fuel"); //This is the text to send to the phone number.
delay(1000);
sim800l.print((char)26);// (required according to the datasheet)
}
void low(){
delay(1000);
sim800l.print("AT+CMGF=1\r"); //Set the module to SMS mode
delay(1000);
sim800l.print("AT+CMGS="0244862281"\r"); // Phone number to receive SMS
delay(1000);
sim800l.print("Your fuel is running low, make plans for fuel"); //This is the text to send to the phone number.
delay(1000);
sim800l.print((char)26);// (required according to the datasheet)
}