Problem sending SMS to mobile phone

Hello to everyone in the community, firstly would like to thank all of you for reading this post and that any suggestion or remarks would be greatly appreciated. Lets get to it shall we...I have written some code to send SMS's to a recipient phone number using AT commands transmitted from the Controllino MAXI to the SIM Module instructing it to carry out certain commands.

Devices Used:

  • SIM5320E Module
  • Mean Well 5V/5A Switch Mode Power Supply
  • Controllino MAXI - ATmega 2560-16AU chip

This is my problem:

I am able to receive certain messages but unable to receive some as well.

Within this piece of code you will see a switch that toggles 4 messages to be sent to the users phone. Case 1 and 2 are the main cases that will be used, case 3 and 4 are just to show you how strange a behavior this problem is.

Now, if you were to try out my code...you should be able to observe the symptom that I am currently facing:

  • Case 1: Works fine; response from SIM module received and message received on users phone.
  • Case 2: Does not work; response from SIM module received but message not received on users phone.
  • Case 3: Commented out the first line of the message, works fine; response from SIM module received and message received on users phone.
  • Case 4: Commented out the third line of the message, works fine; response from SIM module received and message received on users phone.

Would like to understand better as to why Case 2 SMS message was not able to be sent even with successful responses from the SIM module. Thank you in advance.

This is my code:

#include <Controllino.h>
#include <SoftwareSerial.h>
SoftwareSerial SIM5320(52, 50); //rx, tx

unsigned long initialTime = 0;
byte commandInterval = 50;
String stringUser = "+xxxxxxxxxxx";


void setup() {
  Serial.begin(9600);
  Serial.println("Remote Control Test Ready!");

  SIM5320.begin(9600);
  Serial.println("SMS Communication Line Initialised...");

  Serial.println("System Setting Up...");
  delay(5000);
  Serial.println("System Setup Complete!");

}

void loop() {

  while (SIM5320.available()) {
    Serial.write(SIM5320.read());
  }

  while (Serial.available()) {
    char serialInput = Serial.read();
    switch (serialInput) {
      case '1':
        SIM5320.print(F("AT+CMGS=\""));
        SIM5320.print(stringUser);
        SIM5320.println(F("\""));
        initialTime = millis();
        while (millis() < initialTime + commandInterval) {
          //Do nothing
        }
        SIM5320.print(F("Remote Locker Assign Report\n")); 
        SIM5320.print(F("Locker Number : 1\n"));
        SIM5320.print(F("Pin Code : 99999\n"));
        SIM5320.print(F("Blocks Paid : 255"));
        break;

      case '2':
        SIM5320.print(F("AT+CMGS=\""));
        SIM5320.print(stringUser);
        SIM5320.println(F("\""));
        initialTime = millis();
        while (millis() < initialTime + commandInterval) {
          //Do nothing
        }
        SIM5320.print(F("Remote Locker Terminate Report\n"));
        SIM5320.print(F("Locker Number : 1\n"));
        SIM5320.print(F("Pin Code : 99999\n"));
        SIM5320.print(F("Blocks Paid : 0"));
        break;
        
      case '3':
        SIM5320.print(F("AT+CMGS=\""));
        SIM5320.print(stringUser);
        SIM5320.println(F("\""));
        initialTime = millis();
        while (millis() < initialTime + commandInterval) {
          //Do nothing
        }
        //SIM5320.print(F("Remote Locker Terminate Report\n"));
        SIM5320.print(F("Locker Number : 0\n"));
        SIM5320.print(F("Pin Code : 99999\n"));
        SIM5320.print(F("Blocks Paid : 0"));
        break;
        
      case '4':
        SIM5320.print(F("AT+CMGS=\""));
        SIM5320.print(stringUser);
        SIM5320.println(F("\""));
        initialTime = millis();
        while (millis() < initialTime + commandInterval) {
          //Do nothing
        }
        SIM5320.print(F("Remote Locker Terminate Report\n")); 
        SIM5320.print(F("Locker Number : 1\n"));
        //SIM5320.print(F("Pin Code : 99999\n"));
        SIM5320.print(F("Blocks Paid : 0"));
        break;
    }
  }
}

Reading your code, I don't think it's a code problem, as I don't see why the same command lines would not work the same when in different switch / case blocks. Maybe there is a problem with your module (connection, power, what else?).

I suggest you try this and enter your AT commands in the serial monitor (each 4 cases) and see if they all respond correctly.

Is it as simple as the message being too long for an SMS? I recall a 140 character limit?

No the message are less than 100 characters

Thank you lesept and AmphenolSensors for the inputs, appreciate it.

The link you attached was where I started off building this sketch :slight_smile:

I think the module is working fine, but will still run some more tests..will try sending the commands from the serial monitor to see if the bug in Case 2 still occurs. Will update if i find out anything new; cheers.

On another note, the character limit according to SIM depends on the used coding scheme, i.e. 7 bit GSM coding scheme ~ approx. 160 chars