ERROR Too many links

Hi, first at all, sorry about my “english”
I have a problem with my project Blynk (Arduino Mega, connected by USB to my local server), need to change the state of a virtual pin to write the state of a digital pin.
I have this code in arduino:

widgetRiego void ()
if (digitalRead (pinRiego) == LOW) {
Blynk.virtualWrite (40, “Watering”); //if pinRiego(D52) is LOW, show “Watering” msg

} Else {
Blynk.virtualWrite (40, “Off”); //if pinRiego(D52) is HIGH, show “Off” msg

In Blynk App I set a button to on / off the digital pin 52 (pinRiego), and a Value Display on pin V40 to read the state (watering or off) with 3 sec interval.

Finally, I have in void setup:
timer.setInterval(3000L, widgetRiego);

When I press the button in the app to on/off the digital pin 52, works fine the first 2 or 3 attemps and then get the following error on my local server:

InOut(): GetOverlappedResult(EVENT_WRITTEN) ERROR Too many links (31)

If I delete the widgetRiego sentence, the button to on/off D52 pin works fine.
Sorry if it’s something very basic, but I’m just starting in this world.

Thanks a for this amazing community, has helped me a lot.

Is your Mega connected via Ethernet?

I believe by default Mega’s might have 32 V pins (0 to 31) but there is a flag you can set if you think it can handle more (like an ESP). Can’t remember what the flag is though. A thorough search of this site or the GitHub should find the flag unless @vshymanskyy can point it out to us.

Hi Costas! thanks for your quickly answer!
I have my arduino connected over USB, I didn’t know I could only use up to V31, I’ll change it to test
Thanks again, I will update with the results.

Maybe Mega does have the full 128 pins.

Found the flag for you.

//#define BLYNK_USE_128_VPINS
is in Blynk/BlynkConfig.h

Thanks a lot for your help!
i tried changing the VPins (under V31) and uncomenting the flag that you sent me, and something changed, but I still having issues.
I don’t have anymore the “Too many links” error, but after some clicks on my swtichs buttons, seems like I lost the connection (sensors doesn’t update the values, switch buttons doesn´t change the digital pins status, etc). and the only way to solve it, is restarting my arduino.
In short, I have the same issue, but now I don’t have the “too many links” error.
If I delete the arduino code to change the VPIN status, the switch buttons works fine everytime.
Any idea?

thanks a lot again!

Are you able to post your full code and formatted by highlighting the code and pressing the </> button?

There might be some issues we can identify in your sketch.

Thanks again! and sorry about my code…i’m very new in this world…
Also I upload screenshot of my app:

#include <SPI.h>
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX
#define BLYNK_PRINT DebugSerial

#include <SimpleTimer.h>
#include <BlynkSimpleStream.h>
#include <DHT.h>
#define DHTPIN_VF 42
#define DHTPIN_ES 40
#define DHTTYPE DHT22

#define pinRiego 52 // I have a button on blynk app to switch this pin on/off
#define pinLedE 50 // I have a button on blynk app to switch this pin on/off
#define pinServer 46

int pinCirculador = 12;
int pinIntractor = 11;

SimpleTimer timer; //

char auth[] = "token";

void widgetRiego() // Change the V4 with pinRiego (D52) status
  if (digitalRead(pinRiego)==HIGH) { 
     Blynk.virtualWrite(4, "Apagado");
  } else {
     Blynk.virtualWrite(4, "Regando");

void widgetLedE()  // Change the V5 with pinLedE (D50) status
  if (digitalRead(pinLedE)==HIGH) { 
     Blynk.virtualWrite(5, "OFF");
  } else {
     Blynk.virtualWrite(5, "ON");

void sendSensor() //send values of both DHT sensors to VPINS

 float h_VF = dhtVF.readHumidity();
 float t_VF = dhtVF.readTemperature();

 Blynk.virtualWrite(0, h_VF);
 Blynk.virtualWrite(1, t_VF);
 float h_ES = dhtES.readHumidity();
 float t_ES = dhtES.readTemperature();
 Blynk.virtualWrite(2, h_ES);
 Blynk.virtualWrite(3, t_ES);

if((t_VF >=26) && (t_VF <=30)) {           //set fans speed according temperature and write the status on V6
        if(t_VF <26) {
        if(t_VF >=31) {


void setup()
  // Debug console

  // Blynk will work through Serial
  Blynk.begin(auth, Serial);

 //set pinmode and starting state
  pinMode(48, OUTPUT);
      digitalWrite(48, HIGH);
  pinMode(46, OUTPUT);
      digitalWrite(46, LOW);
  pinMode(52, OUTPUT);
      digitalWrite(52, HIGH);
  pinMode(50, OUTPUT);
      digitalWrite(50, HIGH);
  pinMode(22, INPUT);
  pinMode(A8, INPUT);
  // start dht sensors      

    timer.setInterval(5000L, sendSensor);
    timer.setInterval(2000L, widgetRiego);
    timer.setInterval(2000L, widgetLedE);

void loop()
{;; // Initiates SimpleTimer



@Pancho I have looked through your code and I can’t see anything obviously wrong with it.

I checked some Mega settings and it looks like 128 virtual pins is the default in the App so I’m not sure if you needed to make the tweak to the library that I suggested.

All I can suggest is creating a sketch with all the VPIN stuff included and none of the DHT stuff i.e. turn some app and Mega onboard LED’s on and off etc.

If that works ok then the problem is somehow related to DHT. If it doesn’t work then we need to investigate the VPIN’s in more detail.