Easily pick colours from physical objects with this Arduino based RGB colour picker, enabling you to recreate the colours you see in real life objects on your pc or mobile phone. Simply push a button to scan the colour of the object and you’re given the RGB colour values as well as an indication of the measured colour on an RGB LED.
I’ve designed a simple 3D printed enclosure for the electronics to make the device portable, simply plug it into a USB port, charger or power bank to power it up.
I usually try to use an Arduino Uno as this is one of the most widely used Arduino boards, but to make this device portable, it has been designed around an Arduino Pro Micro board. It can however be easily adapted to run on most of the other Arduino compatible boards with enough IO, such as the Uno, Leonardo or Mega, you’ll just need to build it into a larger enclosure.
This guide assumes that you’ve worked with an Arduino micro-controller before know the basics of programming the Arduino and connecting an LCD panel to it. If you do not, follow the linked guides for more information and in-depth explanations.
Here is a summary video of the build, otherwise read on for the full guide to make your own.
What You Need To Build Your Own Arduino RGB Colour Picker
- Arduino Pro Micro (Or Other) – Buy Here
- TCS34725 RGB Sensor – Buy Here
- 16 x 2 LCD Panel – Buy Here
- Push-button – Buy Here
- 2 x 10K Resistors – Buy Here
- 3 x 220Ω Resistors – Buy Here
- 470Ω Resistor – Buy Here
- RGB LED – Buy Here
- 7 Pin Female Header Strip (Cut to Length) – Buy Here
- 10K Potentiometer – Buy Here
- Breadboard & Jumpers for Testing – Buy Here
- 3D Printer & White/Black Filament (Optional for Housing) – This One Used
In addition to these, you’ll need basic tools for working with electronics, including a soldering iron if you’re permanently building your circuit for use in an enclosure as well as a PC for programming your Arduino.
Connecting the RGB Colour Picker Test Circuit
It’s always a good idea to assemble your components onto a breadboard first to test them and make sure that your circuit and software are working correctly before making any soldered connections.
The components are connected onto the breadboard as shown below:
There is nothing particularly unique or strange in any of these connections between the components and the Arduino, they are typical basic circuit configurations for connecting the LCD, push button and LEDs to the Arduino.
The 10K resistors are used for the push button connection and the 220Ω resistors for the colour sensor LED and the red and blue legs of the RGB LED. The 470Ω resistor is used for the green leg of the LED to reduce its brightness a little to create more realistic looking colours.
The 10K potentiometer is connected to control the contrast of the LCD display, if you are not getting any characters displayed on your LCD and no errors uploading your program, first try adjusting this potentiometer. You may find that the characters are actually being displayed, they’re just too dim to see.
The RGB colour sensor is connected to the Arduino using a simple I2C interface. Make sure that you’re using the correct pins on your Arduino for this interface if you’re using a different board.
If you are using a different Arduino board, make sure that you have the same functionality on each pin used on the Pro Micro. For example, you need PWM enabled pins for the control of the RGB LED in order to simulate the picked RGB colour.
Here are some pictures from the assembly of the components onto the breadboard:
And the final completed breadboard:
Programming Your Arduino RGB Colour Picker
Now that you’ve assembled your components onto the breadboard and made the required interconnections, you can load the code onto your Arduino and check that the components work correctly.
Before plugging the USB cable into your Arduino, check all of your connections again to make sure that they are correct. The USB cable supplies power to the board and connected components which may damage them if not connected correctly.
This particular board, the Arduino Pro Micro acts as a Leonardo board when connected to your PC, so make sure to select the correct board type in the Arduino IDE.
Here is the code:
// Michael Klements
// RGB Colour Picker
// 3 January 2019
#include <LiquidCrystal.h> //Include the required libraries
byte gammatable; //Table to convert measured RGB values in more realistic visulisation colour on the RGB LED
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X); //Setup the colour sensor through Adafruit library
LiquidCrystal lcd(15, 14, 16, 4, 5, 8, 7); //Assign LCD pins
int pinLED = A0; //Assign pins for the colour picker LED, push button and RGB LED
int pinButton = A1;
int redLED = 6;
int greenLED = 9;
int blueLED = 10;
#define commonAnode false //Set up RGB LED common cathode or anode for gammatable - thanks PhilB for this gamma table
pinMode (pinLED, OUTPUT); //Assign output pins
pinMode (pinButton, INPUT);
pinMode (redLED, OUTPUT);
pinMode (greenLED, OUTPUT);
pinMode (blueLED, OUTPUT);
lcd.begin(16,2); //Defines the number of characters and rows on our LCD
lcd.clear(); //Clear the screen
lcd.setCursor(0,0); //Set the cursor to first character, first row
lcd.print("Colour Picker"); //Display this text
analogWrite(redLED, 255); //Routine to quickly fade change the LED from red to green to blue, just a visual effect
for (int i=0; i<=255 ; i++)
for (int i=0; i<=255 ; i++)
if (tcs.begin()) //Connect to the colour sensor
digitalWrite(pinLED, LOW); //Turn off the sensor's white LED
for (int i=0; i<256; i++) //Set up the gamma table for RGB conversion
float x = i;
x /= 255;
x = pow(x, 2.5);
x *= 255;
gammatable[i] = 255 - x;
gammatable[i] = x;
if (digitalRead(pinButton) == LOW) //If the button is pressed
float red, green, blue; //Create variables for the measured RGB values
digitalWrite(pinLED, HIGH); //Turn the sensor LED on for measurement
delay(500); //Delay to allow any movement from the button press to stop
tcs.setInterrupt(false); //Start measurement
delay(60); //Takes 50ms to read
tcs.getRGB(&red, &green, &blue); //Get the required RGB values
delay(500); //This delay and delay at end just allow time for the button to be released, avoids repeated readings
digitalWrite(pinLED, LOW); //Turn off the sensor LED
lcd.clear(); //Clear the LCD display
lcd.print("Colour Picked"); //Display the results
analogWrite(redLED, gammatable[(int)red]); //Set the RGB LED to reflect the measured colour with gammatable conversion
Download – RGB Colour Picker Code
The code contains comments to guide you through each line and what its purpose is. The colour identification and LED portion is based on the Adafruit colorview example code.
You will need to have the Adafruit libraries installed. This is easily done by clicking on Tools -> Manage Libraries in your IDE and then typing in “Adafruit TCS” in the search bar and installing the found library.
Some things to look out for in the code:
The LCD assigned pins are in a weird order (15 ,14 ,16 ,4 ,5 ,8 ,7). I usually try and keep the pins sequential but in this example they’re a bit mixed up for two reasons, one because I needed to work around the available PWM pins for the LED and the second because the pins on the Pro Micro are not all in sequential order.
The colour sensor LED (pinLED) and push-button (pinButton) are connected to the Pro Micro’s analogue inputs, being used as digital IO, as there were not enough digital IO pins available.
There is a brief routine to fade the LED between red, green and blue when starting up. This is just a visual effect and can be removed if you’d like your colour picker to start up quicker. It takes about 1.5 seconds to run through.
The program won’t progress past the setup if it does not establish a connection with the colour sensor, this will show up as “Sensor Error” on your LCD. If the LED is coming on, indicating power to the sensor then check your SDA and SCL connections.
The gamma table simply converts the measured RGB values from the sensor into values which will result in a more realistic LED representation of the actual colour, this is just to improve the LED visualisation effect and doesn’t have an affect on the measured RGB values displayed.
The code then waits for the push-button input to take a reading from then sensor and display the values on the LCD and through the LED. The three delays in the loop if statement are simply to allow and movement from pushing the button to stop and then to avoid taking repeated readings before the button is released again as the actual reading and cycle time would be about 100ms. You can adjust these values for faster colour picking.
Installing the Components into the Housing
In order to make a useful and portable device, I decided to solder the components together and mount them into a housing.
A circuit of this complexity should probably be designed onto a PCB to make it easier to handle and more robust inside the enclosure, but most people don’t have access to PCB manufacturing services so I’ve stuck with soldering the components together with sections of ribbon cable.
3D Print the Housing
I designed a basic rectangular housing for the colour picker, the 3D print files can be downloaded through the link provided after the images.
Download – Colour Picker Enclosure 3D Print Files
The colour sensor is on the back so that you can hold the device over an object and pick the colour with the readout shown on the front.
I printed the housing using white PLA and 20% infill, I would avoid using a coloured filament for the back panel as you don’t want to introduce reflected coloured light onto the surface being picked. Stick with either black or white.
The housing dimensions are approximately 110mm (4.3”) x 46mm (1.8”) x 20mm (0.78”) with both halves assembled. Each half is 10mm (0.39”) high.
Solder the Circuit
Once you’ve 3D printed the housing, you’ll have an idea of where all of the components are mounted and how long to make the interconnections.
Start by soldering each component to your Arduino as you remove it from the breadboard and try to only remove components to make up a full circuit at a time.
For example, start with the push-button circuit and solder the resistors to the push-button and then connect them to the Arduino before removing the LED components. This way you’ll be able to keep track of the components and make sure that you’re connecting them individually to the correct Arduino inputs and outputs.
Take care with the LCD panel and the colour sensor to make sure that you make the connections to the correct Arduino IO ports.
The colour sensor connections should be soldered onto the 7 pin female header strip (cut an 8 pin or longer header strip down to 7 pins) to enable it to be plugged in through the back section of the housing. This just enables the two halves to be properly separated if you need to. You can also solder directly to the colour sensor with a section of ribbon cable, just make sure that the ribbon cable runs through the slot in the housing before soldering the connections.
There are a number of connections to be made to GND and 5V and it makes things easier to connect them to larger central points rather than trying to solder them all onto the two Arduino pins. I connected them all onto the two outside legs of the LCD potentiometer as this is roughly in the centre of the housing and has the largest surface area to make the connections.
Once you’ve made all of your connections and you’re happy with the connection lengths. Try powering up your circuit again to verify that everything is working correctly before mounting the components into the housing. Be careful and ensure that none of the components or exposed terminals are touching each other, which may lead to a short circuit.
If your circuit is working correctly then you can mount your components into the 3D printed housing.
Mount Components into the Housing
The last step is to mount your components into your housing. I used a hot melt glue gun to mount the components, you can also use epoxy or small amount of superglue.
The colour sensor can be glued into the cavity on the back of the housing with the pin header strip sticking through to the inside of the housing. The female header strip will then be used for the sensor to plug into the circuit.
Mount the push-button, LCD and LED through the holes in the front panel and glue them into place on the inside of the housing. If your push-button has a press-on cap, install that piece as well.
Your Arduino should fit snuggly into the slot in the base and shouldn’t require any glue to hold it into place but if it does, make sure you don’t put glue on any components on the back of the board. Rather glue it in place along the edges.
The micro USB port should now be easily accessible through the side of the housing.
Glue the two halves together, using the pegs on the two corners as a guide. These should press together tightly and assist in holding the two halves together. Make sure that none of your exposed terminals or leads on your resistors, LED or potentiometer are touching anything else in your circuit. If they are, use a bit of insulation tape or paper to separate them or cover them up to prevent short circuits.
Lastly, test your colour picker and make any final tweaks you’d like to the software.
Using Your RGB Colour Picker
To use your colour picker, plug a micro USB cable into the port on the side of your colour picker and connect it to a powered USB port on a PC, charger or power bank to power it up.
The startup sequence should run and then you’ll be able to pick a colour.
Place the sensor over the colour you’d like to pick and then push the button to pick the colour. The LED light on the sensor should come on momentarily, after which you’ll get an RGB readout on the LCD and the LED will change to reflect the colour which has been picked.
The coloured feedback LED is meant to give you an indication of the colour which has been identified. This is just a quick way for you to check that the sensor has picked up on the correct surface and is not always an accurate representation of the colour due to limitations with the way in which these LEDs work. For example, they can’t show blacks or greys as the actual LED diffuser material is white and can only produce light in order to create colours. For this same reason, darker colours also don’t show up well on the LED although the measured RGB values are correct.
Have your tried making your own RGB colour picker using an Arduino and the TCS34725 sensor module? Let us know how it went in the comments section below. We would love to hear your tips, tricks and any changes you’ve made to the design.