Project on sending sms

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)
}

What threshold?

Which Arduino ?

Which code ?

For you, code is easier to read if you indent consistently, or use the IDE's auto-format tool.

For us, code is easier to read if you use code tags.

(20ms is an awfully long trigger pulse for an ultrasound ranger)

Thanks and What do suggest?

  1. Go to the top of the forum and read the posts about how to post a question
  2. Answer the questions that people have been asking you.

The way you have it coded resultCM must equal 4, 11, or 18 exactly in order to trigger an SMS message. This doesn't sound reasonable to me if you are measuring fuel level with an ultrasonic sensor (assumption I make from your code and print statements). More details on your application might help. All we can do is guess.

Threshold of 4,11 and 18 being full, half and low

I want the system to measure the fuel threshold when it's full, half or low and send sms.

We need a more detailed report of how it behaves. I can tell you at least, that code like this:

if (resultCM ==4){
counter2=0;
counter3=0;
counter1=counter1+1;
if (counter1==1){

is difficult to analyze, and so needs inline comments so the reader can understand.

It seems like you are using three counters as some kind of bizarre debounce or change of state detection system. I think the unnecessary complexity of that system is hiding the main issue (which was already mentioned above), which is that you are detecting the thresholds themselves, rather than a condition of exceeding a threshold which is the normal way to treat a threshold.

Exceeding a threshold is detected with greater than, less than like:

if (resultCM < 4){

There are several ways of implementing a change of state detection system, that are waaaaayyyyy simpler than what you made. The basic logic is;

if (the new measurement is not the same as a saved measurement)
  {
  save the new measurement to the saved measurement
  respond to the change
  }

This can easily be adapted to consider inequality like < and >.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.