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

Hello!
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.

components

Arduino Mega
Relay Module 4-channel
three way switch

I appreciate your attention and reading time.

Hello.
@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.

https://github.com/blynkkk/blynk-library/blob/master/examples/More/ButtonInterrupt/ButtonInterrupt.ino
https://github.com/blynkkk/blynk-library/blob/master/examples/More/ButtonPoll/ButtonPoll.ino

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:
https://github.com/blynkkk/blynk-library/blob/master/examples/More/SyncPhysicalButton/SyncPhysicalButton.ino

Hello!
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