Arduino nano + Sim800l v2 goes offline very often

Hi,
I having problem with blynk cloud. I want to see an analog value and send a notification if the value is smaler that my analog read value! Evrithyng works for 1-2 minutes then i get the notification in app “your device is offline”. My power supply is a 5Vdc 2A power adapter(mobile phone charger) and I put a 3300uF capacitor near to SIM800L V2 modul!
Thank you.

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

/* Fill-in your Template ID (only if using Blynk.Cloud) */
//#define BLYNK_TEMPLATE_ID   "YourTemplateID"


// Select your modem:
#define TINY_GSM_MODEM_SIM800
//#define TINY_GSM_MODEM_SIM900
//#define TINY_GSM_MODEM_M590
//#define TINY_GSM_MODEM_A6
//#define TINY_GSM_MODEM_A7
//#define TINY_GSM_MODEM_BG96
//#define TINY_GSM_MODEM_XBEE

// Default heartbeat interval for GSM is 60
// If you want override this value, uncomment and set this option:
//#define BLYNK_HEARTBEAT 30

#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "Qz7bDuRDBxrzAlYePU2dJHpYVAotQrmb";

// Your GPRS credentials
// Leave empty, if missing user or pass
char apn[]  = "ipfix.vodafone.ro";
char user[] = "";
char pass[] = "vodafone";

// Hardware Serial on Mega, Leonardo, Micro
//#define SerialAT Serial1

// or Software Serial on Uno, Nano
#include <SoftwareSerial.h>
SoftwareSerial SerialAT(2, 3); // RX, TX
int senzorpin = A0;
int valoare;
TinyGsm modem(SerialAT);

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("Initializing modem...");
  modem.restart();

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

  Blynk.begin(auth, modem, apn, user, pass);
}

void loop()
{ 
  Blynk.run();
  valoare = analogRead(senzorpin);
 if (valoare <= 400)
 {
  Blynk.notify("Alarma nivel minim, Se incearca recuperarea");
  }
}



You should clean your void loop first, read this article
https://docs.blynk.io/en/legacy-platform/legacy-articles/keep-your-void-loop-clean
The ideal blynk void loop should look like this

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

I cleen de loop and is working fine but in the app I get this message after every 5minutes “Your device disconected”.

In serial monitor everything is fine:

[3127] Modem init…
[3351] Connecting to network…
[3445] Network: CONNEX GSM
[3446] Connecting to ipfix.vodafone.ro …
[9623] Connected to GPRS
[9696] Connecting to blynk-cloud.com:80
[12295] Ready (ping: 1536ms).

Code:

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

/* Fill-in your Template ID (only if using Blynk.Cloud) */
//#define BLYNK_TEMPLATE_ID   "Tanc Apa"


// Select your modem:
#define TINY_GSM_MODEM_SIM800
//#define TINY_GSM_MODEM_SIM900
//#define TINY_GSM_MODEM_M590
//#define TINY_GSM_MODEM_A6
//#define TINY_GSM_MODEM_A7
//#define TINY_GSM_MODEM_BG96
//#define TINY_GSM_MODEM_XBEE

// Default heartbeat interval for GSM is 60
// If you want override this value, uncomment and set this option:
//#define BLYNK_HEARTBEAT 30

#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "Qz7bDuRDBxrzAlYePU2dJHpYVAotQrmb";

// Your GPRS credentials
// Leave empty, if missing user or pass
char apn[]  = "ipfix.vodafone.ro";
char user[] = "";
char pass[] = "vodafone";

// Hardware Serial on Mega, Leonardo, Micro
//#define SerialAT Serial1

// or Software Serial on Uno, Nano
#include <SoftwareSerial.h>
SoftwareSerial SerialAT(2, 3); // RX, TX
int senzorpin = A0;
int valoare;
TinyGsm modem(SerialAT);

BlynkTimer timer;
int sensorValue;
void setup()
{
  timer.setInterval(1000L, sensorDataSend);
  // 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("Initializing modem...");


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

  Blynk.begin(auth, modem, apn, user, pass);
}

void loop()
{ 
  Blynk.run();
    timer.run();
}
void sensorDataSend()
{
  sensorValue = analogRead(A0);         // reading sensor from analog pin
  sensorValue = map(sensorValue, 200, 1023 , 0, 10000 ); // maping 1-5V
  Blynk.virtualWrite(V0, sensorValue);  // sending sensor value to Blynk app
}

