Hi,
The code below is used for controlling the inbuilt LED and a relay board connected to pin DO using the ESP8266 and Blynk. Everything works fine except that during reboot, both the inbuilt LED and the relay board are turned on without any activation from the Blynk app.
To troubleshoot the issue, the code attempted to set the relay pin to low using digitalWrite(relayPin, LOW), and added a logic flag using if and else statements after updating the Blynk state as follows:
int ledState = param.asInt();
if(ledState==0)
else(Ledstate ==0)
However, despite these changes, the inbuilt LED and port pin are still set to high during boot without activation from Blynk. Can you please help to solve this problem?
code:
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "---"; // Blynk auth token
char ssid[] = "---"; // WiFi SSID
char pass[] = "----"; // WiFi password
int relayPin = D0;
void loop()
{
Blynk.run();
}
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode(LED_BUILTIN, OUTPUT);
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin,LOW);
}
BLYNK_WRITE(V0)
{
int ledState = param.asInt();
if(ledState==1)
{
digitalWrite(LED_BUILTIN,HIGH);
digitalWrite(relayPin,HIGH);
}
else if (ledState==0)
{
digitalWrite(LED_BUILTIN,LOW);
digitalWrite(relayPin,LOW);
}
}