Problem mit SIM800L

Hallo zusammen,
ich befasse mich gerade mit dem UNO und dem GSM-Shield "SIM800L" und will damit SMS senden bzw. ggf. auch empfangen.
Dazu verwende ich dieses Modul.
Mit diesem Sketch gebe ich die AT-Befehle ein:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(2,3);

void setup() {
  Serial.begin(9600);
  Serial.println("Software Serial Sketch");
  mySerial.begin(9600);
}

void loop() { // run over and over
  while(mySerial.available()) {
    Serial.write(mySerial.read());
  }
  while(Serial.available()) {
    mySerial.write(Serial.read());
  }
}

Das Ergebnis im Monitor:

Die LED des Moduls blinkt nur im Sekundentakt und es wird bei Eingabe von "AT+CMGF=1" ERROR angezeigt. Vermutlich wird die Netzwerkverbindung nicht hergestellt. Die SIM-Karte benutzt keine PIN und beim Test im Handy war die Rufnummer erreichbar. Woran kann das liegen?

In deinem Sketch ist nicht zu sehen, wie du eine SMS sendest.
So kann das nicht funktionieren.
Welches Netzteil hast du am SIM800L und welchen Strom kann das liefern ?

Zum Senden der SMS will ich den Sketch aus diesem Beispiel verwenden. Wenn ich im Monitor AT eingebe, tut sich nichts. Deswegen habe ich mit einem anderen Sketch getestet, der zumindest auf AT reagiert. Was muss ich ergänzen, damit hier auch Befehle vom Monitor angezeigt werden?
Die Ursache der fehlenden Netzwerkverbindung habe ich gefunden: Zuerst hatte ich den SIM800L mit dem Arduino versorgt, was wohl zu wenig Strom geliefert hat. Diese Version wird auch in anderen Beispielen gezeigt. Nun über ein Labornetzteil ein DC-DC-Converter 5 Volt zur Versorgung geschaltet und es funktioniert! Die SMS wird gesendet. Bin mit diesem Teil noch am Einarbeiten.

Da fehlt auch die Funktion, AT-Befehle zu nutzen. Daher funktioniert das nicht.
Das SMS-Senden sollte da funktionieren.

Damit die AT-Befehle hier funktionieren, musst du diese Anweisungen

hinzufügen.

Ich habe die Ergänzung eingegeben und "my" entfernt. SMS-Versand ist noch OK, aber bei Eingabe von AT im Monitor wird nur AT angezeigt (OK fehlt).

/* This code works with Sim800L and a push button
   Press the button to send a simple SMS/Text to a specified phone number
   Refer to www.SurtrTech.com for more details
   Arduiono Uno Elego Port 6
   16.04.2022
*/

#include <SoftwareSerial.h>
SoftwareSerial sim800l(2, 3); // RX,TX for Arduino and for the module it's TXD RXD, they should be inverted

#define button1 7 //Button pin, on the other pin it's wired with GND

bool button_State; //Button state


void setup()
{

  pinMode(button1, INPUT_PULLUP); //The button is always on HIGH level, when pressed it goes LOW
  sim800l.begin(9600);   //Module baude rate, this is on max, it depends on the version
  Serial.begin(9600);
  Serial.print("Sketch:   ");   Serial.println(__FILE__);
  Serial.print("Uploaded: ");   Serial.println(__DATE__);
  Serial.println("Start");
  delay(1000);
}

void loop()
{
  // AT-Befehle im Monitor ausgeben
  while (Serial.available()) {
    Serial.write(Serial.read());
  }
  while (Serial.available()) {
    Serial.write(Serial.read());
  }

  button_State = digitalRead(button1);   //We are constantly reading the button State

  if (button_State == LOW) {            //And if it's pressed
    Serial.println("Button pressed");   //Shows this message on the serial monitor
    delay(200);                         //Small delay to avoid detecting the button press many times

    SendSMS();                          //And this function is called

  }

  if (sim800l.available()) {           //Displays on the serial monitor if there's a communication from the module
    Serial.write(sim800l.read());
  }
}

