LED Widget, Virtual Pin and ESP8266

Hi, I am trying have 2 way control system i.e., One LED connected at GPIO 0 and One Switch connected at GPIO 2 of ESP8266. I want to ON/ OFF the ESP LED using my Android and similarly control Blynk’s (V PIN) LED using the Switch at the ESP. This is my Code and it works fine to ON/ OFF the LED of ESP. But I am not able to control Blynks V PIN LED. Request Someone to correct my code below to resolve this problem.

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


char auth[] = "d987d7b61931416a9xxxxxxxxxxxxxxx";
int swpin = 2;

void setup()
{
  pinMode(swpin, INPUT);
  Serial.begin(9600);
  Blynk.begin(auth, "SSID", "password");
  
}

void loop()
{
    int val=digitalRead(swpin);
if(val= HIGH)

{
Blynk.virtualWrite(1, LOW);
}
else {
     
      Blynk.virtualWrite(1, HIGH);
      }
  Blynk.run();
}

1 Like

You should use BLYNK_WRITE() function to accomplish what you want:

    BLYNK_WRITE(1) // VirtualPin 1
    {
      int getValue = param.asInt(); // Get the value from VPin 1 (could also be a slider)
    }

Also see the Blynk Examples with GetData and PushData

1 Like

Use LED Widget

WidgetLED led(V?);

led.on();

led.off();