Sync button in app with relay status

Isn’t that code the same as the code i posted in first post?
The code in my first post does not update my app button.

And why do u have to use “lambda timer”? Why can’t i use an ordinary timer?

And yes, i use the Virtual pin in button settings in the app. (V1)

if param.asInt()
    digitalWrite(coffeemaker, LOW);         // change coffeemaker to your IO pin and LOW to you default ON for your relay
    timer.setTimeout(600000, []()              //will execute the following after 10mins
         digitalWrite(coffeemaker, HIGH);
         Blynk.virtualWrite(V1, LOW);          //turns the button off on the app

Also note the comments in the code !!!

As noted this was just typed from memory if it doesn’t work dig into the syntax for “Lambda timer” but I use it all the time to communicate back to the app and change the button state after the routine is finished.

Many thanks daveblynk!! :slight_smile:

I will try that later to day.

But i can’t find any information on how to use Lambda Timer. Other than i can see the code you posted. I also want to understand it, not just use it, if you understand? :slight_smile:

I just see an “[]” and an “)” at the end.

Is there any way i can use an ordinary blynk timer instead? (Since i actually know how that work)

So the 50+ results obtained by searching the forum weren’t enough?


I can’t find post that actually explain the code. I just see the code.

(I’m apparently not crazy nuff yet… so one more try…)

You don’t… and you can… the Lambda method just compacts timer command and called function into one compact form. If you want to learn more about it, best to Google as it is not a Blynk specific thing… just something I started learning about and using all the time after seeing another user try it once.

It is the same as this…

BLYNK_WRITE(V1) {  // Blynk Button set to switch mode
if param.asInt()   {  // If 1 or HIGH, proceed with commands
    digitalWrite(coffeemaker, LOW);  // Or 0, Turn relay ON (or use HIGH/1 if relay uses active high logic)
    timer.setTimeout(600000, coffeeOFF)  // Execute this function after 10mins

void coffeeOFF() {
digitalWrite(coffeemaker, HIGH);  // Or 1, Turn relay OFF (or use LOW/0 if relay uses active high logic)
Blynk.virtualWrite(V1, LOW);   // Or 0... Turns the button OFF on the app
1 Like

Ahaa… now we getting somewhere! :slight_smile:

Thats was all i needed. I will try the code later today :slight_smile:

Aside from the Lambda shortcut, this is all very standard Blynk control stuff… All officially documented and covered zillions of times in this forum… So I admit I do find it concerning that it was so hard for you to understand, despite your stats showing you have put in 9 hours of reading over 1000 posts :thinking:

Oh well, hope it works for you this time :slight_smile:

You do not need to concern about me. I’m a grown man.

Sometimes we need a last bit of a puzzle to understand a bigger one. But do not worry. I always get it to work some how. If i do not get help here, i get it other places :slight_smile:

I understand, but I have found out blindly using it for a bit in different sketches I begin to slowly understand it.

Maybe you are a lot smarter than me then. Or have more time to spend regards to coding. I do not have much time to code because i have several other projects going.

Or is it a competition?


One last question before i test the code later today:

If i use the code over and loose the Wifi. Will the relay shut of the Coffee maker?

I don’t :stuck_out_tongue:

Then we are wasting our time trying to help.

Yes, No, Maybe… depends on your understanding, wiring, final code and why/how it lost connection… as already tried to explain above, loss of connection without proper failsafe code and wiring (which you don’t seem to have) can lock the whole process in the middle of some unwanted (and unknown) state

I wouldn’t trust your code for anything critical, but you are you and it is not my burnt coffee or house :rofl:

Well… it was you that sayed it…

With answers like that, i think you waste you’r own time.

You’r answer is almost like reading the coffee makers manual. It says that by no means that the cover to the heating element must be taken off because of som mambo jambo about fire hazard etc. So my house is probably allready in big risk.

Now i really feel what it is to be a real man.

That code actually worked after i corrected some small errors. Thanks :slight_smile: .

Of course it would… it is one of the most basic of Blynk & timer functions. And is essentially the answer @daveblynk gave you in the very 2nd (and 29th) post of this arduis topic. He deserves the thanks.

Any errors come from my quickly typing it out in the forum instead of in the IDE… I now see at least one missing } … That’s OK, it gave you some troubleshooting practice :innocent:

Okay. You can give the gold medal to who you want. The most important for me is that i got it to work.

I know it was a simple solution and i mentioned it in my first post. But sometimes i get stucked with the most simple codes.

Thanks anyway.

@daveblynk :medal_sports: