Arduino RGB Color Picker – Pick Colors From Real Life Objects

33,693

291

29

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.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

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

Be the First to Share

    Recommendations

    • Trash to Treasure Contest

      Trash to Treasure Contest
    • Raspberry Pi Contest 2020

      Raspberry Pi Contest 2020
    • Wearables Contest

      Wearables Contest

    29 Discussions

    0
    mikeulator
    mikeulator

    6 weeks ago

    I love this... I could actually use something like this sometimes. But I would put 1 or 2 really bright, white light balanced LEDs on the back for accuracy. Incandescent, flourescent, light bouncing off colored walls/ceilings, etc will all make this not very accurate since they put their own color cast on it. Flooding the subject with white light for the sensor would help, I think.

    0
    Taranach
    Taranach

    Reply 10 days ago

    Perhaps you didn't notice but this module already has a white 4150K color temperature LED right next to the sensor that provides the light for all measurements. Basically it already has the LED built in and gives the specific color temperature for calibration and adjustment purposes as necessary. Your concerns have already been accounted for in the listed sensor module.

    0
    turbo_tux
    turbo_tux

    4 weeks ago

    Which boards are compatible? I'd like to use the simplest Arduino to make it permanent...

    0
    thediylife
    thediylife

    Reply 4 weeks ago

    The most simple would be to use the Pro Micro and copy this Instructable. You should be able to use an Uno, Mega, Micro, Leonardo or Due as well.

    0
    Eduarde1
    Eduarde1

    6 weeks 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
    thediylife
    thediylife

    Reply 6 weeks 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 4 weeks 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 6 weeks 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 5 weeks 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 :)

    0
    Ed_Portland
    Ed_Portland

    Reply 5 weeks ago

    Also, if I end up making a PCB, I'll post the file. That is, unless some one has done it already.

    0
    Rehaan33
    Rehaan33

    6 weeks ago

    Where in the code is the colour sensor setup where pin 2 is attached to SDA and pin 3 to SCL. I consistently got the 'Sensor Error' feedback and am trying to troubleshoot the problem via the code...I ended up connecting the SCL pin to A5 and the SDA pin to A4 to get it to work. Great project!

    0
    thediylife
    thediylife

    Reply 6 weeks ago

    The I2C interface on Arduinos doesn't require you to define the pins, the pins are already assigned through the hardware on your board. Glad you managed to come right, I assume you're using an Arduino Uno (A4 and A5), rather than the Pro Micro?

    0
    Rehaan33
    Rehaan33

    Reply 5 weeks ago

    Yup, I am using an Arduino Nano instead.

    0
    msmith238
    msmith238

    6 weeks ago on Step 1

    Where is the rgb sensor in tinkercad??
    And Arduino??

    0
    thediylife
    thediylife

    Reply 6 weeks ago

    If you're referring to the circuit diagram, I put those on there externally. They don't have the RGB sensor or Pro Micro in Tinkercad

    0
    msmith238
    msmith238

    Reply 5 weeks ago

    ok Thanks

    0
    msmith238
    msmith238

    Reply 5 weeks ago

    do you have the file for it??

    0
    Brian clark
    Brian clark

    6 weeks ago

    Hi Thank you for the mail.
    A mate from me has used this spray on FR4 hot beds and all work o.k
    give it a test .

    0
    Datawolf
    Datawolf

    6 weeks ago

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