GSM Module Serial communication problems, code advice?

Hello everybody
I have been working on a GSM on of switch project.
The parts that are used are:
arduino Nano
Goouuutech iot 6 GSM module Flashed with normal A6 Tinker firmware to make it work :slight_smile:

I have been trying to make my Software Serial work for ages, tried different baud rates, buffer size and so on.
My problem is that I can not get the soft serial comm to work reliably between the Arduino and the GSM module. (Missing commands)

I have tried to put the GSM module on a simple serial to USB and the module is working great, and accepting the config codes copied from my sketch, and is able to receive and show messages.

When starting the Arduino i usually cant see any OK or other commands on the arduino recieved from the GSM module, even though it should print them according to the void loop, on some occations it recieves the config data that was intended to be send to the GSM module. The serial connection is ok between them as far as i can see…

I seems to me that the culprit is in the way the arduino communicates over serial to the module and i cant seem to get my head around it, tried delays between config commands and so on…

i have put the ino file under here.
I am really starting to have a headcache over this as i have tried various things and none worked to configure the GSM board right.

Any help is appreciated :confused:

Thank you

//GSM Controller 2020//


// Include Software Serial library to communicate with GSM
#include <SoftwareSerial.h>

// Configure software serial port
SoftwareSerial SIM800(7, 8); // Define serial over software to pin 7 and 8 on the nano


// Variables for later storage
String textMessage; //Store space only for later

String relayState = "OFF"; //Useful for storing the relay state 


const int relay = 13; // Relay connected to digital pin 13
const int resetpin = 2; // Reset pin connected to digitalpin 2 (For use later)
const int gsmonpin = 9; //GSM module start signal connected to Digital pin 9

//Timer function definition//
unsigned long previousmillis = 0; // Useful for storing millis later  
const long interval = 1800000; // Interval before auto shutting off by millis function


void setup() {
  //First turn on the shield
  digitalWrite(gsmonpin, HIGH);// pull digitalpin 9 high
  delay(400);// Wait 400 milliseconds
  digitalWrite(gsmonpin, LOW);// Pull digitalpin 9 low
 // delay(5000);
  
  // Set relaypin as OUTPUT
  pinMode(relay, OUTPUT);// Set ouput mode for relaypin
  digitalWrite(relay, LOW);// Initial state is off or low
  
  // Initializing serial commmunication
  SIM800.begin(115200);// Start serial comm with GSM module
  Serial.begin(115200);
  
  // Give time to GSM shield to start and find network
  delay(8000);
  ;
  

  // AT Commands to configure GSM Shield
  Serial.print("GSM is starting..."); //Print message to pc serial 
  delay(2000);// Wait 2 seconds
  Serial.print("AT");// Serial handshake with GSM module
  delay(2000);// Wait 2 seconds
  SIM800.print("AT+CMGF=1"); // Set GSM module to TEXT mode
  delay(2000); //Wait 2 seconds
  SIM800.print("AT+CNMI=2,2,0,0,0");// Set module to send SMS data to serial out upon receipt 
  delay(2000);//wait 2 seconds
  Serial.print("GSM configured...");//Print message to pc serial 
  
}


void loop(){
unsigned long currentmillis = millis(); //Define millis to unsigned long

    
//Millis function//  
//Millis function to turn off automaticly after a given time//
if (relayState=="on"){
  if(currentmillis-previousmillis >=interval){
    digitalWrite(relay, LOW);
    relayState = "off"; 
    Serial.println("Relay set to OFF by timer");
    textMessage = "";
    SIM800.println("AT+CMGD=1,4");
    delay(1000);
}
}
  {
//GSM read functions and print to visible pc serial//    
  if(SIM800.available()>0){
    textMessage = SIM800.readString();
    Serial.print(textMessage);    
    delay(10);
  }
  //Message reaction functions// 
  if(textMessage.indexOf("START")>=0){
    // Turn on relay and save current state
    digitalWrite(relay, HIGH);
    relayState = "on";
    Serial.println("Relay set to ON");  
    textMessage = "";
    previousmillis = millis();//
       
  }
  if(textMessage.indexOf("STOP")>=0){
    // Turn off relay and save current state
    digitalWrite(relay, LOW);
    relayState = "off"; 
    Serial.println("Relay set to OFF by user");
    textMessage = "";
    SIM800.println("AT+CMGD=1,4");
    delay(1000); 
  }
} 
}

Please follow the advice on posting a programming question given in Read this before posting a programming question

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless

UKHeliBob:
Please follow the advice on posting a programming question given in Read this before posting a programming question

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless

Sorry, The post should be updated now :relaxed:

Let me know if there’s more to it than i have changed…
Thank you :grinning:

Just some feedback
Ended up by purchasing a SIM 800 Module and everything worked well from here, the sim 800l module was running on 9600 baud from the start so there was not the same configuration problems..
Hope this can help other in the same situation later...
Best regards