Arduino and SIM800 does not reconnect when cell is lost

Hello everybody

I would need help with my arduino - SIM800 project.
I’ve tried to search anywhere and it seems I can only find some similar issue but not exactly the same as I would need.
I am using Blynk IoT (and not the old Blynk)

The issue is that basically it works for 6-7 hours then it disconnects (I believe from the network) and the code starts to loop trying to connect to Blynk server but not able to reconnect to internet.
If I reset the modem or the arduino he restarts to work.
Since I know it disconnects every 6-7 hours I’ve tried to setup a timer that resets every 5 hours and it works but I don’t like this way.
It must be a way to detects that it’s not connected and reconnects automatically.

Could you please help?

//Blynk setup
#define BLYNK_TEMPLATE_ID           "ciao"
#define BLYNK_DEVICE_NAME           "ciao"
#define BLYNK_AUTH_TOKEN            "ciao"
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space

//DHT setup
#include <DHT.h>
#define DHTPIN 7     // what pin we're connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302)
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino

// Cellular setup:
#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>

//data manipulation 
String signalS;
int signalRSSI;

// Set serial for debug console (to the Serial Monitor, default speed 115200)
#define SerialMon Serial

// Hardware Serial on Mega, Leonardo, Micro
#ifndef __AVR_ATmega328P__
#define SerialAT Serial2

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

// Your GPRS credentials, if any
const char apn[]  = "simbase";
const char user[] = "";
const char pass[] = "";

char auth[] = BLYNK_AUTH_TOKEN;

TinyGsm modem(SerialAT);
BlynkTimer timer;

void setup()

  timer.setInterval(300000L, sendSensor); // 5 minutes
  timer.setInterval(300000L, signalStrenght); // 5 minutes
  // Set console baud rate

  // Set GSM module baud rate

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

  String modemInfo = modem.getModemInfo();
  SerialMon.print("Modem Info: ");

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


void sendSensor() {
    float h = dht.readHumidity();
    float t = dht.readTemperature();
    // Please don't send more that 10 values per second.
    // humidity is V1 and temperature is V0
    Blynk.virtualWrite(V1, h);
    Blynk.virtualWrite(V0, t);


void signalStrenght() {

 signalS = modem.getSignalQuality( );
 signalRSSI = signalS.toInt();
 Blynk.virtualWrite(V2, signalRSSI*3);

void loop()

not everybody at the same time please ahahah :slight_smile:

Have you tried the AT commands ?

You can connect to the APN using modem.gprsConnect(apn, user, password) and check if Modem is connected with modem.isNetworkConnected().

Use them in your code.

Check the TinyGSM library and you will see several tools to help you with your connection management.