Virtual Pin doesn't change back to 0

Hi everyone i’m working on my infusion device project where I start my motor when the value of the virtual pin = 1. the motor need to stop running when the virtual pin = 0 but during the infusion process the value of the virtual pin can’t change back to 0 until the process is done how do I fix this problem

Hardware : ESP32 wifi
Blynk server
Library version 1.2.0

  int value = param.asInt();
  if(value == 1){

  Infusion_Duration(FlowRate, VTBI, &Inf_Hours, &Inf_Minutes, &Inf_Seconds);
 Calibration_Infusion (FlowRate, VTBI, 0.2, &totalSteps, &rpm);
  step_delay =  SetSpeed(rpm, stepsPerRevolution);
  Blynk.virtualWrite(V8, value);

@Fha_Napasrawee Please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:

Copy and paste these if you can’t find the correct symbol on your keyboard.

I think you need to explain more about what you’re trying to achieve.
This probably means also posting your full sketch, with sufficient in-code documentation to make it understandable (which your current code snippet doesn’t do).

It looks like you may be expecting the code in the BLYNK_WRITE(V5) code to loop until your process is completed, which it won’t do.

It’s also not clear how you expect the V5 datastream’s value to change back to zero in your code (and even if it did, it wouldn’t trigger the BLYNK_WRITE(V5) callback).


When the value is set to 1, the infusion process is initiated by the Infusion_Process() function, and the motor continues to run until the process is completed. However, I would like to be able to change the virtual pin value to 0 during the process to stop it. Currently, the value cannot be changed back to 0 during this time. Is there any solution that can help me achieve this?

You’re taking the wrong approach to using virtual pins.

As I said earlier, Blynk.virtualWrite(V5) will not cause BLYNK_WRITE(V5) to be called.

You should move most of the code out of BLYNK_WRITE(V5) and restructure your code.