Active Relay causes Blynk to disconnect

what psu are you using? did you try with a different psu?

The vast majority of Blynkers (including myself) use ESP8266s and relays on a daily basis and don’t experience any problems with disconnection when the relay is activated.

It’s important to use decent onto-isolated relays that are powered by a good quality PSU that’s wired correctly (not taking its power via the ESP.

In my experience, most Blynk disconnection issue are the result of bad coding, including failure to use timers when interrogating temperature and humidity sensors.
If you have a piece of code that’s being executed in every void loop cycle, which checks the temperature/humidity readings - possibly using a small delay to allow the sensor time to recover between readings - then you might get get away with this without experiencing Blynk disconnections. However, as soon as the criteria are met that requires the relay to be activated, the code will have other instructions to process, including activating the relay and probably changing the state of some variables. In this scenario, the Blynk.run process is already being ‘starved’ of processor time by the badly written void loop and the additional bit of processing needed to run the relay activation routine will be the ‘straw that breaks the camels back’, causing a disconnection.

Switching to a faster processor (from Arduino to ESP8266 or up again to ESP32) or simply compiling the code to use a faster processor clock speed, may alleviate the symptoms in the short term. This is because you’re allowing more processing to be done between Blynk heartbeats, but it’s not a long-term solution to the problem.

If your code is well-written and you’re using good quality relays and PSUs then it would be worth monitoring Wi-Fi signal strength and looking at whether the thing that’s being switched by the relay is causing interference which is causing the Wi-Fi signal to drop-out (an easy way to test is to remove the load from the relay and see if the problem persists). Things like mai s operated central heating pumps and motorised valves may need a suitable capacitors across their Line and Neutral terminals to reduce EMF interference.

Pete.

1 Like

i had to use pairs of MOV’s across the relay contacts to solve this issue with my 24VAC damper motors…

Has the relay been optically isolated? If not, that could be the issue. You can buy relay boards with Optcouplers on them, I’d advise those any case, just to be on the safe side. You are switching mains supply with those tiny things, so a bit of isolation is actually mandatory :slight_smile:

Use a transistor 2222 tun conect realy

hello,
I think it’s probably an EMC problem when the relay is switched on: is there a diode on the relays solenoid to reduce the overvoltage on power supply or it’s genarated by the switched load (FAN) ??

THIS is the problem, I’m almost 100% sure of that.

So many assumed solutions to a “problem” that hasn’t even been clarified, by a user that hasn’t returned to the forum since the initial post :stuck_out_tongue: Too Funny :rofl:

1 Like

Well, probably he found the problem or he forget the project, but brown out problems are coming normally from a defective PSU or solenoids without diode… this is a must known in electronics.

1 Like

The OP never mentioned brown out… rather that fan and relay works, but Blynk disconnects… and also connecting using USB indicates an Arduino and USB link that is possibly failing not necessarily power… but again, without clarification we could all just as easily assume a dozen other issues.

Ok, I’m back from a long week in the great outdoors!! Thanks for all of the comments, I am pouring through them now. If I had to guess, even if the issue isn’t just bad code, I will guess my potentially bad code, (posted below), isn’t helping matters. It is basically a bunch of sample code that I have slapped together to start learning, so constructive criticism is more than welcome.

Thank you.

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

#include <SoftwareSerial.h>
SoftwareSerial SwSerial(10, 11); // RX, TX
int valvePIN = 9;
int fanPIN = 8;    
#include <BlynkSimpleStream.h>
#include <DHT.h>

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

#define DHTPIN 2          // What digital pin we're connected to

// Uncomment whatever type you're using!
#define DHTTYPE DHT11     // DHT 11
//#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21   // DHT 21, AM2301

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{  
  const int MOISTURE_LEVEL =500;
  float h = dht.readHumidity();
  float t = dht.readTemperature(true); // or dht.readTemperature(true) for Fahrenheit
  int m = analogRead(A0);
  if (isnan(h) || isnan(t)){
    SwSerial.println("Failed to read from DHT sensor!");
    return;
  }
  if (isnan(m)){
    SwSerial.println("Failed to read from Moisture Sensor!");
    return;
  }  
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, h);
  Blynk.virtualWrite(V6, t);
  Blynk.virtualWrite(V7, m);
  //Blynk.virtualWrite(V8, valvePIN);
  Blynk.virtualWrite(V9, fanPIN);

    if(m > MOISTURE_LEVEL)
  {
    Blynk.setProperty(V7, "color", "#D3435C");
    digitalWrite(fanPIN, HIGH);
  }
  else 
  {
    Blynk.setProperty(V7, "color", "#23C48E");
    digitalWrite(fanPIN, LOW);
  }

     if(t > 69)
  {
    //Blynk.setProperty(V8, "color", "#23C48E");
    digitalWrite(fanPIN, LOW);
    delay(30000);
  }
  else 
  {
    //Blynk.setProperty(V8, "color", "#D3435C");
    digitalWrite(fanPIN, HIGH);
  } 

}

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

  // Blynk will work through Serial
  // Do not read or write this serial manually in your sketch
  Serial.begin(9600);
  Blynk.begin(Serial, auth);

  pinMode(valvePIN, OUTPUT);
  digitalWrite(valvePIN, LOW);
  pinMode(fanPIN, OUTPUT);
  digitalWrite(fanPIN, HIGH);

  dht.begin();

  // Setup a function to be called every second
  timer.setInterval(1000L, sendSensor);
}

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

Not sure if this is turning ON or OFF the fan, but a 30 second delay either way will most definitely trigger Blynk’s 10 second heartbeat timeout :stuck_out_tongue: And also blocks all other code from running.

1 Like

yup, it’s not a brown out :rofl:

I had problem like that. I use relay board with 8 relays. Power comes from different power supply to relays. also i added diodes and transistors to activate relays.

If i run single relay, no problem. When i run 8 relays at the same time, i lost connection. I figured it out, that was a electromagnetic field problem. I isolated my relays with alluminium and grounded that.

Also changing high power cables with coaxial type may be helpful.

@yilmazyurdakul to keep this topic from further red herrings… this OP issue is NOT power or interference related. just bad code. :stuck_out_tongue:

1 Like

Ha ha, I will concede to the “bad code” diagnosis… On that note, how do I go about telling the the relay to go active for a set amount of time without interrupting the blynk communications?

Thanks

Timers… particularly a timeout timer should work

http://playground.arduino.cc/Code/SimpleTimer#F_setTimeout

Yeah. I know that but i wanted to share my experience. I love this community and i want to be helpful but you are right. This post is not related :smiley:

I use a 2N7000 transistor to fix it. It works right afther 40 seconds

A post was split to a new topic: Problems operating relay