Relay control with Arduino and SIM800L

Hi

I am trying to control a relay (switch is on or off) by sending a SMS message “ON” or “OFF” to a SIM800L unit connected to an Arduino Pro Mini (which I program with a FDTI):

SIM800L ARDUINO
RX ---- 10
TX ---- 9
LED ---- 7

I modified the code of Noel Orbong that I found on the internet. The code works perfectly as long as the FTDI is connected to the Arduino board. However, if I unplug the FDTI, power down the Arduino as well as SIM800L and power it up again (without the FTDI connected) the code does not switch the LED that is connected to pin 7 on or off, nor does the confirmation messages “Switched ON” or “Switched OFF” gets sent to my cell phone.

I tried removing the normal Serial communication lines (not the “mySerial” lines and that does not solve the problem.

Can anyone maybe see what I am doing wrong? (Actually I am a chemist not an electronic engineer so I am not surprised that I do not get it right!)

Will appreciate any proposal. Thank you in advance.

Regards
Deon

The code:

[//*************************************************** 
 This code is an open source and can be modefied for better use

 created 16 Feb 2017
 by Noel Orbong Jr.

 I have modified this code slightly - Deon Steyn
 ****************************************************/  
 
#include <SoftwareSerial.h>
SoftwareSerial mySerial(9,10); 

char incomingByte; 
String inputString;
int led = 7;


void setup() 
{
      pinMode(led, OUTPUT);
      pinMode(LED_BUILTIN, OUTPUT);
      //Serial.begin(9600);
      mySerial.begin(9600); 
      // Check if you're currently connected to SIM800L 
      while(!mySerial.available()){
        mySerial.println("AT");
        delay(1000); 
        ////Serial.println("connecting....");
        }
      ///Serial.println("Connected..");  
      mySerial.println("AT+CMGF=1\r\n");  //Set SMS Text Mode 
      delay(1000);  
      mySerial.println("AT+CNMI=1,2,0,0,0");  //procedure, how receiving of new messages from the network
      delay(1000);
      mySerial.println("AT+CMGL=\"REC UNREAD\""); // Read unread messages
      delay(1000);
      digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(1000);                   
     }

void loop()

{  
  if(mySerial.available()){
      delay(100);
      
      // Serial buffer
      while(mySerial.available()){
        incomingByte = mySerial.read();
        inputString += incomingByte; 
        }
        
        delay(10);
       
        ////Serial.println(inputString);
        inputString.toUpperCase(); // uppercase the message received

        //turn LED ON or OFF
        if (inputString.indexOf("ON") > -1){
          digitalWrite(led, HIGH);
          delay(100);
            mySerial.write("AT+CMGS=\"082xxxxxxxx\"\r\n");
            delay(1000);
            mySerial.write("Switched ON");
            delay(1000);
            mySerial.write((char)26);
            delay(1000);
            ////Serial.println("SMS sent");
        }         
         if (inputString.indexOf("OFF") > -1){
          digitalWrite(led, LOW);
          mySerial.write("AT+CMGS=\"082xxxxxxxx\"\r\n");
          delay(1000);
          mySerial.write("Switched OFF");
          delay(1000);
          mySerial.write((char)26);
          delay(1000);
          ////Serial.println("SMS sent");
          }
          
        delay(50);

        //delete messages to save memory
        if (inputString.indexOf("OK") == -1){
        mySerial.println("AT+CMGDA=\"DEL ALL\"");
        delay(1000);}

        inputString = "";
  }
}

When the FTDI cable is not powering the Arduino, what is? I would think that even a chemist would realize that that was important information.

Hi PaulS.

Indeed. Even as a chemist I know that the Arduino has to be powered. Apologies for my dilapidated use of the English vernacular, not my first!

Thus the fragment: "However, if I unplug the FDTI, power down the Arduino as well as SIM800L and power it up again (without the FTDI connected) ...." should have read: "However, if I unplug the FDTI, power down the Arduino as well as SIM800L and power both up again (without the FTDI connected) ..."

Again apologies for the mistake! And thanks for the input. At least it eliminated one obvious fundamental physical law that has to be obeyed (in chemistry, physics, quantum physics, electronics, biology, etc., i.e. energy in some form is required!

Yet for what it is worth to others, in retrospect your contribution has some applicability. Subsequently I cleaned up the power supply to the SIM800L by adding several sizes of capacitors between Vcc and GND and that seemed to have solved the problem.

Thanks again.