Reading messages by Arduino received from SIM800L GSM Module

I am working to build a project to send an alert SMS to a mobile number, after sending an SMS i want to decrease the frequency of the message sent to the number. I will cause a delay in the program to equal number of hours as the person responds by a number in the message. The Arduino should read the SMS and cause a delay in the program. Can I get the code to achieve such a work? The GSM Module will receive the SMS send by the mobile.

1 Like

I want to read the message and cause a delay of that much in the code. Also I have to delete the message so that it don't gets repeated.

best regards Stefan

I have gone through the article but I am not getting how to read the SMS and cause delay of the number of hours as the number received as SMS.

So write about your programming experience and give a more detailed description what a bystanding person watching the process can see.
In this description use example numbers for everything.

best regards Stefan

1 Like

Suppose the Arduino sends an alert SMS to a mobile number of a presence of smoke as detected by smoke detector. As the command of sending SMS is in
void loop()
{
}

The SMS will be sent continously to the mobile number. Here I want to introduce a delay in the sending SMS time after sending the first SMS. Any time the user responds with a numbers like "2" then Arduino will send SMS after every 2 hours if smoke is present.

OK that's a description of the functionality you want.
Next step: what programming-experience do you have?

@StefanL38
void loop()
{
float temp = sht20.readTemperature(); // Read Temperature
if(temp>=50) // Checks if temp is greater than the threshold level
{

  temp = sht20.readTemperature();               // Read Temperature

 Data_SMS = "High Temperature \nValue = "+ (String)avg +"\nTemperature 
                                         = "+ (String)(temp,1) +" °C";

Serial.println("Sending SMS...");
sim800l.println("AT+CMGF=1"); // Set the module to SMS mode
delay(1000);

// Phone number in which text needs to be sent

sim800l.println("AT+CMGS="+91**********"\r");
delay(1000);

sim800l.println(Data_SMS); // This text is sent to the phone number
delay(1000);
Serial.println(Data_SMS);

sim800l.println((char)26); // required according to the datasheet
delay(1000);
Serial.println(" SMS sent...");

// here I want to add a delay as per the SMS received. If "2" is received, here I will add delay for 2 hours

}

}

I was asking how much experience do you have in programming.
what are your programming skills?
What was the most complex project you did with a microcontroller?

by the way:
you should always post the full sketch.
You should post code by using code-tags
There is an automatic function for doing this in the Arduino-IDE
just three steps

  1. press Ctrl-T for autoformatting your code
  2. do a rightclick with the mouse and choose "copy for forum"
  3. paste clipboard into write-window of a posting

best regards Stefan

@StefanL38
This is my first project, I don't have much experience with microcontroller.
I have knowledge of Java.

#include<SoftwareSerial.h> // Loads SoftwareSerial Library for Serial communication
#include <Wire.h> // Loads Wire Library to communicate with I2C devices
#include "DFRobot_SHT20.h" // Arduino Library for SHT20 Sensor

DFRobot_SHT20 sht20;

String Data_SMS;

void setup()
{
// put setup code here, to run once:

Serial.begin(9600); // Set Serial Monitor baude rate to 9600
sht20.initSHT20(); // Init SHT20 Sensor
delay(1000); //Delay of 1 second
}

void loop()
{

float temp = sht20.readTemperature();
if(temp>=50) // Checks if avg is greater than the threshold level
{

  temp = sht20.readTemperature();               // Read Temperature

 Data_SMS = "High temperature \nValue = "+ (String)avg +"\nTemperature 
                                         = "+ (String)(temp,1) +" °C";

Serial.println("Sending SMS...");
sim800l.println("AT+CMGF=1"); // Set the module to SMS mode
delay(1000);

// Phone number in which text needs to be sent

sim800l.println("AT+CMGS="+91**********"\r");
delay(1000);

sim800l.println(Data_SMS); // This text is sent to the phone number
delay(1000);
Serial.println(Data_SMS);

sim800l.println((char)26); // required according to the datasheet
delay(1000);
Serial.println(" SMS sent...");

// here I want to add a delay as per the SMS received. If "2" is received, here I will add delay for 2 hours

}

}

You should post code by using code-tags
There is an automatic function for doing this in the Arduino-IDE
just three steps

  1. press Ctrl-T for autoformatting your code
  2. do a rightclick with the mouse and choose "copy for forum"
  3. paste clipboard into write-window of a posting

best regards Stefan

Ctrl T is opening a new tab
I am doing the code in online Arduino Editor.
Please help me out in the last part, Please

mark all lines of your program. From the very first to the very last line.
press Ctrl-C to copy the marked lines into the clicpboard.

Click on the <|>-Button above the textinputfield of the forum.
This will create signs for a code-section

Press Ctrl-V to paste the clipboard content.
best regards Stefan

#include<SoftwareSerial.h> // Loads SoftwareSerial Library for Serial communication
#include <Wire.h> // Loads Wire Library to communicate with I2C devices
#include "DFRobot_SHT20.h" // Arduino Library for SHT20 Sensor



// Pin 9,10 is used as RX,TX for Arduino and for the GSM module it's TXD, RXD
SoftwareSerial sim800l(9,10); 

DFRobot_SHT20 sht20;

String Data_SMS;

void setup()
{
// put setup code here, to run once:

Serial.begin(9600); // Set Serial Monitor baude rate to 9600
sim800l.begin(9600);          // Set Module baude rate to 9600
sht20.initSHT20(); // Init SHT20 Sensor
delay(1000); //Delay of 1 second
}

void loop()
{

float temp = sht20.readTemperature();
if(temp>=50) // Checks if avg is greater than the threshold level
{

  temp = sht20.readTemperature();               // Read Temperature

 Data_SMS = "High temperature \nValue = "+ (String)avg +"\nTemperature 
                                         = "+ (String)(temp,1) +" °C";
Serial.println("Sending SMS...");
sim800l.println("AT+CMGF=1"); // Set the module to SMS mode
delay(1000);

// Phone number in which text needs to be sent
sim800l.println("AT+CMGS="+91**********"\r");
delay(1000);

sim800l.println(Data_SMS); // This text is sent to the phone number
delay(1000);
Serial.println(Data_SMS);

sim800l.println((char)26); // required according to the datasheet
delay(1000);
Serial.println(" SMS sent...");

// here I want to add a delay as per the SMS received. If "2" is received, here I will add delay for 2 hours

}

}

@StefanL38

there is a function called millis() which is non-blocking.
delay() is a blocking command as long as a delay is executed your code can do nothing else

here is a doem-code

unsigned long DemoTimerA = 0; // variables that are used to store timeInformation
unsigned long DemoTimerB = 0; 
unsigned long DemoTimerC = 0; 
unsigned long DoDelayTimer = 0; 

boolean TimePeriodIsOver (unsigned long &expireTime, unsigned long TimePeriod) {
  unsigned long currentMillis  = millis();
  if ( currentMillis - expireTime >= TimePeriod )
  {
    expireTime = currentMillis; // set new expireTime
    return true;                // more time than TimePeriod) has elapsed since last time if-condition was true
  } 
  else return false;            // not expired
}

void ClearScreen() {
  for (uint8_t i = 0; i < 100; i++){
    Serial.println();
  }
}

// pslib pstringlib
#include <PString.h> // the use of PString avoids code-malfunction like Strings can do

char    SenderID_AoC[16];
PString SenderID_PS (SenderID_AoC, sizeof(SenderID_AoC) );

char    StatusMsg_AoC[64];
PString StatusMsg_PS (StatusMsg_AoC, sizeof(StatusMsg_AoC) );

typedef struct ESP_Data_ToSend_type {
  char  MyESP_NOW_SenderID_AoC[16];
  char  MyESP_NOW_StatusMsg_AoC[64];
  int   MyESP_NOW_Int;
  float MyESP_NOW_Float;
} ESP_Data_ToSend_type;

ESP_Data_ToSend_type ESP_Data_ToSend;


void setup() 
{
  Serial.begin(115200);
  Serial.println("Program started");
}

void loop() 
{
  if (  TimePeriodIsOver(DemoTimerA,1000)  )
    {
      //ClearScreen();
      SenderID_PS = "Cow01";
      StatusMsg_PS = "TimerA overDue";
      memcpy(ESP_Data_ToSend.MyESP_NOW_SenderID_AoC, SenderID_AoC, sizeof(ESP_Data_ToSend.MyESP_NOW_SenderID_AoC) );
      memcpy(ESP_Data_ToSend.MyESP_NOW_StatusMsg_AoC, StatusMsg_AoC, sizeof(ESP_Data_ToSend.MyESP_NOW_StatusMsg_AoC) );
      Serial.println(ESP_Data_ToSend.MyESP_NOW_SenderID_AoC);      
      Serial.println(ESP_Data_ToSend.MyESP_NOW_StatusMsg_AoC);      
    }
       
  if (  TimePeriodIsOver(DemoTimerB,2000)  )
    {
      //ClearScreen();
      Serial.println("X                TimerB overDue         X");
    }

  if (  TimePeriodIsOver(DemoTimerC,3000)  )
    {
      //ClearScreen();
      Serial.println("X                               TimerCODX");
    }

  if (  TimePeriodIsOver(DoDelayTimer,20000)  )
    {
      Serial.println("every 20 seconds execute delay(3500)... to make all other timers overdue");
      delay(3500);
    }    
}

Using variable-rtype String on an arduino is a bad idea. Strings eat up memory over time which will make the program crash
You should use something like
PString or SafeString

What is the reason to not use a locally installed Arduino-IDE?
best regards Stefan

Online Arduino Code Editor can be accessed from anywhere as it is saved in the cloud. So I can edit from other computers as well

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