Arduino nano with sim800 and rf transmiiter

Add details : I’m trying to make an electric gate to be an IOT by using sim800L, arduino nano, RF transmitter. it has its function to be controlled by Blynk, when in Blynk dashboard the button V0 is On=(close), every 30 mins it will send signal to open just to make sure to be close. i add V1 as a terminal widget, i add V2 as a storage of the current state of the gate to confirm its action whether to close the gate or open it. when i try to connect to sgp1.blynk.cloud is connected but it returns “Cmd error” from blynk debug in serial monitor. I need help ASAP. here is the serial monitor prints:

01:09:23.073 -> [402527] Connecting to sgp1.blynk.cloud:80

01:09:24.559 -> [403990] <[1D|00|01|00|20]Cm*****************************G

01:09:25.502 -> [404952] >[00|00|01|00|C8]

01:09:25.534 -> [404953] Ready (ping: 859ms).

01:09:25.566 -> [404953] Free RAM: 720

01:09:25.599 -> [405020] <[11|00|02|00|9A]mcu[00]0.0.0[00]fw-type[00]TMPL6_****m[00]build[00]Mar[20|20]1[20]2024[20]01:02:21[00]blynk[00]1.3.2[00]h-beat[00]60[00]buff-in[00]256[00]dev[00]Arduino[20]Nano[00]cpu[00]ATmega328P[00]con[00]SIM800[00]tmpl[00]TMPL6_l***m

01:09:27.001 -> [406431] Cmd error

• Hardware model + communication type: arduino nano, gprs sim800L
• Smartphone OS (iOS 17.3.1)
• Blynk server region :singapore:
• Blynk Library version : 1.3.2
• Post your serial monitor output when experiencing some issues

Here is my code I create :

#define BLYNK_TEMPLATE_ID           "TMPxxxxxx"
#define BLYNK_TEMPLATE_NAME         "Device"
#define BLYNK_AUTH_TOKEN            "YourAuthToken"

#define BLYNK_PRINT Serial
#define BLYNK_DEBUG
#define TINY_GSM_MODEM_SIM800

#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>
#include <SoftwareSerial.h>
#include <RCSwitch.h> //rf library


char apn[]  = "gprs";
char user[] = "gprs";
char pass[] = "gprs";

// or Software Serial on Uno, Nano

SoftwareSerial SerialAT(3,2); // RX, TX

TinyGsm modem(SerialAT);


BlynkTimer timer;
RCSwitch RfOutput = RCSwitch();




int stateInMemory=0; // the current reading from the input pin
int qtyResend = 0; //counting how many it resends
int SigQual;

// This function will run every time Blynk connection is established
BLYNK_CONNECTED() {
  //get data stored in virtual pin V0 from server
  Blynk.syncVirtual(V0);
  Blynk.syncVirtual(V2);
}

// restoring counter from server
BLYNK_WRITE(V0)
{
//lastOutputState = EEPROM.read(0);
  if(param.asInt()==1 && stateInMemory==0) //v0 is 1 memory is 0
  {
    //send rf signal on
    sendRfComp();

    //saving
    stateInMemory = 1; //invert
    Blynk.virtualWrite(V2, stateInMemory);
    //delay(40);
    Serial.println("1 on");
    
    Blynk.virtualWrite(V1, "\n 1 on");
    //Blynk.logEvent("on_jbr_sent");
  }

 else if(param.asInt()==0 && stateInMemory==1) //v0 is 0 memory is 1
  {
    // Binary code - rf off
    // Binary code - rf off
    RfOutput.send("24 digit boolean"); //send rf signal off
    //Serial.println("off A1");  
    //delay(40);  
    
     RfOutput.send("24 digit boolean"); //send rf signal off
    //Serial.println("off B1");  
    //delay(40);  
    
     RfOutput.send("24 digit boolean"); //send rf signal off
    //Serial.println("off C1new");  
     
    
    stateInMemory = 0; //invert
    Blynk.virtualWrite(V2, stateInMemory);
    qtyResend = 0; //reset resendcounter

    //delay(50);
    Serial.println("1 off");
 
    Blynk.virtualWrite(V1, "\n 1 off ");
    //Blynk.logEvent("off_jbr_sent");
    
  }
  else 
  {
    Blynk.virtualWrite(V1, "Prob dtcted"); //debug
  }
  Serial.print("memory is ");
  Serial.println(stateInMemory);
  
}

BLYNK_WRITE(V1)
{

  // if you type "Marco" into Terminal Widget - it will respond: "Polo:"
  if (String("ck") == param.asStr()) {
    compSig();
    Blynk.virtualWrite(V1, "\n resnd alr ");
    Blynk.virtualWrite(V1, qtyResend);
    } 
  
}

BLYNK_WRITE(V2)
{
  //restoring int value
  stateInMemory = param.asInt();
}

void increment() {
if(stateInMemory==1)
  {
    sendRfComp();
    qtyResend++;
    
  }
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  delay(10);

  // Set GSM module baud rate
  SerialAT.begin(9600);
  delay(3000);

  // Restart takes quite some time
  // To skip it, call init() instead of restart()
  Serial.println("Init mdm");
  modem.restart();

  // Unlock your SIM card with a PIN
  //modem.simUnlock("1234");

  Blynk.begin(BLYNK_AUTH_TOKEN, modem, apn, user, pass,"sgp1.blynk.cloud");
  timer.setInterval(900000L, increment);

  RfOutput.enableTransmit(10); //to tx pin of rf transmitter
  RfOutput.setPulseLength(350);
  RfOutput.setProtocol(1);
  RfOutput.setRepeatTransmit(2);
  compSig();
 
}

void loop()
{
  Blynk.run();
  timer.run();
}

void compSig() {
   Blynk.virtualWrite(V1, "\n sgnl qty ");
  SigQual = modem.getSignalQuality();
  Blynk.virtualWrite(V1, SigQual);
}

void sendRfComp(){
      //send rf signal on
    // Binary code - rf on
    RfOutput.send("24 digit boolean");
    //Serial.println("on A1");  
    //delay(40);
   
    RfOutput.send("24 digit boolean");
    //Serial.println("on B1");  
    //delay(40);

    RfOutput.send("24 digit boolean");
    //Serial.println("on C1new"); 


Your ping time is quite long, which is probably due to a poor GRPS signal.
I’d try adding a better antenna to your SIM800 board.

Also, the SIM800 can draw quite a lot of current in Tx mode, so you need to have a good power supply for it.

I’d also comment this line of code out…

because the debug info isn’t telling you anything useful at this stage, and it can add to the processor overhead of the underpowered Nano.

Pete.

thank you for your comment mr. Pete, I will try your suggestion mister

@Pavel sir would you agree with what mr Pete Knight comments?

Hi Pete, its still wouldn’t solve it… and I notice something, even when i try to run it without #blynk_debug, when i check the device through the app, the device is shown online but is not responsive(when i try to send command “ck” in the terminal widget no response).

What does that mean?

Pete.