Color Sensor

This project involves the construction of a sensor capable of detecting colors using RGB LED and a photodiode

Similar projects worth following
This project involves the construction of a sensor capable of detecting colors using RGB LED and a photodiode

This project involves the construction of a color detector from an Arduino board, a photodiode and LED RGB

Arduino Project Code

Zip Archive - 3.85 kB - 03/18/2016 at 21:08


Project with all documentation

Zip Archive - 2.31 MB - 03/17/2016 at 18:37


Portable Network Graphics (PNG) - 112.43 kB - 03/17/2016 at 18:35


Portable Network Graphics (PNG) - 124.11 kB - 03/17/2016 at 18:35


  • 1 × Arduino UNO
  • 1 × LED RGB LED RGB Luckylight LL509RGBC4
  • 1 × Photodiode Fotodiodo BPW21R photodiode visible light range of wavelengths of light received is similar to the human eye, used to detect the refraction of colors on the surface.
  • 1 × LT1490A integrated Integrated containing 2 operational amplifiers, used one of them to create the transimpedance amplifier that will convert and amplify the signal voltage of the photodiode.
  • 1 × Button Button: Used to start the sequence lighting and reading the photodiode

View all 9 components

  • 1
    Step 1

    Explanation circuit

    The circuit has two main parts, the transimpedance amplifier and resistors settings RGB LED:

    Transimpedance amplifier

    This circuit serves to convert the intensity of the photodiode into a voltage and amplifying the signal of this, the resistance I was chosen to amplify the signal to acceptable values, the capacitor for filtering the signal, the integrated used is named before the pin negative integrated is 2, pin 3 is the positive pin, pin 1 is the output of OAMP, pin 4 is gnd that connects to gnd arduino and pin 6 is the pin that connects to 5v in arduino. Although the signal was acceptable we have changed the reference voltage Arduino manually, for this we have connected the 3.3 volt salidad arduino Aref, thus the reference voltage is 3.3V, making values showing in A0 be greater since the vref is lower than before (previously 5V).

    The reference used was:

    Resistance and LEDs

    Each leg rgb has different resistance for calibrating the power emitted color so that the optical sensor receives the same power with each color when reflected by a white surface, it is important to note that the power of each LED color is different in a commercial led, and that the sensitivity of the colors is also different in the photodiode (it is more sensitive to green than red or blue). Part of red has a total resistance of 220 ohm formed by two resistors in series (100 + 120), the portion of blue has a total resistance of 250 ohms (100 + 150) and the portion of green has a resistance of 10 ohm . This setting is for the LED and photodiode used in this circuit, using another sensor or other RGB LED should be recalibrated. The method used was 3 colors reflect a pure white surface as possible and record the values obtained in the photodiode. Note that the led to be common anode is connected to the digital inputs of arduino (in this case 5,6 and 7) on the negative side, to make it work instead of a HIGH level we introduce a LOW level arduino.

  • 2
    Step 2


    The code consists of two functions, one reads the colors and the other passes a 256 rgb format.

    At the beginning of the code variables are created and told to arduino that uses an external reference, in this case the 3.3v which are connected to Aref.

    The reading portion LED lights, wait 500ms (photodiode has time to notice color differences, it is usually very low, with this amount of time left over much but it's more to display the visual effect of changing a color to another) takes 10 readings and computes the average of these 10 readings, after it saves the value in an array, performs the same operation with the green and blue.

    Part 256 format divides the values of each color array for the maximum value to reflect against a target of each color (in our case we obtain a value of 600) and multiplied by 256 to obtain the RGB value.

    These two functions are called in the loop loop and after that in the Serial written to be read by processing.

    The code expecting a change in the pin which is connected the button to start the reading sequence, the PIN pad is usually found in state high except when you press passing LOW, have an if checking this value and running the rest of the code when there is a LOW on pin D8 arduino.

    Arduino will comment the code and processing so you can put it on page

    The reference used to pass the values obtained in the photodiode 256 is values:

    Especially the called function Checkcolour.

  • 3
    Step 3

View all 3 instructions

Enjoy this project?



mishragnit1992 wrote 04/20/2018 at 19:31 point

Hi....I need a code which can give the photodiode's voltage output when different colors of light is incident on it with the help of RGB led. Thank you!

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates