Still working on my first proper project and I’m stuck. Really sorry I wanted to figure this out for myself, I’ve spent 3 days going through this and I just can’t work out what I’m doing wrong, I’ve even spent 4hrs watching a C++ tutorial on Youtube which was very useful in what I’ve learned but hasn’t got me any further with this issue.
It’s a sketch to allow opening and of closing of garage doors, and that bit is working perfectly thanks to @PeteKnight, but now I’m trying to determine the open/close status of each door and display it via a virtual LED widget that changes colour. I’ve taken the Virtual LED example sketch and amalgamated it into my sketch, and added subroutines to determine the status and display it - except I haven’t. I’m obviously doing something fundamentally wrong because I can see from the serial monitor that these subroutines aren’t even being run. This is what I’ve got so far
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "do";
// Your WiFi credentials.
char ssid[] = "Vodaf";
char pass[] = "5il9v6";
WidgetLED led1(V3);
WidgetLED led2(V4);
BlynkTimer timer;
// constants won't change. They're used here to set pin numbers:
const int door1 = 4; // D2
const int door2 = 5; // D1
const int door1Status = 13; // D7
const int door2Status = 12; // D6
#define BLYNK_GREEN "#23C48E"
#define BLYNK_RED "#D3435C"
void setup()
{
pinMode(door1, OUTPUT);
pinMode(door2, OUTPUT);
pinMode(door1Status, INPUT);
pinMode(door2Status, INPUT);
digitalWrite(door1,LOW); // ensure relays not activated on power-on
digitalWrite(door2,LOW);
Serial.begin(74880);
led1.on(); // Turn LED widgets on
led2.on();
timer.setInterval(1000L, LED1Widget);
timer.setInterval(1000L, LED2Widget);
Blynk.begin(auth, ssid, pass); //connects to the blynk server using the credentals from above.
}
// Door 1 LED Widget
void LED1Widget()
{
if (door1Status) {
led1.setColor(BLYNK_GREEN);
Serial.println("LED on V3: green");
} else {
led1.setColor(BLYNK_RED);
Serial.println("LED on V3: red");
}
}
// Door 2 LED Widget
void LED2Widget()
{
if (door2Status) {
led2.setColor(BLYNK_GREEN);
Serial.println("LED on V4: green");
} else {
led2.setColor(BLYNK_RED);
Serial.println("LED on V4: red");
}
}
BLYNK_WRITE(V1)
{
if (param.asInt() == 1) // DOOR 1 MODULE
{
digitalWrite(door1, HIGH); //Close the relay
Serial.println("Relay 1 Activated");
delay(500);
digitalWrite(door1, LOW); //Release the Relay
Serial.println("Relay 1 Deactivated");
Serial.println("");
}
}
BLYNK_WRITE(V2)
{
if (param.asInt() == 1) // DOOR 2 MODULE
{
digitalWrite(door2, HIGH); //Close the relay
Serial.println("Relay 2 Activated");
delay(500);
digitalWrite(door2, LOW
); //Release the Relay
Serial.println("Relay 2 Deactivated");
Serial.println("");
}
}
void loop()
{
Blynk.run();
}