Relay not working with Blynk code

• Hardware model + communication type : ESP01S-RELAY (ESP8266 based)
• Smartphone IOS 16.6.1
• Blynk server region : EU
• Blynk Library version : 1.3.2

Hello
I’m a blynk server user since manby years and i would like to evalutate the native cloud version of Blynk.
I’m trying to use a relay but it doesn’t work. The relay is never change his state (LOW - HIGH).
This is the code i use.
Mobile app is working fine, and i can see the ‘MARK’ in the text zone.
It seems it’s the digitalWrite than does’nt work but i don’t know why. I know we have to avoid delay(), but this code was working fine with my own Blynk Server.
Any ideas ?
Thanks in advance

#define PIN_TEXT V4
#define PIN_CONTACT V5
#define RELAY 0

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

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

BlynkTimer timer;

BLYNK_WRITE(PIN_CONTACT)
{
  int BTN = param.asInt();
     if (BTN == 1) {
     digitalWrite(RELAY, LOW);
     delay(2000);
     digitalWrite(RELAY, HIGH); 
     delay(2000);
     Blynk.virtualWrite(PIN_TEXT, "MARK");
     delay(2000);
     }
}

// This function is called every time the device is connected to the Blynk.Cloud
BLYNK_CONNECTED()
{
  // Change Web Link Button message to "Congratulations!"
  Blynk.setProperty(V3, "offImageUrl", "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations.png");
  Blynk.setProperty(V3, "onImageUrl",  "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations_pressed.png");
  Blynk.setProperty(V3, "url", "https://docs.blynk.io/en/getting-started/what-do-i-need-to-blynk/how-quickstart-device-was-made");
}

void setup()
{
  // Debug console
  Serial.begin(115200);

  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);

}

void loop()
{
  Blynk.run();
  Blynk.virtualWrite(PIN_TEXT, " ");
}

You need to IMMEDIATELY remove this from your void loop, it will be flooding the server.

Pete.

done. you’re right but it wasn’t a problem with my own server.

You can abuse your local server as much as you like, but you’ll get kicked-off the cloud servers if you break the rules.
In this case the rules are no more than ten Blynk.virtualWrites per second.

Your RELAY pin isn’t declared as an OUTPUT pin in void setup.

Pete.

You can abuse your local server as much as you like, but you’ll get kicked-off the cloud servers if you break the rules.

You’re right and i have to precise i’m not a crazy flooder :slight_smile:
But we act curiously when we are in trouble :slight_smile:

Your RELAY pin isn’t declared as an OUTPUT pin in void setup.

I added this instructions to my code, and it work fine now :

pinMode(RELAY, OUTPUT);

Thanks Pete !

1 Like

Hi JMA,

I’m also facing similar problem.
Please share the full the code to compare with mine?

@Ravikvrao it might be better if you started a new “need help with my project” topic and posted details of the hardware you are using, the code you are having problems with, and the results that you are seeing.

When you do this, take care to read the information that appears in your new topic before you delete it, especially the information about how to format code correctly.

Pete.