#Robotics Using the EV3 Colour Sensor in RGB mode

David Meego - Click for blog homepageThis fourth article covers a really cool trick for working with the EV3 colour sensor. It resolves a couple of issues that I discovered when I first started working with Lego Mindstorms EV3.

The Robocup Junior Australia Rescue competition uses tiles to create the line following course. The starting point for the tiles is the Robocup Junior Rescue Field mat from Modern Teaching Aids which can be used whole or cut into 15 tiles.

While the NXT colour sensor in colour mode was very forgiving with its colour detection (for green in particular), the EV3 colour sensor was less forgiving and would not always return green when looking at the green shortcut squares on the course tiles. The issue was that Lego made the EV3 sensor very good at identifying the Lego colours, but it was now less accurate for other shades of the colours.

The other issue was using brightness mode for line following and then having to swap to colour mode to look for shortcuts. The NXT colour sensor could not swap quickly between modes, and even though the EV3 sensor can swap faster between modes, having the sensor flickering continuously between modes is not optimal.

While researching for a solution, I found about the MindCub3r for Lego Mindstorms EV3. So, why would a Rubik’s Cube solving robot be important? Well, it needed to be able to identify non Lego colours so it could read the colours from the cube. To achieve this they created a custom block which enables an additional “hidden” mode on the sensor that allows the Red, Green and Blue colour values to be returned. This RGB mode allows your program to decide what ranges of RGB values are needed to identify each colour.

[Edit] I recently found an updated version of the custom RGB block for EV3 with more advanced features created by OFDL (Original Flipped Digital Lab) see their post EV3 Color Sensor RGB Block Enhanced. You can download the block from their GitHub repository.

Note: Use of this third party custom block is supported with the EV3-G block development environment which is still available for PC computers. It does not work with the newer EV3 Classroom environment which is supported on both PC and Mac Computers. Sadly, the EV3 Classroom software does not support loading of custom blocks or third party sensors.

Using this RGB mode allows you to select a single colour to use for line following (as per Reflected Light mode) and at the same time be able to see colours (as per Colour mode but more flexible).

EV3 Basic natively has support for this RGB mode and so you can use it without needing anything additional installed.

Below are some examples based on the Two Sensor simple line follower from the previous article:

The examples are for a Lego Mindstorms robot with the motors plugged into ports B & C and the sensors plugged into ports 1 & 3. They are using the red value to control the line following.


Note: The three values returned by the custom block range between 0 and 255 and you will need to take readings and adjust your trigger points accordingly.

EV3 Basic

'  ** Simple Bot 2 **

'  By David Musgrave

'  http://WinthropDC.com

'  Last Modified: 13-Jul-2017

' ** Setup Starts Here *******************************************************************************************************

' Initialise Variables
Clicks = ""
Finished = "False"
Left  = Vector.Init(3,0)
Right = Vector.Init(3,0)

' ** Main Program Starts Here *******************************************************************************************************

Sensor.SetMode(1, 4) '  Color to RGB
Sensor.SetMode(3, 4) '  Color to RGB

' Program Main Loop
Finished = "False"
While Finished = "False"
  ' Read sensors
  Left  = Sensor.ReadRaw(1, 3)
  Right = Sensor.ReadRaw(3, 3)

  If Left[0] >= 100 Then
    If Right[0] >= 100 Then
      Motor.StartSync("BC", 50, 50)
      Motor.StartSync("BC", -25, 50)
    If Right[0] >= 100 Then
      Motor.StartSync("BC", 50, -25)
      Motor.Stop("BC", "True")

  ' Check for Button
  Clicks = Buttons.GetClicks()
  If Text.IsSubText(Clicks, "E") Then
    Finished = "True"
EndWhile ' Finished

' End Program
Motor.Stop("BC", "True")

Note: The three raw values returned from the sensor will be approximately in the range from 0 to 800 and you will need to take readings and adjust your trigger points accordingly.

Language Support

The custom block from Mindcuber.com only is set up for the Language English-US. If you install it and it says that the display name is missing when you point at the block in the toolbar, copy the English-US text for the language you need.  For example to get it to work for English-UK (GB):

Locate the ColorSensorRGB folder in one of the locations below (depending on version of the software installed – Education or Home):

C:\Program Files (x86)\LEGO Software\LEGO MINDSTORMS Edu EV3\Resources\Blocks\ColorSensorRGB

C:\Program Files (x86)\LEGO Software\LEGO MINDSTORMS EV3 Home Edition\Resources\Blocks\ColorSensorRGB

Note: Above paths are for Windows, the location on the Mac version is similar, just find Resources\Blocks\ColorSensorRGB.

In both the help and strings folders, copy the en-US folder and rename it to the appropriate name for your language, in this case en-GB.

If you are unsure what to name the folder, have look in the Blocks\LEGO\strings folder to see what language your current installation is using.

More Information

For more information on robotics and the EV3 Basic extensions to Microsoft Small Basic, check out the following links:

In the next article, we will discuss how to use the Mindsensors Sensor Multiplexer with EV3 Basic.



16-Mar-2018: Fixed path to strings folder.
30-Sep-2020: Updated with links to alternate advanced RGB block.
06-Feb-2023: Added Note about lack of compatibility with EV3 Classroom software.

This article was originally posted on http://www.winthropdc.com/blog.

4 thoughts on “#Robotics Using the EV3 Colour Sensor in RGB mode

  1. Tenho 12 anos, mas já sou da robótica da minha cidade e já estou quase na minha primeira OBR. Eu e minha equipe estavamos com problemas pois o sensor não conseguia ler o verde da pista, então tevemos que usar o RGB, mas não conseguiamos usa-lo pois o mindstorm estava em português; tivemos que chamar o técnico para rebaixar o mindstorm em português, mas agora com esse post, acredito que ficará muito mais fácil para essa troca de idioma. Obrigado


    • Translation: I’m 12 years old, but I’m already in robotics in my city and I’m almost on my first OBR. My team and I were having problems because the sensor couldn’t read the green of the track, so we had to use RGB, but we couldn’t use it because the mindstorm was in Portuguese; we had to call the technician to downgrade the mindstorm in Portuguese, but now with this post, I believe it will be much easier for this language change. Thanks

      Glad to be able to help. David


Please post feedback or comments

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.