Arduino Projects: Color Sensor

We’ve learned how to use the LCD module, the microphone module, LEDs and the potentiometer. Those are devices you will make use of most of the time.

Today, we are going to be working with the Arduino color sensor module. It is a quite unpopular piece but often very useful and easy to use. The color sensor can be used in projects like the skittle sorting machine.

This project will consist of letting the sensor read colors and using the LCD to display the current color the sensor is reading. The color sensor is quite hard to calibrate to get the perfect results thus we will display only the following 3 colors: the red, green and blue.

Arduino color sensor

Parts needed

While using the schematic below to connect the project, remember that if your Arduino board does not have separate SCL and SDA pins, you can connect the pins from the LCD to A4 and A5 (analog pins) of the Arduino. If you do so, remember to indicate the right pins in the code.

This code will read colors from our sensor using the pulseIn function because the TCS230 returns the frequency of each color (red, green, blue). With pulseIn, we can read colors and easily compare them to one another to identify the current color and display it on the LCD.

We will do it every half a second.

The program also prints those colors on the serial, just in case you don’t have an LCD. The only library that you need is for the LCD with I2C converter.

Here is the code:

The one thing that can be unclear in this code is this:

digitalRead(10) == HIGH ? LOW : HIGH

It’s just a short form of if and else. (if the read from pin 10 is HIGH, it will return LOW otherwise it will return HIGH). If and else in one line without brackets.

The best materials to use while testing the project are pieces of paper as we’ve done in the video below.

Hope this helped, and I will challenge you to go and create something amazing using the basic tools we have just made use of in the project.

You might also like:

Leave a Comment