Hi, I have a problem understanding how to use millis(). May home automation project is that when the sim800L receive a "ON" message it will turn on the relay for 5 minutes. and it will turn off after 5 minutes. Thank you in advance.
Here's the code I found in the internet without turn on the relay for 5 minutes
#include <Sim800l.h>
#include <SoftwareSerial.h>
// Configure software serial port
SoftwareSerial Sim800l(4, 5);
// Variable to store text message
char incomingMessage;
String textMessage;
// Relay connected to pin 7
const int relay = 7;
void setup() {
 pinMode(relay, OUTPUT); // Set relay as OUTPUT
 digitalWrite(relay, HIGH); // By default the relay is off // HIGH is OFF // LOW is ON
 // Initializing serial commmunication
 Serial.begin(9600);
 Sim800l.begin(9600);
 while (!Sim800l.available()) {
  Sim800l.println("AT");
  delay(1000);
  Serial.println("Connecting...");
 }
 Serial.println("Connected!");
 Sim800l.println("AT+CMGF=1"); //Set SMS to Text Mode
 delay(1000);
 Sim800l.println("AT+CNMI=1,2,0,0,0"); //Procedure to handle newly arrived messages(command name in text: new message indications to TE)
 delay(1000);
 Sim800l.println("AT+CMGL=\"REC UNREAD\""); // Read Unread Messages
}
void loop() {
 if (Sim800l.available()) {
  delay(100);
  // Serial Buffer
  while (Sim800l.available()) {
   incomingMessage = Sim800l.read();
   textMessage += incomingMessage;
  }
  delay(10);
  Serial.println(textMessage);
  textMessage.toUpperCase(); // Uppercase the Received Message
  //turn RELAY ON or OFF
  if (textMessage.indexOf("ON") > -1) {
   digitalWrite(relay, LOW);
  Â
  }
  //for test only
  if (textMessage.indexOf("OFF") > -1) {
   digitalWrite(relay, HIGH);
  } //test end
  delay(50);
  //Delete Messages & Save Memory
  if (textMessage.indexOf("OK") == -1) {
   Sim800l.println("AT+CMGDA=\"DEL ALL\"");
   delay(1000);
  }
  textMessage = "";
 }
}