ARDUINO UNO & SIM800L

Dear, I am trying to write a code which enables an action by certain sms. I use Arduino UNO and a SIM800L module.

The code should realize the actions according to the attached scheme.

Could you please help me to modify the code below to realise the task (I have been learning Arduino basics however I am not experienced in programming).

// include the GSM library
#include <GSM.h>

// PIN Number for the SIM
#define PINNUMBER ""

// initialize the library instances
GSM gsmAccess;
GSM_SMS sms;

// Array to hold the number a SMS is retreived from
char senderNumber[20];

void setup() {
  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.println("SMS Messages Receiver");

  // connection state
  boolean notConnected = true;

  // Start GSM connection
  while (notConnected) {
    if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
      notConnected = false;
    } else {
      Serial.println("Not connected");
      delay(1000);
    }
  }

  Serial.println("GSM initialized");
  Serial.println("Waiting for messages");
}

void loop() {
  char c;

  // If there are any SMSs available()
  if (sms.available()) {
    Serial.println("Message received from:");

    // Get remote number
    sms.remoteNumber(senderNumber, 20);
    Serial.println(senderNumber);

    // An example of message disposal
    // Any messages starting with # should be discarded
    if (sms.peek() == '#') {
      Serial.println("Discarded SMS");
      sms.flush();
    }

    // Read message bytes and print them
    while (c = sms.read()) {
      Serial.print(c);
    }

    Serial.println("\nEND OF MESSAGE");

    // Delete message from modem memory
    sms.flush();
    Serial.println("MESSAGE DELETED");
  }

  delay(1000);

}

Please, could you help a little to invent the code? :sob:

I've almost succeeded. But it works only once after recording the code to the Arduino. What is wrong?

// PIN Number

define PINNUMBER ""

// initialize the library instance GSM gsmAccess; // include a 'true' parameter for debug enabled GSM_SMS sms;

char remoteNumber[20]; // Holds the emitting number char smsData[80]; //tablica do przechowania smsa byte smsIndex = 0; //Then, you create an index into the array char c;

void setup() { // initialize serial communications Serial.begin(9600);

Serial.println("SMS Messages Receiver");

// connection state boolean notConnected = true;

// Start GSM shield // If your SIM has PIN, pass it as a parameter of begin() in quotes while(notConnected) { if(gsmAccess.begin(PINNUMBER)==GSM_READY) notConnected = false; else { Serial.println("Not connected"); delay(1000); } }

Serial.println("GSM initialized"); Serial.println("Waiting for messages");

pinMode(13,OUTPUT); digitalWrite (13, LOW);

}

void loop() { // If there are any SMSs available() if (sms.available()) { Serial.println("Message received from:");

// Get remote number sms.remoteNumber(remoteNumber, 20); Serial.println(remoteNumber);

// This is just an example of message disposal // Messages starting with # should be discarded if(sms.peek()=='#') { Serial.println("Discarded SMS"); sms.flush(); }

// Read message bytes and print them. Read and (effectively) throw away all but the last character from the message. while(c=sms.read()) { smsData[smsIndex++] = c;} smsIndex = 0; //-Serial.println("\nEND OF MESSAGE"); // delete message from modem memory sms.flush(); Serial.println("MESSAGE DELETED"); if (strcmp(smsData, "on") == 0) {Serial.println("OKAY"); digitalWrite (13, HIGH); } else {Serial.println("NO"); digitalWrite (13, LOW); } delay(1000);

}}