LFR code isn't executing when it's programmed with ir remote


I am trying to program the ir remote to do certain functions on Mbot.
I tested everything on it remote and mbot. Everything is working perfectly. Also the ir remote workers default as well as when I do simple function like movement and showing led lights.
But when I program the ir remote to follow lines, when pressing a button like; A,B,C it doesn’t work. I also tried putting the lfr code in a custom function, but doesn’t executes the lfr code.
Here is a sample of my code below,

Please someone help me, I need this to be done ASAP😭It executes all code except line following one.


Hi Tahamid,

I slightly adjusted your code

One of your problems is that you are using a blocking instruction. You lose a precious second on your line sensor. What makes that your robot enters the decor.

Hope this will help?


@Crackel Thank you so much for the help, but now I am facing two more problems,
1- I can’t add a timer function like I want the bot to start the times with a given time e.g. 5 sec and when time is up the bot will stop where it reached. But when I put the timer function inside the repeat, it doesn’t work. It worked if I don’t assign it button.
Bewlo is an example:

2- I wanted to use the different buttons for different purposes like I want to use A- follow the one given path, when pressed B- follow another given path for a certain period of time like this.
I want the bot to receive ir command freely, not after pressing A, then stoping it with C and again pressing B. I want it to do as any button I press , like If I press B instead of A it should do B-command, not A, below is an example.

Because I have multiple LF- paths with different lengths, I measured the time to finish each line and assigned the robot to follow that path for that certain time as I place the robot in front of the line and press a button on my IR remote.

Again, thank you very much for the above help.!🥺


Hi Tahamid,

Personally, I would go with a request and a POST because otherwise the others on the forum will be a bit lost in the conversation. So, I will answer your questions:

Program all the buttons on the remote control with your mBot

2 types of behavior

  1. The command which must be executed continuously;
  2. THE command which must be executed only once;


Line.zip (25,1 Ko)

Warning: Blockchoice must be numeric (no text or character)



For the time being, this is unfortunately not possible with mBot 1. It is probably possible to calculate a duration but not to obtain the time.



I am very sorry if I offended you without making it a request, But please take this a request from me as a beginner mblocker, and thank you so much for this help, Again thanks for the kind response to my comment also.
I don’t know how I could make this as a post, but please do if you know.

I was able to do a time_stop in one of my previous project and wanted to implement here also, I am currently using the mBot_1. But that’s all for now.
Thank you very much @Crackel
Hope you consider this…


Hi Tahamid,

English is not my language so in reality it makes me really happy to help. To be honest, any problem helps me be better.

Otherwise, maybe I misunderstood the request with the timer.

  • Make a time stop, I don’t see a problem. I want you to code one so I will try.
  • Doing a time start with a real start time is impossible. You can start the mBot is 5 minutes or 10 minutes but not at a specific time like 4:45 p.m.

So what is your request.

  • Stop the mBot within a specific time (Example 10 seconds?)
  • Calculate the time between keystrokes
  • Start the mBot within a specific time (Exmple 10 seconds?)

Note: There is no stupid question. I am not an expert with Makeblock products, I have fun just like you.


Wow! You are awesome man,
Thank you very much for offering such help.

Right now I won’t ask anything immediately but if you insist,
My exact question in the reply was the first one “stopping the bot within a specific time (ex: 10 sec)”


Hi Tahamid,

There is nothing extraordinary, it makes me happy …

I programmed the button from 1 to 9 in seconds. So the 3 button equals 3 seconds of gas.

Line.zip (26,3 Ko)


Thank you very much for such help.
It will help me to build my project further.


Hi Tahamid,

As I said, it makes me happy, I took very little time. So, if you want to obey or get stuck in your project, just ask for help on the forum. The mBlock code is fairly easy to read, but it can quickly become spaghetti.

Good luck