How to add Start/Stop button on blynk?

Hello,

Iā€™m currently working on a project with Ultrasonic sensor HC-SR04 with ESP32 that attached to a drone. my question is, how do I add an on/off button, so the ultrasonic sensor only read the distance when I want it to, not whenever the power is on?

Widget button attached to a virtual datastream.
Within the BLYNK_WRITE(Vpin) callback, assign the incoming value to a GLOBAL variable.
Call the function that takes distance readings using a BlynkTimer.
At the beginning of that function, check the value of the global variable that was set in the BLYNK_WRITE(Vpin) callback.

You may also want to have a BLYNK_CONNECTED function that calls Blynk.syncVirtual(VPin)

Pete.