Arduino RGB Color Picker – Pick Colors From Real Life Objects

48,529

505

40

Introduction: Arduino RGB Color Picker – Pick Colors From Real Life Objects

Easily pick colors from physical objects with this Arduino based RGB color picker, enabling you to recreate the colors you see in real life objects on your pc or mobile phone. Simply push a button to scan the color of the object using a cheap TCS34725 colour sensor module and you’re given the RGB color values as well as an indication of the measured color on an RGB LED.

If you enjoy this Instructable, please vote for it in the Make It Glow Contest.

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. You could also modify the design to accommodate a battery to make it even more portable.

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.

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.

Supplies

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.

Step 1: Connecting the RGB Color 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 in the circuit diagram.

There is nothing particularly different or strange with any of these connections between the components and the Arduino, they are typical basic circuit configurations for connecting an LCD, push button and LEDs to the Arduino.

The 10K resistors are used for the push button connection and the 220Ω resistors for the Color 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 colors.

The RGB color sensor is connected to the Arduino using the simple I2C interface. Make sure that you’re using the correct pins for this interface if you’re using a different board. It is controlled using the Adafruit library discussed in the code section.

If you are using a different Arduino board, make sure that you have the same functionality on each pin as 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 color.

Step 2: Programming Your Arduino RGB Color Picker

Now that you’ve got your components assembled onto the breadboard and made the required interconnections, you can load the code onto your Arduino using your PC and check that the components work correctly.

Check all of your connections again before plugging the USB cable into your Arduino to make sure that they are correct. The USB cable powers the board and connected components which may damage them if they are not connected correctly.

This particular board, the Arduino Pro Micro acts as a Leonardo when connected to your PC, so make sure to select the correct board type in the Arduino IDE otherwise you'll get errors when you try and upload the code.

Here is a link to the RGB colour picker code: Download RGB Color Picker Code

The code contains comments to explain what each section is doing. The color identification and LED portion is based on the Adafruit colorview example code. If you'd like to try writing up your own code then this is a useful example to work through and start with.

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 because of two things, one because I needed to work around the PWM pins for the LED and the second because the pins on the Pro Micro are not all in sequential order.

The color sensor LED and pushbutton are connected to the Pro Micro’s analogue inputs, being used as digital IO, as there were not enough digital IO pins available. They are still defined in the code as standard digital IO pins.

There is a brief routine to fade the LED between red, green and blue when starting up. This is just a visual effect which takes about 1.5 seconds to run through and can be removed if you’d like your color picker to start up quicker.

The program won’t progress past the setup if it does not establish a connection with the color sensor, it will show up as “Sensor Error” on your LCD if it cannot establish a connection. If the LED is coming on, indicating power to the sensor then check your SDA and SCL connections and that you're using the correct Arduino pins.

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 color, this is just to improve the LED visualization effect and doesn’t have an effect 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 avoid taking repeated readings before the button is released again as the actual reading and cycle time would be about 100ms, you can also play around with these values if you'd like to make your picker faster or slower.

Step 3: Installing the Components Into the Enclosure

In order to make a useful and portable device, I decided to solder the components together and mount them into a simple 3D printed enclosure.

A circuit of this complexity should probably be designed onto a PCB 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.

Step 4: 3D Print the Enclosure

I designed a basic rectangular housing for the color picker, the 3D print files can be downloaded here. You could also get creative and change up the design to suite your components and how you're going to be using your colour picker.

The color sensor is on the back so that you can hold the device over an object and pick the color with the readout shown on the front.

I printed the housing using white PLA and 20% infill, I would avoid using a colored filament for the back panel as you don’t want to introduce reflected colored light onto the surface being picked.

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.

Step 5: 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 soldered ribbon cable connections.

Start by soldering each component to your Arduino as you remove it from the breadboard and try to remove components to make up a full circuit at a time.

For example, start with the LED circuit and solder the resistors to the LED and then connect them to the Arduino before removing the push-button 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 Color sensor to make sure that you make the connections to the correct Arduino IO ports.

