mBot Code Not Working


Hi! I am trying to get my mBot to switch between 6 different modes. Each of them work individually.
The modes are:
LLFM: Lighted Line Following Mode
NLLFM: Not Lighted Line Following Mode
LOAM: Lighted Obstacle Avoidance Mode
NLOAM: Not Lighted Obstacle Avoidance Mode
AOAM: Ambulance-themed Obstacle Avoidance Mode (I know it’s childish, it’s just to bamboozle my cat.)
AUTO: Automatic Mode Switcher (Automatically selects the best mode for the present conditions)
Can you help?
Thank you, Remiel Tan
P.S. If @Crackel and @Best_codes see this, I’m terribly sorry for not seeing your answer in my previous question. I wasn’t able to code (my laptop got reformatted) and got discouraged when all my code got destroyed. I haven’t visited this site or the mBlock 5 app since then. It has only been since today when I recovered an outdated version of my code, and tried to get it to work.


Also, I forgot to attach a sample of code. Here it is:


If you are using the onboard button or IR Remote to switch modes, your code should look something like this:

Better picture:

When the onboard button is pressed, the first code stops running and the second begins. However, since Arduino controllers like mBot can’t multitask, any “Wait 1 Second” Blocks or ones like them will ruin the code. If you want, I can show you an alternative code for “Wait 1 Second”.

Thanks for your time,


Hi remieltan0617,

Ok, I looked at the code you lost and there is only a small logic error.
OBBP = 7 should be =6. Otherwise, it’s not very serious but you will get the AUTO function twice.

Otherwise, everything is perfect except that you actually have a lot of code to redo…

Here is the principle but do not be discouraged…



This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.