void SendSMS()
{
  Serial.println("Sending SMS...");               //Show this message on serial monitor
  sim800l.print("AT+CMGF=1\r");                   //Set the module to SMS mode
  delay(100);
  sim800l.print("AT+CMGS=\"+49176xxx\"\r");  //Your phone number don't forget to include your country code, example +212123456789"
  delay(500);
  sim800l.print("SIM800l is working");       //This is the text to send to the phone number, don't make it too long or you have to modify the SoftwareSerial buffer
  delay(500);
  sim800l.print((char)26);// (required according to the datasheet)
  delay(500);
  sim800l.println();
  Serial.println("Text Sent.");
  delay(500);

}

Was fehlt noch am Code?
Wenn es dann klappt, muss ich noch die delays ersetzen, um den Ablauf nicht auszubremsen.
Dieser Teil kommt in ein größeres Projekt rein, wobei ich auf einem entfernten Grundstück beim Unterschreiten einer bestimmten Akku-Spannung eine SMS als Alarmierung versenden will.

Du hast doch SoftwareSerial als sim800l definiert.
Da musst du mySerial als sim800l eintragen. Nur so kannst du auch sehen was gesendet bzw. als Quittung kommt.

Danke für die Hinweise. Es funktioniert nun mit diesem Code:

/* This code works with Sim800L and a push button
   Press the button to send a simple SMS/Text to a specified phone number
   Refer to www.SurtrTech.com for more details
   Arduiono Uno Elego Port 6
   16.04.2022
*/

#include <SoftwareSerial.h>
SoftwareSerial sim800l(2, 3); // RX,TX for Arduino and for the module it's TXD RXD, they should be inverted

#define button1 7 //Button pin, on the other pin it's wired with GND

bool button_State; //Button state


void setup()
{

  pinMode(button1, INPUT_PULLUP); //The button is always on HIGH level, when pressed it goes LOW
  sim800l.begin(9600);   //Module baude rate, this is on max, it depends on the version
  Serial.begin(9600);
  Serial.print("Sketch:   ");   Serial.println(__FILE__);
  Serial.print("Uploaded: ");   Serial.println(__DATE__);
  Serial.println("Start");
  delay(1000);
}

void loop()
{
  // AT-Befehle im Monitor ausgeben
  while(sim800l.available()) {
    Serial.write(sim800l.read());
  }
  while(Serial.available()) {
    sim800l.write(Serial.read());
  }

  button_State = digitalRead(button1);   //We are constantly reading the button State

  if (button_State == LOW) {            //And if it's pressed
    Serial.println("Button pressed");   //Shows this message on the serial monitor
    delay(200);                         //Small delay to avoid detecting the button press many times

    SendSMS();                          //And this function is called

  }

  if (sim800l.available()) {           //Displays on the serial monitor if there's a communication from the module
    Serial.write(sim800l.read());
  }
}

void SendSMS()
{
  Serial.println("Sending SMS...");               //Show this message on serial monitor
  sim800l.print("AT+CMGF=1\r");                   //Set the module to SMS mode
  delay(100);
  sim800l.print("AT+CMGS=\"+49176xxx\"\r");  //Your phone number don't forget to include your country code, example +212123456789"
  delay(500);
  sim800l.print("SIM800l is working");       //This is the text to send to the phone number, don't make it too long or you have to modify the SoftwareSerial buffer
  delay(500);
  sim800l.print((char)26);// (required according to the datasheet)
  delay(500);
  sim800l.println();
  Serial.println("Text Sent.");
  delay(500);

}

Das Problem mit den delays beim SMS-Versand will ich folgendermaßen umgehen:
Bei Unterspannung des Akkus geht ein Pegel auf HIGH und es wird ein kurzer Impuls zum Triggern des SMS-Versandes erzeugt. Die SMS-Funktion binde ich erst bei Unterspannung ein. So könnte es klappen.
Vielen Dank für deine Hilfe, denn beim SIM800L habe ich noch keine Erfahrung gesammelt.

Das sollte so funktionieren. Da du nur die SMS sendest, wenn das Problem auftritt, machen die delay() dann kein direktes Problem. Außer dein restliches Programm muss in dieser Zeit irgend etwas erledigen.

Prima, dass es soweit funktioniert.
Danke für deine Rückmeldung.