BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Blynk disconnet but arduino work

Hi there!

I have a issue with my project, blynk disconnect in long term like is running well between 1-4 days. After that i need to reset manual the arduino to get conneted to blynk.

NOTE: Arduino is controlling well the humidity without connected to blynk.

This project is a humidity controller for grow mushrooms.

Items List:

  • Arduino Uno
  • Relay module
  • Ethernet Shield
  • Sensor Shield v5 (to have better wiring for sensors)
  • 2 DHT22 Sensors

I use two sensors, one is just for reading and the other is for controlling humidity. The first sensor is wired 12m and the other 16m from the arduino. I use a electrovalve to control the water that goes in to mist system to reach humidity levels.

This code is based in @chrome1000 “ESP8266 HVAC control” project.

thanks for the support!

and sorry for my bad grammar ! :sweat_smile:

Blink dashboard:

Incubacion = Incubation room Temperature (red one)
Incubacion= Incubation room Humidity (green one)
Frutificacion= grow room Temperature(yellow one)
Seleccionar humedad deseada= Select desired humidity (Slider)
Humedad Frutificacion= grow room Humidity
Humedad Deseada= Selected Humidity

include <SPI.h>
#define BLYNK_PRINT Serial   
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <SimpleTimer.h>
#include <DHT.h>



char auth[] = "token";

SimpleTimer timer;

#define DHTPIN 5
#define DHTPIN1 3     
#define DHTTYPE DHT22
#define DHTTYPE1 DHT22
#define RelayPin 7
#define RelayPin2 8

DHT dht(DHTPIN, DHTTYPE);
DHT dht1(DHTPIN1, DHTTYPE1);

int HumDes = 85;
int PreviousHumDes = 85;
int HumAct = dht.readHumidity();
int HumCorrection = 0;
int UpdateFrequency = 5000L; 
float LastRead;

int Hysteresis = 2;

boolean FirstRead = true;
WidgetLED led1(V2);

void setup() 
{
  dht.begin();
  delay(2250);
  dht1.begin(); 
  delay(2250);

  pinMode(RelayPin,OUTPUT);
  digitalWrite(RelayPin,HIGH);
  
  pinMode(RelayPin2,OUTPUT);
  digitalWrite(RelayPin2,HIGH);
   
  Serial.begin(9600);
  delay(10);
  Blynk.begin(auth);
  Serial.println("Startup");
  Serial.println("");
  Serial.print("IP = ");
  Serial.println(Ethernet.localIP());
  
  timer.setInterval(UpdateFrequency, HumUpdate);
  
}

BLYNK_WRITE(V3){
  HumDes = param.asInt();
  Blynk.virtualWrite(V1,HumDes);
}


void HumUpdate()
{
{
  float ReadH = dht.readHumidity();
  float t = dht.readTemperature(); 
  float h1 = dht1.readHumidity();
  float t1 = dht1.readTemperature();
    
  Blynk.virtualWrite(V6, t);
  Blynk.virtualWrite(V7, h1);
  Blynk.virtualWrite(V8, t1);
    
  if (isnan(ReadH)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
    }
    
  if (FirstRead == true){
    HumAct = (int)(ReadH + HumCorrection);
    FirstRead = false;
    Serial.print("First humidiy reading (corrected): ");
    Serial.println(HumAct);
    LastRead = ReadH;
    return;   
  }
    
  else   { 
    int HumAvg = (int)((ReadH + LastRead + (2 * HumCorrection))/2);
    if (HumAvg >= HumAct + 1){
      HumAct = HumAct + 1;
    }
    if (HumAvg <= HumAct - 1){
      HumAct = HumAct -1;
    }

    LastRead = ReadH;
  }
  Blynk.virtualWrite(V0,ReadH); 
  Serial.print("Actual Humidity (corrected): ");
  Serial.println(HumAct);
    
    if (HumAct < HumDes){
      digitalWrite(RelayPin,LOW);
      led1.on();
      }
 
    else if (HumAct >= (HumDes + Hysteresis)) {
    digitalWrite(RelayPin,HIGH);
    led1.off();
    }
 
}
}

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

