Why does not green led turns on?

Oh my good I have checked and tested now, and the problem was as i suspected. I had not connected the ground from Wemos to the ground rail on breadboard.

:rofl:

1 Like

With your current code that uses the Blynk.syncVirtual(V1); this will not be the case. As you are essentially just setting the button to off, then triggering the command that would simulate manually pushing it. I would maybe try the approach of deleting the timer if the button is pressed before it finishes.

int coffeeTimer;

void coffeeOFF() {
 Blynk.virtualWrite(V1, LOW);  // Sets the virtual pin state
 digitalWrite(coffeeSwitch, HIGH); //Turn OFF Coffee
 digitalWrite(yellowLED, LOW); //Turn OFF Yellow LED
 digitalWrite(greenLED, HIGH); //Turn ON Green LED
 }

BLYNK_WRITE(V1) {
  int pinValue = param.asInt();
  if (pinValue == 1)   {
    digitalWrite(coffeeSwitch, LOW);//Turn ON Coffee
    digitalWrite(yellowLED, HIGH); //Turn ON Yellow LED
    digitalWrite(greenLED, LOW); //Turn OFF Green LED
   coffeeTimer =  timer.setTimeout(5000L, coffeeOFF); //Start coffeeOFF Timer
  }
  if (pinValue == 0) {
    digitalWrite(coffeeSwitch, HIGH); //Turn OFF Coffee
    digitalWrite(yellowLED, LOW); //Turn OFF Yellow LED
    timer.deleteTimer(coffeeTimer); //delete CoffeeOFF Timer
  }
}

P.S. Adding comments to your code can help with troubleshooting, and helps others when trying to troubleshoot.

¨Thanks alot Toro_Blanco! :grinning:

That code worked perfectly.

Here is my working code so far. I’m going to build it out a little more i think, but now i have a little more meat on my legs :slight_smile:

#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 coffeeTimer;

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 LEDtimer(){
  digitalWrite(greenLED, LOW); //Turn ON Green LED
}

void coffeeOFF() {
 Blynk.virtualWrite(V1, LOW);  // Sets the virtual pin state
 digitalWrite(coffeeSwitch, HIGH); //Turn OFF Coffee
 digitalWrite(yellowLED, LOW); //Turn OFF Yellow LED
 digitalWrite(greenLED, HIGH); //Turn ON Green LED
 Blynk.notify("Kaffen er klar! PS! Trakteren vil så seg av automatisk etter 10 minutter.");
 timer.setTimeout(5000L, LEDtimer);
 }

BLYNK_WRITE(V1) {
  int pinValue = param.asInt();
  if (pinValue == 1)   {
    digitalWrite(coffeeSwitch, LOW);//Turn ON Coffee
    digitalWrite(yellowLED, HIGH); //Turn ON Yellow LED
    digitalWrite(greenLED, LOW); //Turn OFF Green LED
   coffeeTimer =  timer.setTimeout(5000L, coffeeOFF); //Start coffeeOFF Timer
  }
  if (pinValue == 0) {
    digitalWrite(coffeeSwitch, HIGH); //Turn OFF Coffee
    digitalWrite(yellowLED, LOW); //Turn OFF Yellow LED
    timer.deleteTimer(coffeeTimer); //delete CoffeeOFF Timer
  }
}

void loop() {
  Blynk.run();
  timer.run();
}
1 Like