I changed by code, first I need to control the relays just using the blynk app.So the changed code is as follows:
#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).
char auth = “my auth code”;
// Your WiFi credentials.
// Set password to “” for open networks.
char ssid = “wifi”;
char pass = “wifi passwd”;
const int Relay_1 = D1;
const int Relay_2 = D2;
void setup()
{
pinMode(Relay_1, OUTPUT);
pinMode(Relay_2, OUTPUT);
digitalWrite(Relay_1, HIGH);
digitalWrite(Relay_2, HIGH);
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
}
void loop()
{
Blynk.run();
}
/********************** Relay 1 ON/OFF V1 *******************************/
BLYNK_WRITE(V1)
{
int pinValue = param.asInt();
if (pinValue == 1)
{
digitalWrite(Relay_1, LOW);
Serial.println(“Relay 1 On”);
}
else if (pinValue == 0)
{
digitalWrite(Relay_1, HIGH);
Serial.println(“Relay 1 Off”);
}
}
/********************** Relay 2 ON/OFF V2 *******************************/
BLYNK_WRITE(V2)
{
int pinValue = param.asInt();
if (pinValue == 1)
{
digitalWrite(Relay_2, LOW);
Serial.println(“Relay 2 On”);
}
else if (pinValue == 0)
{
digitalWrite(Relay_2, HIGH);
Serial.println(“Relay 2 Off”);
}
}
Still, the problem persists, whenever I’m clicking on the button widget, the project disconnects. But, I’m getting the serial prints but there is no change in the relays.
Heres the serial monitor output :
[57] Connecting to xxxx
[1061] Connected to WiFi
[1061] IP: xxxxxxx
[1061]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ / '/
///_, /////_
/__/ v0.6.1 on NodeMCU
[1138] Connecting to blynk-cloud.com:80
[1709] Ready (ping: 261ms).
Relay 2 Off
Relay 1 Off
Relay 2 On
Relay 1 On
Relay 2 Off
Relay 1 Off