Robot Car Doesn't Follow Black Line if Using BLYNK_WRITE(Vpin)

Hi everyone,

I put the below code 1 in the void loop() without any Blynk Library or Blynk Code, it works, the robot car follows the black line without any issue, now I wanna click one virtual button (See Code 2), lets’ say V100, and then the robot car will start following the line, but it doesn’t work, the robot car only moves forward direction, can somebody advise me which portion could be wrong? :wink:

Thanks for any help you can provide. :grinning:

Code 1

    if (digitalRead(IRLINESENSOR1) == LOW && digitalRead(IRLINESENSOR2) == LOW) {
      Forward();
    } else if (digitalRead(IRLINESENSOR1) == HIGH && digitalRead(IRLINESENSOR2) == LOW) {
      Left();
      delay(20);
    } else if (digitalRead(IRLINESENSOR1) == LOW && digitalRead(IRLINESENSOR2) == HIGH) {
      Right();
      delay(20);

Code 2


BLYNK_WRITE(V100) {
  int isButtonPressed = param.asInt();
  if (isButtonPressed == 1) {
    if (digitalRead(IRLINESENSOR1) == LOW && digitalRead(IRLINESENSOR2) == LOW) {
      Forward();
    } else if (digitalRead(IRLINESENSOR1) == HIGH && digitalRead(IRLINESENSOR2) == LOW) {
      Left();
      delay(20);
    } else if (digitalRead(IRLINESENSOR1) == LOW && digitalRead(IRLINESENSOR2) == HIGH) {
      Right();
      delay(20);
    }
  }
}

Everything inside BLYNK_WRITE is triggered by input from the app (most often)
You need to create a function, and trigger this function by input from BLYNK_WRITE

1 Like

@Zephyr Blynk is an IoT based GUI (App) library and server… thus requires it’s own background communication and processing… so something like this line following routine will have to be modified significantly to allow both processes the time needed to do the job without Blynk disconnecting or your line follower missing a signal and tearing off into the widlderness to start the robot uprising.

So, instead of simply running the code in the void loop() you will need to instead call that routine in it’s own function as frequently as possible (without preventing Blynk’s background housekeeping) with timers.

And adding in a if else() check to see if a button is pressed before even running the timed loop will give you the control you seem to wish in your project.

This is not a simple issue to quickly solve… i suggest you start by familiarizing how Blynk works with smaller, simpler examples (links at the top of this page) Then look at other users examples of fast action code merged with Blynk (PIR, Ultrasonic, rovers, etc). Then you will have a better understanding of what you need to do.

1 Like

Hi @Pavel & @Gunner,

Big thanks for the concept, it works, I created the function & its short timer and then put the flag for both of the function & BLYNK_WRITE(V100) in order to trigger them.

Have a nice day ^.^

2 Likes