How to use RGB Line Follower


i wanna follow my mbot white line with RGB Line Follower? How can i do? i wanna use like that for MAKEX Competition.

Thanks for help


I’m not sure I quite follow what you’re asking. The stock mBot comes with a line follower sensor that can distinguish between black and white. When line following the line is usually black, so if you’re following a white line you’d need to use the opposite values to indicate the line follower is over a white line.

Value Description
0 Both sensors over a black line
1 Left sensor over black line, right sensor off of black line
2 Right sensor over black line, left sensor off of black line
3 Both sensors off of black line

In essence you would want to us a 3 iff both sensors are over a white area vs. using a 1 indicating both sensors are over a black area, and so forth.


The RGB line follow sensor is NOT the standard line follow sensor that comes with the mainboards.

RGB Grayscale Sensor is specially designed for line detect competition. It contains 4 RGB fill flashes and 4 photodiodes. This sensor can be used to detect line on deep background with light color track and light background deep color track as well.

I believe it only supports Arduino programming.


Nice info! My earlier response was based on a lot of folks thinking the line follower sensor is an RGB one. I tested the idea with the sensor on an mBot and it held up so maybe one doesn’t need an RGB sensor for line following?


Hi All,

Here is the learn website which provide detailed explanation for the RGB Line Follower.



Your link shows graph programming for Auriga.
What main boards does it work on for graph programming?


It works with MegaPi Pro, MegaPi, mCore, Orion, Auriga boards.



When i try in link sample code, i get this error. Why i get this error?

Me RGB line follower attached 1 number port


Hi aalimkeskinn,

This is the program issue.
The set enhance encoder is block from an extension enhanceencoderonboard which special for the MegaPi, Megapi Pro, Auriga board . It doesn’t support mBot robot.

Besides, it looks like there is another mistake that you didn’t set a value to the variable turnoffset.


You said “It works with MegaPi Pro, MegaPi, mCore, Orion, Auriga boards.” , for RGB Line Follower.

So How can i work on mCore ? RGB Line Follower.


I think you should add this extension to mblock ;

RGB Line Follower for Makeblock


Hi aalimkeskinn,
The extension for RGB Line follower work on MegaPi Pro, MegaPi, mCore, Orion, Auriga boards. But the extension enhanceencoderonboard is a different extension for encoder motor and it only works with Auriga, MegaPi , MegaPi Pro, but not the mCore.
You can delete the program blocks from extension enhanceencoderonboard and try upload this program:


How to add this extension @_@


Hi SouSageYa16h,

Actually, the mBlock 3 series already has the extension for RGB line follower. You can add its extension from mBlock directly refer to picture below


tech_support i tried your say sample code but when i upload my mcore card my robot do anything. i wanna this robot follow white line you can see this video.

Help please


Hi aalimkeskinn,

The sample code is just for you to test the upload function, did it still upload failed?
If you want to achieve the project in the video, you may need complete the mBlock program by yourself.
Please note that the motor on the mBot is not encoder motor, so that you can’t use the program blocks set enchance encoder motor. You can use the program block below for the mBot motor.


Tech_support thanks for help, i try code on image. But it did not follow white line. It turn around itself

How to use RGB Line Follower to follow white line

Hi aalimkeskinn,
Please make sure RGB line follower has learned color, refer to “learning method” (
Then you may try below program: