RGB Color Picker
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:
- Arduino Pro Micro (Or Other) – Buy Here
- TCS34725 RGB Sensor – Buy Here
- 16 x 2 LCD Panel – Buy Here
- Pushbutton – 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.
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.
L
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.
TipQuestionComment
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.
- Comments(2)
- Likes(1)