Simple RGB Color Detector Using Arduino




Introduction: Simple RGB Color Detector Using Arduino

How do you see colors?

Light is an electromagnetic wave that is available in our universe. As human being we see only a part of the whole Electromagnetic spectrum.

Assume a red ball: When the light hits its surface, it reflects the red color (wavelength) and absorbs all other colors.

How color sensor works?

Assume we have red ball and blue one. Consider the reflected brightness comparison;

If we shined red light (e.g. red LED) and measured the reflected brightness using LDR (Light-Dependent Resistor). We will find out that the red ball will reflect more light than the blue ball.

Now if we shined blue LED, the blue ball will reflect more light than the red ball. The same concept you can do to detect green color.

Why using RGB?

The RGB color model is an additive color model in which red, green, and blue light are added together in various ways to reproduce a broad array of colors.

Step 1: Required Components

  1. LDR (Light-Dependent Resistor)
  2. Red LED
  3. Green LED
  4. Blue LED
  5. Three Resistors (330 ohm)
  6. One Resistor (100k ohm)
  7. Arduino ( I used Nano)
  8. Breadboard Wires and USB cord
  9. Black Tape and paper

Step 2: Circuit Design

The output Red LED is attached to digital pin 2, through 330 ohm resistor
The output Green LED is attached to digital pin 3, through 330 ohm resistor
The output Blue LED is attached to digital pin 4, through 330 ohm resistor

The LDR with 100k ohm resistor forms a voltage divider circuit, its output is attached to Analog input pin 0

Step 3: Breadboard Layout

Step 4: Sensor Isolation

  1. Isolate the LDR from the LEDs by a black paper or a black tape. Because the LDR should sense the reflected light from the object, so an isolation between the LDR and the direct LED illumination should be applied.
  2. Isolate the whole sensor from the surrounding lights by another black tape.

The Black color is used because it absorbs all light waves

Step 5: ​Download My Source Files

Download my source files ( Code and Circuit).

Step 6: Testing

The sensor is capable of distinguishing between Red-Green-Blue colors, from a distance (around 2 cm).

Be the First to Share


    • Science Fair Challenge

      Science Fair Challenge
    • Make It Modular: Student Design Challenge

      Make It Modular: Student Design Challenge
    • Trash to Treasure Contest

      Trash to Treasure Contest



    5 years ago

    I just tried something very similar to this and the LDR was giving me very close results for any color. If the object was blue, the values would show all with in twenty points of the next, when red they would all be lower but still within twenty or so points. Like the color had no influence and it was strictly light intensity being measured. I isolated the direct light from the LEDs with "smoked"(I charred it) paper and no better results. Lowering the resistance to the green because it seemed dim didn't change enough to explain anything. This seems outside the code and hardware outside the Arduino. I'm using a Nano.
    Any pointers.



    5 years ago

    Nicely done!


    Reply 5 years ago