Depending on what you mean by “i turn the relay”… If by switching the widget it should work, if by the timer function then you need to add a command to do so
When i think about it, i only want the green led to light up when the relay shuts down automaticly with timer. When i press the button in app for turning the relay off manually, i do not wnt the greenLED to light up.
Actually, you only need this in your timer function to do the same job that manually pressing the button does…
void coffeeOFF() {
Blynk.virtualWrite(V1, LOW); // Sets the virtual pin state
Blynk.syncVirtual(V1); // runs the vPin function to process the last set state
}
However, that will do everything the manual command does…
I would add in some Serial.println("this thing happened") type statements so you can follow your code progress through the Serial monitor… best way to troubleshoot if what you think is happening… is or isn’t happening.
I changed pin to D7 (GPIO 13) and same problem appears. The greenLED flicker one time and shuts off when i push the button in app to turn off relay or it turns off automaticly with timer.
This is the code i tried with:
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
//Put WiFi cridentials and token here----------------------------------
char auth[] = "****";
char ssid[] = "****";
char pass[] = "****";
//---------------------------------------------------------------------
int coffeeSwitch = 5;
int yellowLED = 4;
int greenLED = 13;
int ledStatus;
BlynkTimer timer;
void setup() {
Blynk.begin(auth, ssid, pass);
Serial.begin(9600);
pinMode(coffeeSwitch, OUTPUT);
digitalWrite(coffeeSwitch, HIGH);
pinMode(yellowLED, OUTPUT);
pinMode(greenLED, OUTPUT);
}
BLYNK_CONNECTED() {
Blynk.syncVirtual(V1);
}
void coffeeOFF() {
Blynk.virtualWrite(V1, LOW); // Sets the virtual pin state
Blynk.syncVirtual(V1); // runs the vPin function to process the last set state
}
BLYNK_WRITE(V1) {
int pinValue = param.asInt();
if (pinValue == 1) {
digitalWrite(coffeeSwitch, LOW);
digitalWrite(yellowLED, HIGH);
digitalWrite(greenLED, LOW);
timer.setTimeout(5000L, coffeeOFF);
}
if (pinValue == 0) {
digitalWrite(coffeeSwitch, HIGH);
digitalWrite(yellowLED, LOW);
digitalWrite(greenLED, HIGH);
}
}
void loop() {
Blynk.run();
timer.run();
}
Possible rebooting is only thing I can think of that matches description of flashing LED then OFF issue… Serial Monitor output will confirm or deny that.
BTW, do the Yellow LED and relay turn ON and OFF as planned??
Lots of things can cause reboots… power brownouts, code issues, possibly even coil feedback from the relay (but probably not that if you are using a relay board with inverting opto isolator chip) … but once you can, a few Serial prints and watching the Serial monitor will help show what is actually happening.