Build a simple RGB LED color detector with Arduino

Arduino TeamAugust 30th, 2017

You may think that visually sensing colors is a complicated operation, requiring a camera or other advanced sensors. This isn’t always the case, as engineer “Tech Martian” illustrates in the video below, using a photoresistor and RGB LED along with an Arduino 101 board.

His setup uses the LED to shine on a piece of paper in three colors, measuring the reflected light intensity. These reflections are first calibrated by reflecting light off of white and black paper, which can then be combined to show the colors presented in front of the emitter/sensor pair.

I got a comment and request from one of my Instructables that they would like to see an LED used as a color detector. Then, I got the idea that if I were to use an RGB LED, I can detect all the color spectrum possible by sending PWM signals to the LED.

Be sure to check out the project write-up for more information, including the Arduino code!

9 Responses to “Build a simple RGB LED color detector with Arduino”

  1. hmjswt Says:

    This is not color detection.
    Tihs is light intensity detection.
    This has nothing to do with color!
    Don’t fool yourself or us.
    This is very stupid.

  2. D-C Says:

    Yet it works – apparently you don’t know colour detection works (hint: absorption).

    Since you are obviously not ‘very stupid’, how about you show us how it’s really done.

  3. DemonBolt Says:

    Something is very fishy here. From what I know, that is a photorezistor. That being said, I am pretty sure it can only read the intensity of light.
    I used the Serial Monitor and it confirmed my theory.
    The board receives voltage between 1 and 5V. Inside the board, it is converted to numbers ranging from 0 to 1023
    How in the word did you make it read the colour?

  4. Nick12543 Says:

    Every different color in the light spectrum has a different light intensity, so that is what allows the photoristor to detect the color of the light. That is why a red led in a dark room will seem darker than a white led.

  5. T001mak3r Says:

    This is a clever idea but it does not work as advertised. LEDs produce light in a very narrow portion of the spectrum. With red, green, and blue LEDs there are gaps in the spectrum of light projected on the target. If the target only reflects light in one of the gaps in the LED light then the target will appear black. That is why commercial color measuring systems use broad spectrum incandescent or Xenon lamps.

  6. T001mak3r Says:

    Also, the light intensity as a function of color (wave length) is at the individual photon level. The LEDs give off a gazillion photons. The “intensity” the photo resistor measures is a combination of the photon energy lev el, the number of photons hitting the sensor, and the sensitivity profile of the photo resistor.

  7. TheRealEthicz Says:


  8. amy9238 Says:

    no thanks

  9. D-C Says:

    People need to spend more time doing and less time thinking about how it ‘should work’ and commenting.

    Look at the screen in front of you. See all those yellows & oranges and purple etc? They don’t exist, only red, green and blue (RGB) do.

    Take a magnifying glass and look at your screen, these is only RGB there. The camera used to take these photos can only detect RGB, it doesn’t have any yellow or purple detectors.

    Same with your eyes. You have three types of cones to detect light, you guessed it – RGB.

    If you shine light at an object, it will absorb some wavelengths and reflect others. A black object reflects nothing, and white reflects everything. Purple will reflect red & blue, yellow will reflect red & green.

    So if you cycle through each LED in sequence and record the intensity of the light coming back, you can determine the colour. For a purple object you will record low green and high red & blue, while yellow will record low blue but high red & green values.

    Yes it will be inaccurate due to the narrow wavelength of LEDs etc, but what more do you want from a 5 cent detector?

    Some commercial detectors work this way, others use white light and an RGB detector.

Leave a Reply

You must be logged in with your Arduino account to post a comment.