I’m thinking the ethernet.maintain(); is responsible for this, but I’m not sure. If I comment out that line it also compiles fine (and remove #include ethernet.h also). So I would suggest trying that and leave all the ethernet stuff to the Blynk library. It probably handles everything from there.

Also, I noticed that some ethernet boards can be really unstable. Which Ethernet board are you using?

1 Like

hi @Lichtsignaal

Thanks for the fasted response, here is the version of the ethernet shield i use:

ARDUINO ETH SHIELD 06 - Rev 03

image

I will tried today with your suggestion and give you some feedback of it!

1 Like

UPDATE:
It still disconneting, with the modification in the code. :disappointed_relieved:

Your sketch suggests you are using 4 pins on the Uno.
If this is the case I would order one of those super fast, high memory, plug and play ESP8266 development boards for $2.50.

2 Likes

Probably better than most of the Ethernet shields on the market, but that’s not really saying much.
After battling with these for a whild I eventually decided to take the plunge and go for a ESP8266 board to use instead of the Arduinio, which made the Ethernet shield redundant.
After a bit of wasted time/money I eventually settled ion the Wemos D1 Mini as my go-to board and haven’t touched an Arduino or those horrible Ethernet shields since.

Don’t be tempted to try using a Wi-Fi shield on the Auduino, or am ESP8266-01 as a Wi-Fi adapter for the Arduino, you’re wasting your time and money.

Pete.

2 Likes

@PeteKnight thanks for the advice and your fasted respond!!

hi @Costas !

Yes i´m using 4 pins of the arduino, two pins for the sensor, one for the relay who control the misting system and other to control manually a ultrasonic humidifier.

Do you mean a Wifi adapter like this?
image

or a wifi module like this?
image

@Costas I´m testing right now your sketch of “auto reset for blynk” hope this work. I will write the update.
https://community.blynk.cc/t/automatic-reset-if-blynk-not-connected/4264/3?u=ptydude

thanks a lot for the help!

Yes like that but Google WeMos D1 Mini.

No, no, no they are a waste of money.

1 Like

thanks!

Nooo!! Don’t use it as a Wi-Fi adaptor, use it instead of the Arduino. It has more memory and more processing power than the Arduino. With one of these (or preferably a Wemos D1 Mini) your Arduino and the Ethernet shield become an interesting paperweight.

Pete.

1 Like

Wemos D1 mini ordered! thanks for the advice @PeteKnight and @Costas.

I have just a little question about this:

11 digital input/output pins, all pins have interrupt/pwm/I2C/one-wire supported

Abstracted form “Wiki Wemos”>“D1 mini”>“Features”

Wemos DIgital pins can work like a “pwm Pin” from arduino? I´m asking this because i have wiring sensor cables in large distance, One have 16 meters and the other is 10 meters long.

With “pwm Pins” in arduino my sensors works great, I think that pins are 8 bytes signal.

According to this article:


the Arduino used 8 bit PWM and the Esp8266 uses 10 bit. What difference that would make in your scenario I have no idea.

The other thing to consider is that not all of the ESP8266 pins are actually usable in an everyday situation. A couple of them have ‘special’ uses and can cause issues when pulled high or low at boot-up, so are best avoided. I would have thought that in your case this won’t be a problem - though and as they only cost a few Pounds/Dollars/Euros each then you could give it a go anyway.

The other consideration is that as the Wemos devices are so small, and they use Wi-Fi, it might be possible for you to use multiple devices, one connected to each sensor, and have them physically located next to the sensor rather than using long wires to connect them. All you need it 5v of power for each device and if that would cause problems then you could maybe look at the threads on this forum about Deep Sleep and go for a battery powered option.

Pete.

2 Likes

@PeteKnight yes the “WeMos” is a great board and you missed off the other very useful feature of auto updates from thousands of miles away. Must add more of their shares to my investment portfolio (only joking) but for many users it’s a near perfect board for working with Blynk and iOT projects.

2 Likes

It’s starting to sound like a Monty Python sketch…
“Alright - so apart from Wi-Fi, more memory, a faster processor, smaller size, lower power consumption, lower cost and the ability to do OTA updates; what has the WeMos ever done for us?”. :grin::grin::grin:

Pete.

1 Like

Remember the sketch very well @PeteKnight