MJRoBot (Marcelo Rovai)
Published © GPL3+

Arduino Color Detection

On this simple tutorial, we will explore how to discover colors using an Arduino and the TCS 3200 sensor, displaying it on an LCD.

BeginnerFull instructions provided4 hours69,231
Arduino Color Detection

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Color Sensor Module Color Recognition
×1
Standard LCD - 16x2 White on Blue
Adafruit Standard LCD - 16x2 White on Blue
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Hw

Code

Code snippet #2

Plain text
    
    digitalWrite(s2, LOW);
    digitalWrite(s3, LOW);
    red = pulseIn(outPin, LOW); // Reading RED component of color
  
    digitalWrite(s2, HIGH);
    digitalWrite(s3, HIGH);
    grn = pulseIn(outPin, LOW); // Reading GREEN component of color
    
    digitalWrite(s2, LOW);
    digitalWrite(s3, HIGH);
    blu = pulseIn(outPin, LOW); // Reading BLUE component of color

Code snippet #3

Plain text
void getColor()
{  
  readRGB();
       if (red > 8  && red < 18   &&  grn >  9 && grn < 19    &&  blu > 8  && blu < 16)   color = "WHITE";
  else if (red > 80 && red < 125  &&  grn > 90 && grn < 125   &&  blu > 80 && blu < 125)  color = "BLACK";
  else if (red > 12 && red < 30   &&  grn > 40 && grn < 70    &&  blu > 33 && blu < 70)   color = "RED";
  else if (red > 50 && red < 95   &&  grn > 35 && grn < 70    &&  blu > 45 && blu < 85)   color = "GREEN";
  else if (red > 10 && red < 20   &&  grn > 10 && grn < 25    &&  blu > 20 && blu < 38)   color = "YELLOW";
  else if (red > 65 && red < 125  &&  grn > 65 && grn < 115   &&  blu > 32 && blu < 65)   color = "BLUE";
  else  color = "NO_COLOR";
}

Github

https://github.com/Mjrovai/Color-Detector

Credits

MJRoBot (Marcelo Rovai)

MJRoBot (Marcelo Rovai)

66 projects • 956 followers
Professor, Engineer, MBA, Master in Data Science. Writes about Electronics with a focus on Physical Computing, IoT, ML, TinyML and Robotics.

Comments