SMS read/write problem sim800 and arduino uno

I have this sketch and it runs great on serial monitor and tells the code to send sms when i sensor is trigged but the modem part in the sketch has a problem some where. i try to add the info from serial monitor in here so you can se it.

#include <SoftwareSerial.h>
const uint8_t rxPin = 2;
const uint8_t txPin = 3;
const uint8_t PIR_PIN = 6;
const uint8_t DOOR_PIN = 7;
const uint8_t WATER_PIN = 10;
const uint8_t GAS_PIN = 11;
const uint8_t RELAY1_PIN = 4;
const uint8_t RELAY2_PIN = 5;
const uint8_t RELAY3_PIN = 8;
const uint8_t RELAY4_PIN = 9;

const String ARM_COMMAND = "ARM";
const String DISARM_COMMAND = "DISARM";
const String RELAY1_ON_COMMAND = "FYR ON";
const String RELAY1_OFF_COMMAND = "FYR OFF";
const String RELAY2_ON_COMMAND = "LYS ON";
const String RELAY2_OFF_COMMAND = "LYS OFF";
const String RELAY3_ON_COMMAND = "PUMPE ON";
const String RELAY3_OFF_COMMAND = "PUMPE OFF";
const String RELAY4_ON_COMMAND = "EKSTRA ON";
const String RELAY4_OFF_COMMAND = "EKSTRA OFF";

const uint8_t SIM_CARD_RESET_MESSAGE_COUNTS = 50;
uint8_t sms_message_count = 0;
bool    reset_sim_card_flag = false;

//SoftwareSerial sim800(2, 3); // SIM800L rx og tx til pin 2 and 3
#define sim800 Serial

bool armed = false; // arm/disarm ;-)
bool relay1On = false;
bool relay2On = false;
bool relay3On = false;
bool relay4On = false;

void setup() {
  sim800.begin(9600);
  pinMode(PIR_PIN, INPUT);
  pinMode(DOOR_PIN, INPUT);
  pinMode(WATER_PIN, INPUT);
  pinMode(GAS_PIN, INPUT);    
  pinMode(RELAY1_PIN, OUTPUT);
  pinMode(RELAY2_PIN, OUTPUT);  
  pinMode(RELAY3_PIN, OUTPUT);
  pinMode(RELAY4_PIN, OUTPUT);  
  digitalWrite(RELAY1_PIN, HIGH);
  digitalWrite(RELAY2_PIN, HIGH);
  digitalWrite(RELAY3_PIN, HIGH);
  digitalWrite(RELAY4_PIN, HIGH);
}

void loop()
{
  /// clocking ///
  static uint32_t T = 0L;
  static uint16_t  seconds = 0;
  bool tick_short_alarm_wait = false; // this will trigger every 10 seconds
  bool tick_long_alarm_wait  = false; // this will trigger every 60 seconds;
  bool tick = false;
  if(millis() - T >= 1000L) // 1 second clock
  {
     T = millis();
     ++seconds;

     if(reset_sim_card_flag && seconds == 1)
     {
         reset_sim_card();
     }
 
     if(seconds % 30) // 30 seconds
     {
        tick_short_alarm_wait = true;
     }
     if(seconds == 300) // 5 min
     {
        seconds = 0;
        tick_long_alarm_wait = true;
    }
     tick = true;
  }

   
  if (armed && tick) // only check the inputs etc every second if armed.
  {
       /// this will monitor a change in the inputs ///
       /// a static type will store the variable similar to a global varaible ///
       static bool pir_alarm_state = false;
       static bool door_alarm_state = false;
       static bool water_alarm_state = false;
       static bool gas_alarm_state = false;
       bool new_alarm = false;
       // check sensors
       if (digitalRead(PIR_PIN) != pir_alarm_state)
       {
          pir_alarm_state ^= true; // this is a tricky way of making the variable state the same as the pin wihout recalling teh digitalRead 
          new_alarm = pir_alarm_state; 
       }
       if (digitalRead(DOOR_PIN) != door_alarm_state)
       {
          door_alarm_state ^= true; // this is a tricky way of making the variable state the same as the pin wihout recalling teh digitalRead 
          new_alarm = door_alarm_state; 
       } 
       if (digitalRead(WATER_PIN) != water_alarm_state)
       {
          water_alarm_state ^= true; // this is a tricky way of making the variable state the same as the pin wihout recalling teh digitalRead 
          new_alarm = water_alarm_state;
       }
       if (digitalRead(GAS_PIN) != gas_alarm_state)
       {
          gas_alarm_state ^= true; // this is a tricky way of making the variable state the same as the pin wihout recalling teh digitalRead 
          new_alarm = gas_alarm_state;
       }
       
       // send the alarm sms
       if(new_alarm) // reset the clock
       {
          seconds = 0;
       }

       if(pir_alarm_state && (new_alarm || tick_long_alarm_wait)) // alarm SMS
       {
         // send SMS message to alert user
         send_SMS("NOGEN I KABINE!");
       }
       if(door_alarm_state && (new_alarm || tick_long_alarm_wait)) // alarm SMS
       {
          // send SMS message to alert user
         send_SMS("DOOR OPEN!");
       }
       if(water_alarm_state && (new_alarm || tick_long_alarm_wait)) // alarm SMS
       {
         // send SMS message to alert user
         send_SMS("VAND_I_BAAD!");
       }
       if(gas_alarm_state && (new_alarm || tick_short_alarm_wait)) // alarm SMS often
       {
          // send SMS message to alert user
          send_SMS("GAS ALARM!");
       }
   }

  // sms beskeder ind
  if (sim800.available()) 
  {
    String message = sim800.readString();
    message.toUpperCase();
    if (message.indexOf(DISARM_COMMAND) >= 0)
    {
       armed = false;
       send_SMS("DISARMED!");
    }
    else if (message.indexOf(ARM_COMMAND) >= 0)
    {
       armed = true;
       send_SMS("ARMED!");
    }
    else if (message.indexOf(RELAY1_ON_COMMAND) >= 0)
    {
       relay1On = true;
       digitalWrite(RELAY1_PIN, HIGH);
       send_SMS("FYR ON!");
    }
    else if (message.indexOf(RELAY1_OFF_COMMAND) >= 0) 
    {
      relay1On = false;
      digitalWrite(RELAY1_PIN, LOW);
      send_SMS("FYR OFF!");
    }
    else if (message.indexOf(RELAY2_ON_COMMAND) >= 0)
    {
      relay2On = true;
      digitalWrite(RELAY2_PIN, HIGH);
      send_SMS("LYS ON!");
    }
    else if (message.indexOf(RELAY2_OFF_COMMAND) >= 0)
    {
      relay2On = false;
      digitalWrite(RELAY2_PIN, LOW);
      send_SMS("LYS OFF!");
    }
    else if (message.indexOf(RELAY3_ON_COMMAND) >= 0)
    {
      relay3On = true;
      digitalWrite(RELAY3_PIN, HIGH);
      send_SMS("PUMPE ON!");
    }
    else if (message.indexOf(RELAY3_OFF_COMMAND) >= 0) 
    {
      relay3On = false;
      digitalWrite(RELAY3_PIN, LOW);
      send_SMS("PUMPE OFF!");
    }
    else if (message.indexOf(RELAY4_ON_COMMAND) >= 0)
    {
      relay4On = true;
      digitalWrite(RELAY4_PIN, HIGH);
      send_SMS("EKSTRA ON!");
    }
    else if (message.indexOf(RELAY4_OFF_COMMAND) >= 0)
    {
      relay4On = false;
      digitalWrite(RELAY4_PIN, LOW);
      send_SMS("EKSTRA OFF!");
    }
  }
}       


void send_SMS(const char *message)
{
   sim800.println("AT+CMGS=\"+4526712271\""); // telefon nummer
   sim800.println(message);
   sim800.println((char)26); // send SMS
   if(++sms_message_count >= SIM_CARD_RESET_MESSAGE_COUNTS)
   {
      reset_sim_card_flag = true;
   }
   // delay(1000); // you may need a delay here
}

void reset_sim_card()
{
   reset_sim_card_flag = false;
   sms_message_count = 0;
   sim800.println("AT+CMGDA=DEL ALL");
   delay(1000);            
}
AT+CMGS="+4526712271"
ARMED!
¤
AT+CMGS="+4526712271"
NOGEN I KABINE!
¤
AT+CMGS="+4526712271"
FYR ON!
¤
skriv eller indsæt kode her

how did you connect and power te SIM800?
before running any specific code, did you try with one of the known working example?

yes I have tested the modem in a sketch and it can send and receive

didn't the code you tested have an AT+CMGF=1 command somewhere?
also are you sure about the

   sim800.println((char)26); // send SMS

usually we do sim800.write(26); without the CR LF

1 Like

I have a problem in this sketch. In serial monitor it runs with out problems but when i run it in real life over gsm by sms it doesent read my sms and doesent reply with sms.
What ever i do i cant spot the error.
Here is the sketch where it runs on serial monitor and doesent read/reply sms.
I hope a friendly member in the forum can fix the problem for me so it works and point out where the error was. i have used many many hours to try to solve the problem my self. My english is more than bad and it doesent make it more easy for me.
The plan with the sketch is to use 4 relay with on/off by sms, monitor 4 sensors and the allert me by sms when they go high and a on/off the sensors sms reply by arm/disarm by sms

#include <SoftwareSerial.h>
const uint8_t rxPin = 2;
const uint8_t txPin = 3;
const uint8_t PIR_PIN = 6;
const uint8_t DOOR_PIN = 7;
const uint8_t WATER_PIN = 10;
const uint8_t GAS_PIN = 11;
const uint8_t RELAY1_PIN = 4;
const uint8_t RELAY2_PIN = 5;
const uint8_t RELAY3_PIN = 8;
const uint8_t RELAY4_PIN = 9;

const String COMMAND_ON  = "ON";
const String COMMAND_OFF = "OFF";
//const String ARM_COMMAND = "ARM";
//const String DISARM_COMMAND = "DISARM";
//const String RELAY1_ON_COMMAND = "FYR ON";
//const String RELAY1_OFF_COMMAND = "FYR OFF";
//const String RELAY2_ON_COMMAND = "LYS ON";
//const String RELAY2_OFF_COMMAND = "LYS OFF";
//const String RELAY3_ON_COMMAND = "PUMPE ON";
//const String RELAY3_OFF_COMMAND = "PUMPE OFF";
//const String RELAY4_ON_COMMAND = "EKSTRA ON";
//const String RELAY4_OFF_COMMAND = "EKSTRA OFF";

const uint8_t SIM_CARD_RESET_MESSAGE_COUNTS = 50;
uint8_t sms_message_count = 0;
bool    reset_sim_card_flag = false;

//SoftwareSerial sim800(2, 3); // SIM800L rx og tx til pin 2 and 3
#define sim800 Serial

bool armed = false; // arm/disarm ;-)
bool relay1On = false;
bool relay2On = false;
bool relay3On = false;
bool relay4On = false;

void setup() {
  sim800.begin(9600);
  pinMode(PIR_PIN, INPUT);
  pinMode(DOOR_PIN, INPUT);
  pinMode(WATER_PIN, INPUT);
  pinMode(GAS_PIN, INPUT);    
  pinMode(RELAY1_PIN, OUTPUT);
  pinMode(RELAY2_PIN, OUTPUT);  
  pinMode(RELAY3_PIN, OUTPUT);
  pinMode(RELAY4_PIN, OUTPUT);  
  digitalWrite(RELAY1_PIN, HIGH);
  digitalWrite(RELAY2_PIN, HIGH);
  digitalWrite(RELAY3_PIN, HIGH);
  digitalWrite(RELAY4_PIN, HIGH);
}

void loop()
{
  /// clocking ///
  static uint32_t T = 0L;
  static uint16_t  seconds = 0;
  bool tick_short_alarm_wait = false; // this will trigger every 10 seconds
  bool tick_long_alarm_wait  = false; // this will trigger every 60 seconds;
  bool tick = false;
  if(millis() - T >= 1000L) // 1 second clock
  {
     T = millis();
     ++seconds;

     if(reset_sim_card_flag && seconds == 1)
     {
         reset_sim_card();
     }
 
     if(seconds % 30) // 30 seconds
     {
        tick_short_alarm_wait = true;
     }
     if(seconds == 300) // 5 min
     {
        seconds = 0;
        tick_long_alarm_wait = true;
    }
     tick = true;
  }

   
  if (armed && tick) // only check the inputs etc every second if armed.
  {
       /// this will monitor a change in the inputs ///
       /// a static type will store the variable similar to a global varaible ///
       static bool pir_alarm_state = false;
       static bool door_alarm_state = false;
       static bool water_alarm_state = false;
       static bool gas_alarm_state = false;
       bool new_alarm = false;
       // check sensors
       if (digitalRead(PIR_PIN) != pir_alarm_state)
       {
          pir_alarm_state ^= true; // this is a tricky way of making the variable state the same as the pin wihout recalling teh digitalRead 
          new_alarm = pir_alarm_state; 
       }
       if (digitalRead(DOOR_PIN) != door_alarm_state)
       {
          door_alarm_state ^= true; // this is a tricky way of making the variable state the same as the pin wihout recalling teh digitalRead 
          new_alarm = door_alarm_state; 
       } 
       if (digitalRead(WATER_PIN) != water_alarm_state)
       {
          water_alarm_state ^= true; // this is a tricky way of making the variable state the same as the pin wihout recalling teh digitalRead 
          new_alarm = water_alarm_state;
       }
       if (digitalRead(GAS_PIN) != gas_alarm_state)
       {
          gas_alarm_state ^= true; // this is a tricky way of making the variable state the same as the pin wihout recalling teh digitalRead 
          new_alarm = gas_alarm_state;
       }
       
       // send the alarm sms
       if(new_alarm) // reset the clock
       {
          seconds = 0;
       }

       if(pir_alarm_state && (new_alarm || tick_long_alarm_wait)) // alarm SMS
       {
         // send SMS message to alert user
         send_SMS("NOGEN I KABINE!");
       }
       if(door_alarm_state && (new_alarm || tick_long_alarm_wait)) // alarm SMS
       {
          // send SMS message to alert user
         send_SMS("DØR ÅBEN!");
       }
       if(water_alarm_state && (new_alarm || tick_long_alarm_wait)) // alarm SMS
       {
         // send SMS message to alert user
         send_SMS("VAND_I_BÅD!");
       }
       if(gas_alarm_state && (new_alarm || tick_short_alarm_wait)) // alarm SMS often
       {
          // send SMS message to alert user
          send_SMS("GAS ALARM!");
       }
   }

  // sms beskeder ind
  if (sim800.available()) 
  {
    String message = sim800.readString();
    message.trim();
    message.toUpperCase();

    if(message.indexOf("ARM") >= 0) // ARM DISARM COMMAND
    {
          if(message.indexOf("DISARM") == 0)
          {
             armed = false;
             send_SMS("DISARMED!");
          }
          else
          {
             armed = true;
             send_SMS("ARMED!");
          }
    }
    else if(message.indexOf("FYR") == 0) // RELAY1 COMMAND
    {
          if(message.indexOf(COMMAND_ON) >= 0)
          {
             relay1On = true;
             send_SMS("FYR ON!");
          }
          else if(message.indexOf(COMMAND_OFF) >= 0)
          {
             relay1On = false;
             send_SMS("FYR OFF!");
          }
          digitalWrite(RELAY1_PIN, relay1On);
    }
    else if(message.indexOf("LYS") == 0) // RELAY2 COMMAND
    {
          if(message.indexOf(COMMAND_ON) >= 0)
          {
             relay2On = true;
             send_SMS("LYS ON!");
          }
          else if(message.indexOf(COMMAND_OFF) >= 0)
          {
             relay2On = false;
             send_SMS("LYS OFF!");
          }
          digitalWrite(RELAY2_PIN, relay2On);
    }
    else if(message.indexOf("PUMPE") == 0) // RELAY3  COMMAND
    {
          if(message.indexOf(COMMAND_ON) >= 0)
          {
             relay3On = true;
             send_SMS("PUMPE ON!");
          }
          else if(message.indexOf(COMMAND_OFF) >= 0)
          {
             relay3On = false;
             send_SMS("PUMPE OFF!");
          }
          digitalWrite(RELAY3_PIN, relay3On);
    }
    else if (message.indexOf("EKSTRA") == 0) // RELAY4  COMMAND
    {
          if(message.indexOf(COMMAND_ON) >= 0)
          {
             relay4On = true;
             send_SMS("EKSTRA ON!");
          }
          else if(message.indexOf(COMMAND_OFF) >= 0)
          {
             relay4On = false;
             send_SMS("EKSTRA OFF!");
          }
          digitalWrite(RELAY4_PIN, relay4On);
    }
  }
}       


void send_SMS(const char *message)
{
   sim800.println("AT+CMGS=\"+4526712271\""); // telefon nummer
   sim800.println(message);
   sim800.println((char)26); // send SMS
   if(++sms_message_count >= SIM_CARD_RESET_MESSAGE_COUNTS)
   {
      reset_sim_card_flag = true;
   }
   // delay(1000); // you may need a delay here
}

void reset_sim_card()
{
   reset_sim_card_flag = false;
   sms_message_count = 0;
   sim800.println("AT+CMGDA=DEL ALL");
   delay(1000);            
}
skriv eller indsæt kode her

as you send characters to the SIM800 they will usually be echoed back, e.g. AT+CGMM
if you look at the SoftwareSerial library documentation it states
It cannot transmit and receive data at the same time.
this may be your problem - try altSoftSerial which s particularly useful when simultaneous data flows are needed

what Arduino are you using - if is supports hardware serial ports use them

I use a arduino uno. I think the problem is in the code. i can se in the serial monitor that the code tells the modem to send sms but it doesent happen and when i send a command by sms it doesent show up on serial monitor. there isnt any simultanes data flow. the plan is, i send a sms ARM and the code reply with ARMED and the code is able to send a sms when a sensor is trigged.
Sorry for my bad english.

#include <SoftwareSerial.h> ok

SoftwareSerial sim800(rxPin, txPin); // RX, TX

vs

//SoftwareSerial sim800(2, 3); // SIM800L rx og tx til pin 2 and 3
#define sim800 Serial

Your two topics on the same or similar subject have been merged.

Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.

Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.

Repeated duplicate posting could result in a temporary or permanent ban from the forum.

Could you take a few moments to Learn How To Use The Forum

It will help you get the best out of the forum in the future.

Thank you.

I found that out. I discovered that I had asked the question in the wrong forum and posted the question in the forum for code. Afterwards I discovered that I could not delete the first question. sorry

using a simple program which sends characters typed into the serial monitor and displays the response can you type the AT commands to send/receive a SMS text ?

The modem is testet and it is ok. I have made some changes and the setup is the same as in the sketch i testet the modem in.

#include <SoftwareSerial.h>
const uint8_t rxPin = 2;
const uint8_t txPin = 3;
const uint8_t PIR_PIN = 6;
const uint8_t DOOR_PIN = 7;
const uint8_t WATER_PIN = 10;
const uint8_t GAS_PIN = 11;
const uint8_t RELAY1_PIN = 4;
const uint8_t RELAY2_PIN = 5;
const uint8_t RELAY3_PIN = 8;
const uint8_t RELAY4_PIN = 9;
const String ARM_COMMAND = "ARM";
const String DISARM_COMMAND = "DISARM";
const String RELAY1_ON_COMMAND = "FYR ON";
const String RELAY1_OFF_COMMAND = "FYR OFF";
const String RELAY2_ON_COMMAND = "LYS ON";
const String RELAY2_OFF_COMMAND = "LYS OFF";
const String RELAY3_ON_COMMAND = "PUMPE ON";
const String RELAY3_OFF_COMMAND = "PUMPE OFF";
const String RELAY4_ON_COMMAND = "EKSTRA ON";
const String RELAY4_OFF_COMMAND = "EKSTRA OFF";
const uint8_t SIM_CARD_RESET_MESSAGE_COUNTS = 50;
uint8_t sms_message_count = 0;
bool    reset_sim_card_flag = false;
//SoftwareSerial sim800(2, 3); // SIM800L rx og tx til pin 2 and 3
#define sim800 Serial
bool armed = false; // arm/disarm 😉
bool relay1On = false;
bool relay2On = false;
bool relay3On = false;
bool relay4On = false;
void setup() {
  sim800.begin(9600);
  Serial.begin(9600);
  Serial.println("Initializing..."); 
  delay(5000);
  sim800.println("AT"); //Once the handshake test is successful, it will back to OK
  delay(5000);
  updateSerial();
  sim800.println("AT+CMGF=1"); // Configuring TEXT mode
  updateSerial();
  sim800.println("AT+CNMI=1,2,0,0,0"); // Decides how newly arrived SMS messages should be handled
  updateSerial();
  sim800.println("AT+CMGS=\"+4526712271\"");//change ZZ with country code and xxxxxxxxxxx with phone number to sms
  updateSerial();
  sim800.print("kloses hjemmelavet baad alarm"); //text content
  updateSerial();
  sim800.write(26);
  pinMode(PIR_PIN, INPUT);
  pinMode(DOOR_PIN, INPUT);
  pinMode(WATER_PIN, INPUT);
  pinMode(GAS_PIN, INPUT);    
  pinMode(RELAY1_PIN, OUTPUT);
  pinMode(RELAY2_PIN, OUTPUT);  
  pinMode(RELAY3_PIN, OUTPUT);
  pinMode(RELAY4_PIN, OUTPUT);  
  digitalWrite(RELAY1_PIN, HIGH);
  digitalWrite(RELAY2_PIN, HIGH);
  digitalWrite(RELAY3_PIN, HIGH);
  digitalWrite(RELAY4_PIN, HIGH);
}
void loop()  
  {
   /// clocking ///
   static uint32_t T = 0L;
   static uint16_t  seconds = 0;
   bool tick_short_alarm_wait = false; // this will trigger every 10 seconds
   bool tick_long_alarm_wait  = false; // this will trigger every 60 seconds;
   bool tick = false;
   if(millis() - T >= 1000L) // 1 second clock
    {
      T = millis();
      ++seconds;
      if(reset_sim_card_flag && seconds == 1)
      {
         reset_sim_card();
      }
      if(seconds % 30) // 30 seconds
      {
        tick_short_alarm_wait = true;
      }
       if(seconds == 300) // 5 min
      {
        seconds = 0;
        tick_long_alarm_wait = true;
      }
     tick = true;
    }
  if (armed && tick) // only check the inputs etc every second if armed.
  {
       /// this will monitor a change in the inputs ///
       /// a static type will store the variable similar to a global varaible ///
       static bool pir_alarm_state = false;
       static bool door_alarm_state = false;
       static bool water_alarm_state = false;
       static bool gas_alarm_state = false;
       bool new_alarm = false;
       // check sensors
       if (digitalRead(PIR_PIN) != pir_alarm_state)
       {
          pir_alarm_state ^= true; // this is a tricky way of making the variable state the same as the pin wihout recalling teh digitalRead 
          new_alarm = pir_alarm_state; 
       }
       if (digitalRead(DOOR_PIN) != door_alarm_state)
       {
          door_alarm_state ^= true; // this is a tricky way of making the variable state the same as the pin wihout recalling teh digitalRead 
          new_alarm = door_alarm_state; 
       } 
       if (digitalRead(WATER_PIN) != water_alarm_state)
       {
          water_alarm_state ^= true; // this is a tricky way of making the variable state the same as the pin wihout recalling teh digitalRead 
          new_alarm = water_alarm_state;
       }
       if (digitalRead(GAS_PIN) != gas_alarm_state)
       {
          gas_alarm_state ^= true; // this is a tricky way of making the variable state the same as the pin wihout recalling teh digitalRead 
          new_alarm = gas_alarm_state;
       }
       // send the alarm sms
       if(new_alarm) // reset the clock
       {
          seconds = 0;
       }
       if(pir_alarm_state && (new_alarm || tick_long_alarm_wait)) // alarm SMS
       {
         // send SMS message to alert user
         send_SMS("NOGEN I KABINE!");
       }
       if(door_alarm_state && (new_alarm || tick_long_alarm_wait)) // alarm SMS
       {
          // send SMS message to alert user
         send_SMS("DOOR OPEN!");
       }
       if(water_alarm_state && (new_alarm || tick_long_alarm_wait)) // alarm SMS
       {
         // send SMS message to alert user
         send_SMS("VAND_I_BAAD!");
       }
       if(gas_alarm_state && (new_alarm || tick_short_alarm_wait)) // alarm SMS often
       {
          // send SMS message to alert user
          send_SMS("GAS ALARM!");
       }
   }
  // sms beskeder ind
  if (sim800.available()) 
  {
    String message = sim800.readString();
    message.toUpperCase();
    if (message.indexOf(DISARM_COMMAND) >= 0)
    {
       armed = false;
       send_SMS("DISARMED!");
    }
    else if (message.indexOf(ARM_COMMAND) >= 0)
    {
       armed = true;
       send_SMS("ARMED!");
    }
    else if (message.indexOf(RELAY1_ON_COMMAND) >= 0)
    {
       relay1On = true;
       digitalWrite(RELAY1_PIN, HIGH);
       send_SMS("FYR ON!");
    }
    else if (message.indexOf(RELAY1_OFF_COMMAND) >= 0) 
    {
      relay1On = false;
      digitalWrite(RELAY1_PIN, LOW);
      send_SMS("FYR OFF!");
    }
    else if (message.indexOf(RELAY2_ON_COMMAND) >= 0)
    {
      relay2On = true;
      digitalWrite(RELAY2_PIN, HIGH);
      send_SMS("LYS ON!");
    }
    else if (message.indexOf(RELAY2_OFF_COMMAND) >= 0)
    {
      relay2On = false;
      digitalWrite(RELAY2_PIN, LOW);
      send_SMS("LYS OFF!");
    }
    else if (message.indexOf(RELAY3_ON_COMMAND) >= 0)
    {
      relay3On = true;
      digitalWrite(RELAY3_PIN, HIGH);
      send_SMS("PUMPE ON!");
    }
    else if (message.indexOf(RELAY3_OFF_COMMAND) >= 0) 
    {
      relay3On = false;
      digitalWrite(RELAY3_PIN, LOW);
      send_SMS("PUMPE OFF!");
    }
    else if (message.indexOf(RELAY4_ON_COMMAND) >= 0)
    {
      relay4On = true;
      digitalWrite(RELAY4_PIN, HIGH);
      send_SMS("EKSTRA ON!");
    }
    else if (message.indexOf(RELAY4_OFF_COMMAND) >= 0)
    {
      relay4On = false;
      digitalWrite(RELAY4_PIN, LOW);
      send_SMS("EKSTRA OFF!");
    }
   }
  }       
void send_SMS(const char *message)
{
   sim800.println("AT+CMGS=\"+4526712271\""); // telefon nummer
   sim800.println(message);
   sim800.println((char)26); // send SMS
   if(++sms_message_count >= SIM_CARD_RESET_MESSAGE_COUNTS)
   {
      reset_sim_card_flag = true;
   }
    delay(1000); // you may need a delay here
}
void updateSerial()
{
  delay(500);
  while (Serial.available()) 
  {
    sim800.write(Serial.read());//Forward what Serial received to Software Serial Port
  }
  while(sim800.available()) 
  {
    Serial.write(sim800.read());//Forward what Software Serial received to Serial Port
  }
}
void reset_sim_card()
{
   reset_sim_card_flag = false;
   sms_message_count = 0;
   sim800.println("AT+CMGDA=DEL ALL");
   delay(1000);            
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.