The Color sensor connections can be soldered onto the 7 pin female header strip (cut an 8 pin 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 open it up. You can also solder directly to the Color 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 your soldering 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 center 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 ribbon cable lengths. Try powering up your circuit again to verify that everything is working correctly before mounting the components into the housing. Ensure that none of the components or exposed terminals are touching each other, which may lead to a short circuit. You may need to add a bit of insulation tape or paper between components to avoid short circuits.

If your circuit is working correctly then you can mount your components into the 3D printed housing.

Step 6: Mount Components Into the Enclosure

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 color 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 pushbutton, LCD and LED through the holes in the front panel and glue them into place on the inside of the housing.

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 onto the components on the back of the board. Rather put glue along the edges of the board.

The micro USB port should 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 as mentioned before, you can use some insulation tape or paper to separate components - I've used some yellow tape on the back of the LCD.

Step 7: Using Your RGB Color Picker

To use your color picker, plug a micro USB cable into the port on the side of your color picker to power it up.

The startup sequence should run and then you’ll be able to pick a color, indicated by Colour Picker Ready.

Place the sensor over the color you’d like to pick and then push the button to pick the color. 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 color which has been picked.

The RGB LED is meant to give you an indication of the color which has been identified. This is just a quick way for you to check that the sensor has picked up on the correct colour and is not always an accurate representation of the color due to limitations with the LED. For example, they can’t show blacks or greys as the actual LED material is white and can only produce light in order to reproduce colors. For this same reason, darker colors also don’t show up well on the LED.

If you enjoyed this Instructable, please vote for it in the Make It Glow Contest.

Have a look at my blog for more Arduino tutorials, projects and ideas.

Make it Glow Contest

Runner Up in the
Make it Glow Contest

2 People Made This Project!

Recommendations

  • Backyard Contest

    Backyard Contest
  • Colors of the Rainbow Contest

    Colors of the Rainbow Contest
  • Water Speed Challenge

    Water Speed Challenge

40 Comments

0
EdR26
EdR26

Question 2 months ago on Introduction

I want to make this project but notice that there is no schematic that shows the wiring setup. The pictures shared are fine for most of the wiring except for the RGB LED (4 leads here) and the 10K pot (3 leads). Can you provide a full schematic?

0
Dwargh
Dwargh

Question 6 months ago

Great project! Everything went well so far! Thanks for this i'ble! :)

My problem is that my LCD backlights are not working.
If I turn the potentiometer to raise the contrast, I can read everything. But it's hard to read.

I have the same LCD part like you are using in your project.

Anyone have any idea what I did wrong? What am I missing? :/

Thank you!

0
Dwargh
Dwargh

Answer 6 months ago

It's solved. I removed the resistors for the LCD LED and the RGB LED. Now it works as expected! :)

0
banman11
banman11

Question 6 months ago

What a brilliant project!
I recon it's the only one out there like it.
I know there are several commercial colorimeters on the market. I think a decent one goes for around a few hundred US dollars.
Do you know how yours stacks up against a commercial one?
I have always been wanting one. Now's my excuse to make one!
😁

0
thediylife
thediylife

Reply 6 months ago

Thank you!
I haven't ever used a commercial one, so I'm not sure how well they work. I can tell you that this one doesn't work particularly well for dark colours (dark greys and blacks) due to the nature of the sensor trying to "illuminate" the object. If you spend some time setting up the calibration values to match your computer software/monitor colours then I don't see any reason why this couldn't be quite comparible to a commercial one.

0
banman11
banman11

Reply 6 months ago

From all the positive responses you have received I was wondering if you have any plans on or know of instructables on how to make adjustments to and how to calibrate your device to say match up what is shown on a computer monitor to the paper printout of the monitor image.
That would be extremely useful?

0
thediylife
thediylife

Reply 6 months ago

You'd have to adapt the libraries and code to run the new sensor but it looks like it would work.

0
AAndy
AAndy

Reply 6 months ago

cool, thanks & Happy Holidays

0
Datawolf
Datawolf

1 year ago

Love your projet.
I will build it if you know how to convert RGB to RAL.

0
thediylife
thediylife

Reply 1 year ago

There are a few online tools for this. There isn't a mathematical algorithm for this conversion, they're typically based on lookup tables, so it would be difficult to integrate this into an Arduino. You could convert the RGB to HEX if that would help?

0
Eduarde1
Eduarde1

1 year ago on Step 7

It seems it is not acurate at all, the yellow color of the cutter seems to be R 215, G 162, B 50. Can you calibrate it? Maybe it is better to put some led lights next to sensor?

0
pragmantic
pragmantic

Reply 7 months ago

Look at example in Adafruit library:
https://github.com/adafruit/Adafruit_TCS34725/blob...
"
// some magic numbers for this device from the DN40 application note
#define TCS34725_R_Coef 0.136
#define TCS34725_G_Coef 1.000
#define TCS34725_B_Coef -0.444
#define TCS34725_GA 1.0
#define TCS34725_DF 310.0
#define TCS34725_CT_Coef 3810.0
#define TCS34725_CT_Offset 1391.0

this might help if you tinker with the values?

https://www.google.com/search?client=firefox-b-1-d...



0
thediylife
thediylife

Reply 1 year ago

It would be fairly easy to modify the code to run the gamma table as a calibration cable for the RGB values as well. The challenge is what do you calibrate it against?

RGB is a digital construct and there isn't a physical standard for it. If you print the same RGB yellow out on four different printers you'd land up with four distinctly different physical colours, the same with monitors and displays. This is one of the reasons there are so many colour settings for displays, printers etc..

But you could definitely calibrate it for a particular application and you should get fairly good repeatability. There is a white LED next to the sensor on the module which is ulluminated for each reading.

0
MattC237
MattC237

Reply 1 year ago

Oh my...not true. As a master systems engineer & developer, I have to say... RGB is a standard just as HEX & CMYK or any of the other color standards remain. RGB is actually known as "Standard RGB" :-D Printers & monitors only show variant colors for those who've incorrectly set them up, and failed to use a correct color profile. Color settings come as "generic" for "the basic user who doesn't care if colors are slightly off"... but, there are profiles available, or you may create them, to correctly calibrate and setup your monitors &/or printers.

Red for example (RGB(255,0,0)),
is hex #ff0000
has a hue of 0° (degrees),
100% saturation and 50% lightness.
Has a light wavelength of 611.37 nm.

It's pretty standard :-)

Kind Regards

0
Eduarde1
Eduarde1

Reply 1 year ago

Hello! Thank you for response. I think you can use Pantone pallete colour to calibrate the device. Next to every colour you have the RGB code.

2FA14FB6-D560-4376-9F77-66A27E13BDBF.jpeg
0
Ed_Portland
Ed_Portland

Reply 1 year ago

I would love to be able to calibrate it. I have +15 yrs in digital printing and we used X-Rite to calibrate monitors and printers. Now that I'm not working, I can only calibrate my monitors. I would also be interested in a CMYK version but that's pushing it. I'll be giving this a try once the parts arrive :)