SIM900 working fine but Arduino not turning on LED

Hi, I have a problem with my code here. The SIM900 was working fine until I changed 64 to 256 in the software serial library while trying to solve this so please help on how to resolve that as well. The main issue though is that the sim900 receives the SMS but it seems like mySerial.available() is never greater than 0. Please help.

The sketch is a bit messy as I have been trying many ways to fix it but here it is.

#include <SoftwareSerial.h>

//Create software serial object to communicate with SIM900
SoftwareSerial mySerial(7, 8); //SIM900 Tx & Rx is connected to Arduino #7 & #8

String textMessage;
const int light1 = 10;
String light1State = "LOW";

void setup()
{
   // Set lights as OUTPUT
  pinMode(light1, OUTPUT);
    // By default the leds is on
  digitalWrite(light1, LOW);

  
  //Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
  Serial.begin(9600);
  
  //Begin serial communication with Arduino and SIM900
  mySerial.begin(115200);
  delay(10000);
  Serial.println("Initializing..."); 
  delay(10000);

  mySerial.println("AT"); //Handshaking with SIM900
  updateSerial();
  
  mySerial.println("AT+CMGF=1");
  updateSerial();// Configuring TEXT mode
  mySerial.println("AT+IPR=115200");
  updateSerial();
  delay(10000);
  mySerial.println("AT+CNMI=2,2,0,0,0"); // Decides how newly arrived SMS messages should be handled
  updateSerial();
}

void loop()
{
  updateSerial();
   if(mySerial.available()>0){
    mySerial.write(mySerial.read());
    textMessage = mySerial.readString(); 
    textMessage.toUpperCase();   
 // mySerial.println(textMessage);
    delay(10);
  } 
  if(textMessage.indexOf("LIGHT1ON")>=0){
    // Turn on yellow led and save current state
    digitalWrite(light1, HIGH);
    light1State = "on"; 
    textMessage = "";   
  }
  if(textMessage.indexOf("LIGHT1OFF")>=0){
    // Turn off yellow led and save current state
    digitalWrite(light1, LOW);
    light1State = "off"; 
    textMessage = ""; 
  }
  if(textMessage.indexOf("LIGHT1STATE")>=0){
    String message = "light1 is " + light1State;
    sendSMS(message);
    textMessage = "";
  }
}

void updateSerial()
{
  delay(500);
  while (Serial.available()) 
  {
    mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
  }
  while(mySerial.available()) 
  {
    Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
  }
}
void sendSMS(String message){
  // AT command to set SIM900 to SMS mode
  Serial.print("AT+CMGF=1\r"); 
  delay(100);

  // REPLACE THE X's WITH THE RECIPIENT'S MOBILE NUMBER
  // USE INTERNATIONAL FORMAT CODE FOR MOBILE NUMBERS
   Serial.println("AT + CMGS = \"xxxxxxxxxxx\""); 
  delay(100);
  // Send the SMS
  Serial.println(message); 
  delay(100);

  // End AT command with a ^Z, ASCII code 26
  Serial.println((char)26); 
  delay(100);
  Serial.println();
  // Give module time to send SMS
  delay(5000);  
}

what was the 64 you changed to 256 - buffer capacity?
if so you have probably corrupted the way the buffers work
if you change it back does it then work?

Software Serial is unreliable at this speed. You are not likely to be able to get better than 38400 in my experience.

1 Like

Yes, it was buffer capacity. When I changed it back I still got weird characters.

Thank you I also tried 9600 and 19200 but got the same problem

you may have changed the SIM900 baudrate to 155200 and cannot change it back using SoftwareSerial
I suggest you get an Arduino with hardware serial ports such as the Mega which will operate at 115200 baud

Can you confirm the baud rate it is set to with
AT+IPR?

So in my code, I ran AT+IPR=15200 to try and set the baud rate and I could read it responded with OK but still had some illegible characters, however, I will check this a bit later because of time pressures I was advised to try out the sim800L so I will let you know how that goes.

Using sim800L now and it's working great

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