Arduino Nano with SIM800L cannot handle 3rd virtual pin

• Hardware model + communication type: Arduino Nano with SIM800L GSM module

• Blynk server region :fra1
• Blynk Library version : latest

The following code works great. However, the device gets disconnected when I uncomment BLYNK_WRITE(V4) logic and tries to reconnect on blynk.cloud:80. What might cause this issue?
The V4 datastream is an integer with values 0-1 same as V0 which works fine

/*************************************************************
  Attention! Please check out TinyGSM guide:
    https://tiny.cc/tinygsm-readme

  Change GPRS apm, user, pass, and Blynk auth token to run :)

  You’ll need:
   - Blynk IoT app (download from App Store or Google Play)
   - Arduino Nano board
   - Decide how to connect to Blynk
     (USB, Ethernet, Wi-Fi, Bluetooth, ...)

  There is a bunch of great example sketches included to show you how to get
  started. Think of them as LEGO bricks  and combine them as you wish.
  For example, take the Ethernet Shield sketch and combine it with the
  Servo example, or choose a USB sketch and add a code from SendData
  example.
 *************************************************************/

/* Fill-in information from Blynk Device Info here */
#define BLYNK_TEMPLATE_ID "tpl"
#define BLYNK_TEMPLATE_NAME "name"
#define BLYNK_AUTH_TOKEN "token"

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

#define TINY_GSM_MODEM_SIM800

// 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>

// Your GPRS credentials
// Leave empty, if missing user or pass
char apn[] = "internet";
char user[] = "";
char pass[] = "";
///////////////////////////////PHOTO RESISTORS///////////////////////////////////////
// Pin definitions
const int photoResistorPins[4] = { A0, A1, A2, A3 };  // Photoresistor analog input pins
const int numSensors = 4;                             // Number of sensors

// Variables to store ambient light levels for each sensor
int ambientLight[numSensors];

// Variables to store current sensor values
int currentLight[numSensors];

int sensitivityThreshold = 200;
int wifiDetectorEnabled =0;
// Time interval for recalibrating ambient light
const unsigned long recalibrationInterval = 10000;  // 10 seconds
const unsigned long suddenLightChangeInterval = 100;

/////////////////////////////////////////////////////////////////////////////////////

#include <SoftwareSerial.h>
SoftwareSerial SerialAT(6, 5);  // RX, TX

TinyGsm modem(SerialAT);
BLYNK_WRITE(V0) {
  uint8_t value = param.asInt();
  // any code you place here will execute when the virtual pin value changes
  Serial.print("Blynk.Cloud is writing something to V0: ");
  Serial.println(value, DEC);
  digitalWrite(LED_BUILTIN, value);
}
BLYNK_WRITE(V1) {
  uint8_t value = param.asInt();
  // any code you place here will execute when the virtual pin value changes
  Serial.print("Blynk.Cloud is writing something to V1: ");
  Serial.println(value, DEC);
  sensitivityThreshold = value;
}
//BLYNK_WRITE(V4) {
//  uint8_t value = param.asInt();
//  // any code you place here will execute when the virtual pin value changes
//  Serial.print("Blynk.Cloud is writing something to V4: ");
//  Serial.println(value, DEC);
//  wifiDetectorEnabled = value;
//}

void lightChangeEvent() {

  // Read current light levels and check for sudden changes
  for (int i = 0; i < numSensors; i++) {
    currentLight[i] = analogRead(photoResistorPins[i]);

    // Calculate the difference between current light and ambient light
    int lightDifference = abs(currentLight[i] - ambientLight[i]);

    // If the difference exceeds the threshold, print a detection message
    if (lightDifference > sensitivityThreshold) {
      Serial.print("Sudden light change detected on sensor ");
      Serial.print(i);
      Serial.print("! Light difference: ");
      Serial.println(lightDifference);
      Blynk.virtualWrite(V0, 0);  //switch off speaker relay
      digitalWrite(LED_BUILTIN, 0);
      Blynk.logEvent("speaker_off");  // send notification to phone
    }
  }
}
void recalibrationEvent() {
  Serial.println("Recalibrating ambient light levels...");
  for (int i = 0; i < numSensors; i++) {
    ambientLight[i] = analogRead(photoResistorPins[i]);
  }
  // Print new ambient light levels for debugging
  Serial.println("New Ambient Light Levels:");
  for (int i = 0; i < numSensors; i++) {
    Serial.print("Sensor ");
    Serial.print(i);
    Serial.print(": ");
    Serial.println(ambientLight[i]);
  }
  String ambient;
  for (int i = 0; i < numSensors; i++) {
    ambient += (String)ambientLight[i] + " ";
  }
  Blynk.virtualWrite(V2, ambient);
}
BlynkTimer timer;

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);  //LED output
  // Debug console
  Serial.begin(115200);

  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("1234");

  Blynk.begin(BLYNK_AUTH_TOKEN, modem, apn, user, pass);
  timer.setInterval(recalibrationInterval, recalibrationEvent);
  timer.setInterval(suddenLightChangeInterval, lightChangeEvent);
  for (int i = 0; i < numSensors; i++) {
    ambientLight[i] = analogRead(photoResistorPins[i]);
  }

  // Print initial ambient light levels
  Serial.println("Initial Ambient Light Levels:");
  for (int i = 0; i < numSensors; i++) {
    Serial.print("Sensor ");
    Serial.print(i);
    Serial.print(": ");
    Serial.println(ambientLight[i]);
  }

}