Please edit your post and add triple backticks ( ``` ) before and after your sketch

Have you tried this?

Also, I’d put this line of code…

after your Blynk.begin command.

Your ping time is quite high. Do you have a good external antenna connected to your SIM800 module?

Pete.

Thank for the help now it seems to be working well. Ping is 300ms! Pleas help me with an idea to do a notificaction function that sends me x notifications and then stops if the analog value is <= y and a notification one time if the analog value >= y and then stops
Thank you in advance

Just use a variable to count how many notifications have been sent, the reset it once the condition you are testing for is false once again.

But, I’d recommend that you upgrade to the new Blynk IoT platform.

Pete.

Thank you, it seems to work but a I was forced to use 6 second delay to send 5 notifications. That delay is ok? If I want to use AT commands for example call comand how can I do it? Can I make in this void?

 void sensorDataSend()
{
  valoaresenzor = analogRead(senzorpin);         // reading sensor from analog pin
  valoaresenzor = map(valoaresenzor, 200, 999 , 0, 10000 ); // maping 1-5V
  Blynk.virtualWrite(V0, valoaresenzor);  // sending sensor value to Blynk app
 
    if ((valoaresenzor <= 2000) && (min_notifications <=5))
    {
    Blynk.notify("Alarma nivel minim, Se incearca recuperarea");
    min_notifications ++ ;
    max_notifications = 0 ;
    delay (6000) ;
    }
    else if ((valoaresenzor >= 2500) && (max_notifications <= 1))
    {
    Blynk.notify("Nivel apa recuperata");
    max_notifications ++ ;
    min_notifications = 0 ;
    delay (2000) ;
    }
  }

No, use of delays is unacceptable in Blynk.

Pete.

Ok I understand. My idea is to increase the time in the blynk timer. It is good like this? Help me please with the call comand(ATD…)

Read this article

I read the article and chose to try the time.setTimer () version but it doesn’t seem to work. I’m missing something?

#define BLYNK_PRINT Serial

/* Fill-in your Template ID (only if using Blynk.Cloud) */
//#define BLYNK_TEMPLATE_ID   "Tanc Apa"


// Select your modem:
#define TINY_GSM_MODEM_SIM800
//#define TINY_GSM_MODEM_SIM900
//#define TINY_GSM_MODEM_M590
//#define TINY_GSM_MODEM_A6
//#define TINY_GSM_MODEM_A7
//#define TINY_GSM_MODEM_BG96
//#define TINY_GSM_MODEM_XBEE

// Default heartbeat interval for GSM is 60
// If you want override this value, uncomment and set this option:
#define BLYNK_HEARTBEAT 60

#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "Qz7bDuRDBxrzAlYePU2dJHpYVAotQrmb";

// Your GPRS credentials
// Leave empty, if missing user or pass
char apn[]  = "ipfix.vodafone.ro";
char user[] = "";
char pass[] = "vodafone";

// Hardware Serial on Mega, Leonardo, Micro
//#define SerialAT Serial1

// or Software Serial on Uno, Nano
#include <SoftwareSerial.h>
SoftwareSerial SerialAT(2, 3); // RX, TX
int senzorpin = A0;
int valoaresenzor;
TinyGsm modem(SerialAT);

BlynkTimer timer;
int min_notifications = 0 ;
int max_notifications = 0 ;
void setup()
{
  
  // Debug console
  Serial.begin(9600);

  delay(10);
  timer.setInterval(1000L, sensorDataSend);
  timer.setTimer(1000L, alarma_nivel , 3);
  timer.setTimer(1000L, nivel_recuperat, 1);
  // 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("Initializing modem...");


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

  Blynk.begin(auth, modem, apn, user, pass);
}

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

void sensorDataSend()
{
  valoaresenzor = analogRead(senzorpin);         // reading sensor from analog pin
  valoaresenzor = map(valoaresenzor, 200, 999 , 0, 10000 ); // maping 1-5V
  Blynk.virtualWrite(V0, valoaresenzor);  // sending sensor value to Blynk app
} 
void alarma_nivel()
 {
  if (valoaresenzor <= 2000)
    {
    Blynk.notify("Alarma nivel minim, Se incearca recuperarea");
    timer.restartTimer(int (nivel_recuperat));
    }  
 }
 void nivel_recuperat ()
 {
  if (valoaresenzor >= 2500) 
    {
    Blynk.notify("Nivel apa recuperata"); 
    timer.restartTimer(int (alarma_nivel));
    }
 }

This description of what you want to achieve…

makes no mention of delays between notifications, yet it appears that delays play a part in what you want to achieve.
Without fully understanding your overall goal, it’s difficult to advise further.

Probably a bad choice, but without understanding your goal it’s difficult to advise.

Pete.

My goal is to send 3 notifications if analog valuae is smaller than X and one notification if analog value is biger then Y!
This code worked well, if I removed “delay” then I only received one notification instead of five in Blynk app

LE: I think I need a break(delay) between notifications

 void sensorDataSend()
{
  valoaresenzor = analogRead(senzorpin);         // reading sensor from analog pin
  valoaresenzor = map(valoaresenzor, 200, 999 , 0, 10000 ); // maping 1-5V
  Blynk.virtualWrite(V0, valoaresenzor);  // sending sensor value to Blynk app
 
    if ((valoaresenzor <= 2000) && (min_notifications <=5))
    {
    Blynk.notify("Alarma nivel minim, Se incearca recuperarea");
    min_notifications ++ ;
    max_notifications = 0 ;
    delay (6000) ;
    }
    else if ((valoaresenzor >= 2500) && (max_notifications <= 1))
    {
    Blynk.notify("Nivel apa recuperata");
    max_notifications ++ ;
    min_notifications = 0 ;
    delay (2000) ;
    }
  }

Is it three, or is it five?

You need to work within the limitations of the Notifications system:

Limitations:

  • Maximum allowed body length is 120 symbols;
  • Every device can send only 1 notification every 5 seconds;

but changing the timer that controls how often your void sensorDataSend() function is called would resolve that without the need for delays or timeout timers.

Pete.

Ok. Now I understand. I modify the code its all right! Thank you sir

Code:

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

/* Fill-in your Template ID (only if using Blynk.Cloud) */
//#define BLYNK_TEMPLATE_ID   "Tanc Apa"


// Select your modem:
#define TINY_GSM_MODEM_SIM800
//#define TINY_GSM_MODEM_SIM900
//#define TINY_GSM_MODEM_M590
//#define TINY_GSM_MODEM_A6
//#define TINY_GSM_MODEM_A7
//#define TINY_GSM_MODEM_BG96
//#define TINY_GSM_MODEM_XBEE

// Default heartbeat interval for GSM is 60
// If you want override this value, uncomment and set this option:
#define BLYNK_HEARTBEAT 60

#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "Qzmb";

// Your GPRS credentials
// Leave empty, if missing user or pass
char apn[]  = "ipfix.vodafone.ro";
char user[] = "";
char pass[] = "vodafone";

// Hardware Serial on Mega, Leonardo, Micro
//#define SerialAT Serial1

// or Software Serial on Uno, Nano
#include <SoftwareSerial.h>
SoftwareSerial SerialAT(2, 3); // RX, TX

int senzorpin = A0;
int valoaresenzor;

TinyGsm modem(SerialAT);

BlynkTimer timer;

int min_notifications = 0 ;
int max_notifications = 1 ;

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

  delay(10);
  timer.setInterval(6000L, sensorDataSend);
  // 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("Initializing modem...");


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

  Blynk.begin(auth, modem, apn, user, pass);
}

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

void sensorDataSend()
{
  valoaresenzor = analogRead(senzorpin);         // reading sensor from analog pin
  valoaresenzor = map(valoaresenzor, 197, 1000, 0, 10000 ); // maping 1-5V
  Blynk.virtualWrite(V0, valoaresenzor);  // sending sensor value to Blynk app
    
    if ((valoaresenzor <= 2000) && (min_notifications <= 2)) 
    {
    Blynk.notify("Alarma nivel minim, Se incearca recuperarea");
    min_notifications ++ ;
    max_notifications = 1 ;
    
    }
    else if ((valoaresenzor >= 2500) && (max_notifications <= 1))
   {
    Blynk.notify("Nivel apa recuperata"); 
    max_notifications ++ ;
    min_notifications = 0 ;
   }
}

I have a curiosity! Can I make a voice call in parallel with Blynk?