Untitled

 avatar
unknown
plain_text
3 years ago
1.2 kB
14
Indexable
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// Replace with your Blynk auth token
char auth[] = "YourAuthToken";

// Replace with your WiFi credentials
char ssid[] = "YourSSID";
char pass[] = "YourWiFiPassword";

// Digital pins for the relays
const int relay1 = D1;
const int relay2 = D2;

void setup()
{
  // Set the digital pins as output
  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);

  // Connect to WiFi
  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }

  // Connect to Blynk
  Blynk.begin(auth, ssid, pass);
}

void loop()
{
  Blynk.run();
}

BLYNK_WRITE(V1)
{
  // Read the value of the virtual pin V1
  int relay1Value = param.asInt();

  // Set the state of the relay based on the value of V1
  if (relay1Value == 1)
  {
    digitalWrite(relay1, HIGH);
  }
  else
  {
    digitalWrite(relay1, LOW);
  }
}

BLYNK_WRITE(V2)
{
  // Read the value of the virtual pin V2
  int relay2Value = param.asInt();

  // Set the state of the relay based on the value of V2
  if (relay2Value == 1)
  {
    digitalWrite(relay2, HIGH);
  }
  else
  {
    digitalWrite(relay2, LOW);
  }
}
Editor is loading...