In this post we are going to construct a circuit which can detect color and trigger respective assigned relays. This project is accomplished using TCS3200 color sensor and Arduino board.
By Girish Radhakrishnan
If you haven’t read the previous article, please go through it where we have discussed the basics of color sensing using TCS3200
The proposed project may be useful, if you want a circuit to take action based on colors. There are oceans of applications based on color detection in various industrial fields.
This project will give an insight on how we can program the color sensor to detect different colors and trigger the relays.
We are going to consider the primary colors: RED, GREEN and BLUE for this project. This project can differentiate between these three colors and trigger the relays, each relay for each color.
The TCS3200 can detect any number of colors, but to keep the project understandable and to keep program code simple, we are concentrating only on the primary colors.
The above schematic is for interfacing the Arduino and TCS3200 colour sensor.
Power the Arduino with 9V adapter with at least 500mA. The transistor acts as amplifier for relay since the Arduino’s GPIO pins cannot provide sufficient current to relay.
The diode 1N4007 will absorb high voltage spikes from relay coil, protecting rest of the semiconductor components.
That concludes the hardware.
Now let’s see how to upload the code and calibrate the sensor for your requirements.
The color sensitivity can vary from module to module and ambient light can alter the color sensitivity drastically.
All the TCS3200 sensors have some variation while fabricating, you have to measure the color parameters for the sensor which you currently own, so that those parameters can be used in the code to detect the color more accurately.
To calibrate and optimize the readings for your sensor follow, the steps precisely:
Step 1: Upload the following code with completed hardware setup.
Step 2: Open the serial monitor, you will find the color parameters like this:
Bring the color object (colored paper is preferred) red, blue and green.
• Place the red colored paper close to the TCS3200 sensor.
• Note down the R, G, B readings (all three colours) while you place the red colour paper.
• Similarly note down the R, G, B reading for green and blue color papers.
• NOTE: when you place any of the 3 colors in front of the TCS3200 note down all the red, blue and green readings for each color paper, which you need to enter in the main color detection program.
Step 4: Read Step 5 and upload the main below code (color detection program)
Step 5: In the above code replace the values with your values which you noted down recently:
When you placed the red colored paper on the sensor you would have got three readings, for example R = 56 | G = 78 | B = 38.
Place the values 56, 78, 38 like this:
//For RED Colour:
int Rx1 = 56;
int Gx1 = 78;
int Bx1 = 38;
Similarly, for other two colours and upload the code.
• Open the serial monitor and place any of the three colours in front of the sensor.
• You will see the detection of colours on the serial monitor; simultaneously the corresponding colour relay gets activated.
• You have press reset button on Arduino board to deactivate the relay.
NOTE 1: The circuit may not detect the colors, if you place slightly different shade/tint of RED, GREEN, BLUE colored object/paper, after calibration. In other words, you have to use exactly same colored object/paper to detect colors and to trigger relay.
NOTE 2: Ambient light can affect the color detection so, please maintain a consistent light near the sensor while calibrating and also while detecting colors.
If you have any questions regarding this project, please express in the comment section, you may receive a quick reply.