top of page

RGB Colour

Detects the RGB (red, green and blue) colours of an object.

RGB Colour

The RGB Colour Sensor detects the RGB (red, green and blue) colors of an object.


Quick Commands

Setup the i2c system by typing:

i2con

Once the command has run the color sensor should be detected. Now you can view the colors from the sensor on the command line by typing this command:

jp "red /cs_red green /cs_green blue /cs_blue clear /cs_clear"


Videos

RGB Color Sensor Part 1: Introduction

RGB Color Sensor Part 2: Using the sensor


NOTES AND CAUTIONS

  1. The sensor has a short range of about 2cm, ideally the object to be measured should be up against the sensor if the sensors LED light is on.

  2. The sensor has a built in LED that is controlled from pin 5 on the USI. Setting the pin high turns the LED on and setting it to 0 turns it off.


Connection Example



Parts of the Sensor



The main parts of the sensor are shown in this photograph. First of all we have the sensor on the far left, this is where the RGB elements are that detect the colors. The sensor has a number of pins the main ones being the red power supply pin which needs to be 5 volts, the green ground pin, the blue serial clock pin, the white serial data pin and the LED control pin. Looking at the lower image you can see the RGB sensor in the center and slightly below that you can see the LED light the purpose of which is to eliminate the subject whose color you're trying to detect. The LED input can be used to turn the LED light on and off from the JackBord.


How it Works


As you may already know the white light that we see every day is actually composed of several different colors which is where the rainbow comes from.




For electronics and robotics we rely on the fact that most colors we can see can be created from just three base colors red green and blue. If we mix these colors as shown in the picture below we derive other colors such as yellow. You can also see at the center, when we combine all three colors we end up with white.



The Sensor

At the center of the sensor is a small IC or integrated circuit that has a number of light sensors on it. These are sensitive to ambient light or normal light, red, green and blue light. You can see the color sensor IC in the picture below, above the white LED.



You can use these values to determine the color of the object the sensor is looking at. For example if we are getting equal values of red and green and the blue value is much lower this means the object is most likely yellow. This is because yellow light it maid up of red and green.


Communications


The sensor uses a special protocol called I2c to communicate with the JackBord on port D.


Input and Output Pins:


The pins of the sensor are listed below:



Connecting the Sensor to the JackBord


To make it easier to connect the sensor to the JackBord we locate it at port D using an M4 bolt and nut. This is because the sensor needs to use the JackBord's i2c port and this is located at port D. This is shown in the picture below.



Connecting the Jumper Wires


The diagram below shows how the sensor should be connected to port D of the JackBord. Note that the INT line is not needed.



Steps:

  1. First take a green jumper wire and connect it to the ground pin on the JackBord and then to the green ground pin on the sensor

  2. Next we take a red jumper wire and connect it from the 5 volt power supply pin on port D of the JackBord and connect it to red 5 volt power supply pin on the sensor.

  3. Take a blue jumper wire and connect it from the blue pin on the sensor to port pin d4 of the JackBord

  4. Take a white jumper wire and connect it from the white pin on the sensor to port pin d5 of the JackBord

  5. Finally use a black jumper wire to connect the black LED pin on the sensor to port pin d1 on the JackBord.

We will use Port D pin 1 on the JackBord to control the sensor's built in LED light.



The jumper wire colors you use don't have to exactly match those shown above, the main thing is each jumper needs to connect to the correct pin on the sensor and the JackBord.


Using the Sensor


The sensor has a number of detectors that measure the amount of light in clear, red, green and blue. The clear value is the overall amount of light which is a combination of all the colors together. While the 3 other values are for their respective colors only.


Accessing the Color Values


In Octagon there are a number of system variables used with this sensor:


You can display the values from the sensor using the print statement below in an Octagon program:

print "Clear /cs_clear Red /cs_red Green /cs_green Blue /cs_blue"

Controlling the Sensors LED Light


When the sensors LED light pin is at 0V or connected to ground the light will be turned off. When its high i.e. connected to 3V the LED will be turned on. If the LED line is connected to pin d1 on the JackBord you can turn it on by turning pin d1 on by typing this command:

d1 1

and you can turn it off with this command:

d1 0


bottom of page