void loop() {
  Blynk.run();
  timer.run();
  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!
}

Version number?

It would help if you explained the problem in detail.

Pete.

Hi Pete. Thank you for your reply. Version number is 1.3.2

The code works fine as soon as I am not using the commented code for V4.

The project is about remote controlling a solid state relay remotely through gsm. I can remotely turn on and off the relay. There are also 4 photo resistors attached that read ambient light and recalibrate. When a rapid change in light occurs in any of the 4 photo resistors, the solid state relay is turned off and i receive a notification. I can manually turn it on through the blynk mobile app.

Now, i need another virtual pin V4 which is attached to a blynk switch and record its value to a global variable. However when i uncomment the section about Blynk_write(v4) it gets disconnected and tries to reconnect without success

What does your serial monitor show when this happens?

With your working code, what board type is shown when you see the Blynk splash screen in the serial monitor?

What happens if you add:

#define BLYNK_USE_128_VPINS

near the top of your sketch?

Pete.

thank you pete for your response. I’ll paste here the output of serial monitor when the v4 is commented and works fine and when is added to the sketch and fails when I get home. i will also try the #define BLYNK_USE_128_VPINS. I only have 4 virtual pins, will this help in any way?

.

@stefanos please edit your post and add triple backticks at the beginning and end of your serial output.

Pete.

Below code when V4 section is commented

Initializing modem...
[10427] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v1.3.2 on Arduino Nano

 #StandWithUkraine    https://bit.ly/swua

[10439] Modem init...
[10559] Connecting to network...
[26229] Network: Vodafone
[26230] Connecting to internet...
[32135] Connected to GPRS
[32177] Connecting to blynk.cloud:80
[33257] Ready (ping: 261ms).
Initial Ambient Light Levels:
Sensor 0: 766
Sensor 1: 838
Sensor 2: 988
Sensor 3: 832
Recalibrating ambient light levels...
New Ambient Light Levels:
Sensor 0: 768
Sensor 1: 840
Sensor 2: 990
Sensor 3: 833
Recalibrating ambient light levels...
New Ambient Light Levels:
Sensor 0: 768
Sensor 1: 842
Sensor 2: 990
Sensor 3: 834
Blynk.Cloud is writing something to V0: 1
Blynk.Cloud is writing something to V0: 0
Recalibrating ambient light levels...
New Ambient Light Levels:
Sensor 0: 752
Sensor 1: 823
Sensor 2: 966
Sensor 3: 812
Blynk.Cloud is writing something to V1: 67

Below code when V4 section is included with #define BLYNK_USE_128_VPINS

    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v1.3.2 on Arduino Nano

 #StandWithUkraine    https://bit.ly/swua


[8800] Modem init...
[8919] Connecting to network...
[15007] Network: Vodafone
[15007] Connecting to internet...
[24152] Connected to GPRS
[24194] Connecting to blynk.cloud:80
[26013] Ready (ping: 538ms).
[31034] Connecting to blynk.cloud:80
[32115] Ready (ping: 245ms).
[37137] Connecting to blynk.cloud:80
[38217] Ready (ping: 260ms).
[43238] Connecting to blynk.cloud:80

have you tried to add BLYNK_Write(V4) as an empty function iso commenting it completely out?

No i havent tried v4 on its own but it seems that an addition of any additional virtual pin is the issue. I let v4 commented and added a slider on v5 an i have the same result.
I copied the code to another sketch and set it up on legacy custom server with blynk version 0.61 and works fine. I have some reconnections but at the end works. It seems something triggers the blynk cloud to block it. When i use blynk debug i get a cmd error message if thst helps