ESP8266 Witty Cloud with relay, always stays On

• Hardware model + communication type. ESP8266 Witty Wifi Cloud, Low level Trigger 1CH relay board
• Smartphone OS (iOS or Android) + version: Android 8.0
• Blynk server or local server: Blynk server
• Blynk Library version : Latest
• Add your sketch code.


#define BLYNK_PRINT Serial

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

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

// Your WiFi credentials.
// Set password to "" for open networks.
const char ssid[] = "xxxxxx";
const char pass[] = "yyyyy";
int relay = 5;

BLYNK_WRITE(V5)
{
  pinMode(relay, OUTPUT);
  if (digitalRead(relay) == LOW)
  {
    digitalWrite(relay, HIGH);
    Serial.print("Pin set to HIGH");
  }
  else
  {
    digitalWrite(relay, LOW);
    Serial.print("Pin set to LOW");
  }
  pinMode(relay, INPUT);
}

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

  Blynk.begin(auth, ssid, pass);
// You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);

  pinMode(led, OUTPUT);
}

void loop()
{
  // Initiates Blynk Connection
  if (Blynk.connected())
  {
    Blynk.run();
  }
 }

After uploading the sketch, disconnected the ESP8266 module from the bottom board. Connected the relay IN pin to the GPIO05 on the board, and the VCC/GND of relay, are connected to external power of 5V. Below are the screenshots of Blynk App project.

The issue I’m facing is that the relay just stays on, after I press the run on app. Basically the voltage on the GPIO05 pin remains at 3.3 V, which seems to be insufficient for the relay to register a HIGH to switch off. But surprisingly, when I just connect the board and relay to power, initially, the relay is Off, which means it’s getting 5v somehow to register a HIGH. But this becomes a LOW when I execute from Blynk App and then the button press on the app does no affect at all. the Relay just stays On.

Any ideas on what am I missing here? Is there anything missing in the code, or the hardware setup?

Start with removing the pinMode in the BLYNK_WRITE. This is usually done in setup(), but it has no function whatsoever, worse, I think it’s your problem :wink:

Thanks for the tip, but unfortunately, It’s still not working. Now, the relay stays Off, though. Never turns On, when operating the button from the app.
I made the following changes to the code:

#define BLYNK_PRINT Serial

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

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

// Your WiFi credentials.
// Set password to "" for open networks.
const char ssid[] = "xxxxxxx";
const char pass[] = "yyyyyy";
int led = 13;
int relay = 5;

BLYNK_WRITE(V1)
{
  if (digitalRead(relay) == LOW)
  {
    digitalWrite(relay, HIGH);
    Serial.print("Pin set to HIGH");
  }
  else
  {
    digitalWrite(relay, LOW);
    Serial.print("Pin set to LOW");
  }
}

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

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);

  pinMode(led, OUTPUT);
}

void loop()
{
  // Initiates Blynk Connection
  if (Blynk.connected())
  {
    Blynk.run();
  }
}

Also changed the app settings accordingly:


Anything else I should change?

Made some more changes to the setup(), and now the relay again went back to staying On…
Still can’t turn off from the app…

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

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);

  pinMode(led, OUTPUT);
  pinMode(relay, OUTPUT);
  digitalWrite(relay, HIGH);
}

If GPIO5 the right pin to connect the IN pin of the relay, according to the code?
(PS: I’m using NodeMCU1.0 as the board in Arduino IDE.)

I see it :slight_smile:

BLYNK_WRITE(V1)
{
  int status = param.asInt();
  digitalWrite(relay) == status;
}

I looked over the fact you have to catch the parameter from the button. And that is done like in this code.

Sorry, I’m not sure I followed you here. The second line looks like a condition with ==.
Was it a typo?

Assuming that was a typo, I wrote the method like this:

BLYNK_WRITE(V1)
{
  int status = param.asInt();
  digitalWrite(relay, status);
}

But still no improvement :frowning:. The relay still remains On, and can’t switch Off from the app.

No, = means assigning a value to a parameter. == is a conditional statement.