Check the status of lâmpda and switch on and off, with relay and physical switch

Could someone help?
I’m dificauldades to control lamps, using shield W5100, relay module and physical switch with Blink.
The difficulty in question is: Tap the widget button (Blynk) and the light comes on, go on the physical switch and turn off the lamp, the widget button to change the status on to off.

Here in the community, I found some discussions and codes, however, could not implement.


Arduino Mega
Relay Module 4-channel
three way switch

I appreciate your attention and reading time.

@BlasiTI so your question is - “How to set Blynk button state after pressing physical button?”

If so - that’s easy. You can call Blynk.virtualWrite. We have few different examples for that.

Thank you for answering!

The sample code, the physical switch on and off the LED widget (App Blynk).

What I like: Both the physical switch and the button widget (App Blynk), on and off the lamp using a relay. If you turn off the lamp with the physical switch, should aprentar the widget button status off.

Sorry if I was unclear.

I appreciate the help.

Yes. Those example above shows you how you can do it. You just need replace led.on() with Blynk.virtualWrite(). And pass virtual pin of your button.
To be more specific. Let’s assume you have a button on Virtual pin 1.
Ti turn it on you need to

Blynk.virtualWrite(V1, 1);

to turn off

Blynk.virtualWrite(V1, 0);

Please check this example:

Thank Dmitriy!
Thank vhymanskyy their help was essential, it was exactly what he wanted!

A post was split to a new topic: Need help getting feedback status of external switching