SIM900 Send recive SMS problem

Greeting,
I have a problem with SIM 900, and receiving more than one message.
The first SMS is received and after that no more messages can be received. As if the condition SIM 900.available ()> 0 is never fulfilled
Board: Arduino Uno, GSM SIM900

CODE:

#include <SoftwareSerial.h> // Library for using serial communication
SoftwareSerial SIM900(7, 8); // Pins 7, 8 are used as used as software serial pins

String incomingData;   // for storing incoming serial data
String message = "";   // A String for storing the message
int relay_pin = 12;    // Initialized a pin for relay module

void setup()
{
  Serial.begin(9600); // baudrate for serial monitor
  SIM900.begin(9600); // baudrate for GSM shield

  pinMode(relay_pin, OUTPUT);   // Setting erlay pin as output pin
  digitalWrite(relay_pin, LOW);  // Making relay pin initailly low

  //set SMS mode to text mode
  SIM900.println("AT+CMGF=1\r");  
  updateSerial();
  
  // set gsm module to tp show the output on serial out
  SIM900.println("AT+CNMI=2,2,0,0,0\r"); 
  updateSerial();  
}

void loop()
{
  //Function for receiving sms
  receive_message();

  // if received command is to turn on relay
  if(incomingData.indexOf("Led_on")>=0)
  {
    digitalWrite(relay_pin, HIGH);
    message = "Led is turned ON";
    Serial.print(message); 
    updateSerial();
  }
  
  // if received command is to turn off relay
  if(incomingData.indexOf("Led_off")>=0)
  {
    digitalWrite(relay_pin, LOW);
    message = "Led is turned OFF";
    Serial.print(message); 
    delay(1000);
  }  
}

void receive_message()
{
  if (SIM900.available() > 0)
  {
    incomingData = SIM900.readString(); // Get the data from the serial port.  
    Serial.print(incomingData); 
    delay(1000);
  }
}

void updateSerial()
{
  delay(500);
  while (Serial.available()) 
  {
    Serial.read();//Forward what Serial received to Software Serial Port
  }
  while(SIM900.available()) 
  {
    Serial.write(SIM900.read());//Forward what Software Serial received to Serial Port
  }
}

OUTPUT ON SERIAL MONITOR:

13:04:37.637 -> AT+CMGF=1

13:04:37.670 -> 
13:04:37.670 -> OK
13:04:38.167 -> AT+CNMI=2,2,0,0,0

13:04:38.200 -> 
13:04:38.200 -> OK
13:05:03.575 -> 
13:05:03.575 -> +CMT: "+38162XXXXX","","21/06/09,13:04:58+08"
13:05:03.608 -> Led_on
13:05:04.568 -> Led is turned ONLed is turned ONLed is turned ONLed is turned ONLed is turned ONLed is turned ONLed is turned ONLed is turned ONLed is turned ONLed is turned ONLed is turned ONLed is turned ONLed is turned ONLed is turned ONLed is turned ONLed is turned O

Any help is welcome

it looks like the code only monitors the SIM900 inteface() within updatesSerial(), but updateSerial() is only called when there is incoming data that matches "Led_on".

shouldn't the code monitor the SIM900 interface by unconditionally calling updateSerial() directly from loop()?

If you could tell me the correct position in the code for updateSerial ();

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