Sending SMS only once on condition detected using Arduino and SIM80L

sim800l

#1

Hello And Good Morning
i Need to ask About im Connecting GSM Module SIM800L and i Already write Code to Manage Temperature And i write on code if condition that will Make GSM Module Send SMS when the Temperature High then Value and i found When The Temperature is high he send sms But if the Temperature Not cool Down GSM will Send SMS Over and Over !!
i Need to ASk if there any way to Control GSM to send SMS One time Or After Every 2 Hour Or something Or Make him send only one sms !!
thnx i hope it will be there anyway to do this :slight_smile:


#2

Hi Tefa,
What you need is a software logic that will run only once.
Like a state machine.

something like,

if(SMSSent == 0)
{
    sendSMS();
    SMSSent = 1;
}

This will send SMS if its not already sent.


#3

Hello Happy to replay me

Can u Be More Specifically Becuse im Beginner in Program So can u give me tut about it !
i will be Very thank u :smiley:


#4

Hello

i Just try something like u told me be4 about how to send sms Only Once so i try your code but i was face problem
i must declare SMSSent AS What ?! Char or int
and i write function SMSSent But he didnt upload the code !! Can u help me because i really need Help in this case thnx


#5
//#include <SoftwareSerial.h>

//SoftwareSerial mySerial(2, 3); // RX, TX
float sensor=A5;
int gas_value;
int Led = 2;
char phone_no[]="01062799948";

void setup()
{
//Sim800l.begin();
pinMode(sensor,INPUT);
pinMode(4,OUTPUT);
pinMode(5, OUTPUT);
Serial.begin(9600);
//mySerial.begin(9600);
delay(1500); 
delay(1500);
  /*  Serial.println("AT+CMGF=1");    
    delay(3000);
    Serial.print("AT+CMGS=\"");
    Serial.print(phone_no); 
    Serial.write(0x22);
    Serial.write(0x0D);                               // hex equivalent of Carraige return    
    Serial.write(0x0A);                             // hex equivalent of newline
    delay(1000);
    Serial.print(" Welcome To Egetronic Produect ");
    Serial.print(" Produect is Ready !! ");
    delay(1000);
    Serial.println (char(26));/*///the ASCII code of the ctrl+z is 26

}

void loop()
{
int SMSSent;
gas_value=analogRead(sensor);
Serial.println(gas_value);
delay(1000);
if( gas_value > 1000 ){
      digitalWrite(5, LOW);
      digitalWrite(4, HIGH); 
if(SMSSent == 0)
{
    sendSMS();
    SMSSent = 1;
}
     
}
else 
{  if (  gas_value < 50 )
{
      digitalWrite(4, HIGH);
      digitalWrite(5, LOW);
}
else {
      digitalWrite(4, LOW);
      digitalWrite(5, HIGH);
  
  }
}
}
void sendSMS() {      Serial.println("AT+CMGF=1");    
      delay(2600);
      Serial.print("AT+CMGS=");
      Serial.print('"');
      Serial.print("01062799948"); 
      Serial.print('"');
   //   Serial.write(0x22);
      Serial.write(0x0D);  // hex equivalent of Carraige return    
      Serial.write(0x0A);  // hex equivalent of newline
      delay(2500);
      Serial.print("Done");
      delay(2500);
      Serial.println (char(26));//the ASCII code of the ctrl+z is 26
      delay(1000);}

i tryed But he still Sending SMS Everytime !!


#6

Declare SMSSent outside loop. Make it global.

The code looks fine, SMS should be sent only once, if you make variable global and make initialize it to 0.


#7

Thanks Thanks Thanks :slight_smile:
its Work Perfect !! :slight_smile:
thanks u again :slight_smile:
u R the Best :slight_smile:


#8

Please @Tefa can you send me the code to my email address Reubinho18@yahoo.com? I want the Arduino to send the text once if the value is above 50 and once if the value is below 50. I am having an overflow of messages here. Please send me the working code. Thanks


#9

Please send me the code with the corrections you are talking of. Reubinho18@yahoo.com thanks in advance


#10

Ok sure no problem … srry i didnt see the comment until now


#11

i already send to u by emil the code :slight_smile:
i hope it help u
if u have good idea can u share it with me i will be glad thanks :slight_smile:


#12

Thanks so much Tefa. I really appreciate what you have done for me and that’s very good of you all. By the way, I saw a code somewhere on a particular site concerning using gsm to control LED. So I copied it and edited it to my specs. Now everything is working fine. I want to add the part whereby when someone Put on the light without my knowledge, that same Arduino will send me a message to notify me that someone has put on the LED at home. I want the sending and the receiving of message to be done by one gsm and one Arduino. Can someone help me with the code? Thanks


#13

Thanks so much my boss. I really appreciate what you have done for me and that’s very good of you all. By the way, I saw a code somewhere on a particular site concerning using gsm to control LED. So I copied it and edited it to my specs. Now everything is working fine. I want to add the part whereby when someone Put on the light without my knowledge, that same Arduino will send me a message to notify me that someone has put on the LED at home. I want the sending and the receiving of message to be done by one gsm and one Arduino. Can someone help me with the code? Thanks


#14

hi tefa can you send me a code I’m badly need it :frowning: please send it to my email : limpotgin143@gmail.com. thanks in advance


#15

//#include <BareBoneSim800.h>

//BareBoneSim800 sim800; //
//BareBoneSim800 sim800(“your APN”); //needed for gprs funtionality
int soma=4;

void setup() {
Serial.begin(9600);
sim800.begin();
while(!Serial);

Serial.println(“Testing GSM module For SMS Sending”);
delay(8000); // this delay is necessary, it helps the device to be ready and connect to a network

Serial.println(“Should be ready by now”);
bool deviceAttached = sim800.isAttached();
if (deviceAttached)
Serial.println(“Device is Attached”);
else
Serial.println(“Not Attached”);

pinMode(soma,INPUT);

}

void loop() {
if(4==HIGH){
genda();

}}

void genda(){

  const char* number = "+2507285";

char* message = “Hello, This is a text message”;
bool messageSent = sim800.sendSMS(number, message);
if(messageSent)
Serial.println(“Message Sent”);
else
Serial.println(“Not Sent, Something happened”);

}

who can help me if pin 4 goes high sms not sent and how i can send one message


#16

Hi, tefa can you send me the your code to roshankumarbhamare@gmail.com…
thanks in advance