#define BLYNK_PRINT Serial
// Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#define WIFI_SSID "" //Enter your network ssid
#define WPA_PASSWORD "" //Enter your wifi password
// Auth Token for the Blynk App.
char auth[] = ""; //Your Blyny auth code
int DoorPin_1 = 1; //relay pin 1 to esp8266 - 01 model gp0 pin in app
int DoorPin_2 = 2; //relay pin 2 to esp8266 - 01 model gp2 pin in app
//Time Object
SimpleTimer timer;
//Set Door Pin to HIGH/LOW
BLYNK_WRITE(V1)
{
pinMode( DoorPin_1, OUTPUT);
if(digitalRead( DoorPin_1) == LOW)
{
digitalWrite( DoorPin_1, HIGH);
Serial.print("Pin set to HIGH");
}
else
{
digitalWrite( DoorPin_1, LOW);
Serial.print("Pin set to LOW");
}
pinMode( DoorPin_1, INPUT);
}
BLYNK_WRITE(V2)
{
pinMode( DoorPin_2, OUTPUT);
if(digitalRead(DoorPin_2) == LOW)
{
digitalWrite( DoorPin_2, HIGH);
Serial.print("Pin set to HIGH");
}
else
{
digitalWrite( DoorPin_2, LOW);
Serial.print("Pin set to LOW");
}
pinMode( DoorPin_2, INPUT);
}
//Try reconnecting to Blynk
void reconnectBlynk()
{
if (!Blynk.connected())
{
if (Blynk.connect())
{
Serial.print("Blynk Reconnected");
}
else
{
Serial.print("Blynk Not reconnected");
}
}
}
void setup()
{
Serial.begin(9600); // See the connection status in Serial Monitor
Blynk.begin(auth, "", ""); //insert here your SSID and password
while (Blynk.connect() == false)
{
// Wait until connected
}
Serial.print("Blynk Setup");
// Setup a function to do reconnection attempts once a minute
timer.setInterval(60000, reconnectBlynk);
}
void loop()
{
// Initiates Blynk Connection
if (Blynk.connected())
{
Blynk.run();
}
timer.run(); // Initiates SimpleTimer
}
2 Likes
looks nice and neat and simple - will it control a solenoid?
I think it will work.
what does your phone app look like?
Only consider button ok
Only consider button ok
see my other project
Can you show the circuit?
Please note timestamps before posting… this is an old post and simple ESP-01 to relay wiring diagrames are readily available via Google.