Components and supplies
Solderless Breadboard Full Size
9V Battery Clip
10k Variable Resistor
Jumper wires (generic)
tcs3200 color sensor
Male/Female Jumper Wires
9V battery (generic)
Resistor 100 ohm
Male/Male Jumper Wires
RGB Backlight LCD - 16x2
Tools and machines
Arduino Uno
Project description
Code
untitled
c_cpp
1#include <LiquidCrystal.h> 2LiquidCrystal lcd(2, 3, 4, 5, 6, 7); 3 4#define outPin 8 5#define s0 9 6#define s1 10 7#define s2 11 8#define s3 12 9 10 11// Variables 12int red, grn, blu; 13String color =""; 14 15 16void setup(){ 17 Serial.begin(9600); 18 19 pinMode(s0, OUTPUT); 20 pinMode(s1, OUTPUT); 21 pinMode(s2, OUTPUT); 22 pinMode(s3, OUTPUT); 23 pinMode(outPin, INPUT); //out from sensor becomes input to arduino 24 25 // Setting frequency scaling to 100% 26 digitalWrite(s0,HIGH); 27 digitalWrite(s1,HIGH); 28 29 lcd.begin(16, 2); 30 lcd.clear(); 31 lcd.setCursor (3,0); 32 lcd.print("Welcome To"); 33 lcd.setCursor (1,1); 34 lcd.print("Color Detector"); 35 delay(2000); 36 lcd.clear(); 37} 38 39void loop(){ 40 getColor(); 41 printData(); 42 showDataLCD(); 43} 44 45/* read RGB components */ 46void readRGB(){ 47 red = 0, grn=0, blu=0; 48 49 int n = 10; 50 for (int i = 0; i < n; ++i){ 51 //read red component 52 digitalWrite(s2, LOW); 53 digitalWrite(s3, LOW); 54 red = red + pulseIn(outPin, LOW); 55 56 //read green component 57 digitalWrite(s2, HIGH); 58 digitalWrite(s3, HIGH); 59 grn = grn + pulseIn(outPin, LOW); 60 61 //read blue component 62 digitalWrite(s2, LOW); 63 digitalWrite(s3, HIGH); 64 blu = blu + pulseIn(outPin, LOW); 65 } 66 red = red/n; 67 grn = grn/n; 68 blu = blu/n; 69} 70 71/***************** 72* Showing captured data at Serial Monitor 73******************/ 74void printData(void){ 75 Serial.print("red= "); 76 Serial.print(red); 77 Serial.print(" green= "); 78 Serial.print(grn); 79 Serial.print(" blue= "); 80 Serial.print(blu); 81 Serial.print (" - "); 82 Serial.print (color); 83 Serial.println (" detected!"); 84} 85 86///***************** 87//* Showing capured data at LCD 88//******************/ 89void showDataLCD(void){ 90lcd.clear(); 91lcd.setCursor (0,0); 92lcd.print("R"); 93lcd.print(red); 94lcd.setCursor (6,0); 95lcd.print("G"); 96lcd.print(grn); 97lcd.setCursor (12,0); 98lcd.print("B"); 99lcd.print(blu); 100 101lcd.setCursor (0,1); 102lcd.print("Color: "); 103lcd.print(color); 104} 105 106 107 108void getColor(){ 109 readRGB(); 110 111 if(red>9 && red<15 && grn>20 && grn<23 && blu>15 && blu<18) color = "RED"; 112//else if(red>16 && red<29 && grn>20 && grn<24 && blu>19 && blu<24) color = "ORANGE"; 113else if(red>17 && red<20 && grn>16 && grn<20 && blu>15 && blu<19) color = "GREEN"; 114else if(red>12 && red<15 && grn>14 && grn<17 && blu>12 && blu<16) color = "BEIGE"; 115else if(red>11 && red<14 && grn>9 && grn<12 && blu>7 && blu<9) color = "DARKGREEN"; 116else if(red>21 && red<27 && grn>17 && grn<20 && blu>10 && blu<14) color = "BLUE"; 117else if(red>9 && red<13 && grn>11 && grn<15 && blu>13 && blu<16) color = "YELLOW"; 118else if(red>10 && red<14 && grn>11 && grn<15 && blu>7 && blu<12) color = "WHITE"; 119else if(red>22 && red<26 && grn>22 && grn<26 && blu>17 && blu<20) color = "BLACK"; 120else color = "NO_COLOR"; 121}
untitled
c_cpp
1#include <LiquidCrystal.h> 2LiquidCrystal lcd(2, 3, 4, 5, 6, 7); 3 4#define 5 outPin 8 6#define s0 9 7#define s1 10 8#define s2 11 9#define s3 12 10 11 12// 13 Variables 14int red, grn, blu; 15String color =""; 16 17 18void setup(){ 19 20 Serial.begin(9600); 21 22 pinMode(s0, OUTPUT); 23 pinMode(s1, OUTPUT); 24 25 pinMode(s2, OUTPUT); 26 pinMode(s3, OUTPUT); 27 pinMode(outPin, INPUT); //out 28 from sensor becomes input to arduino 29 30 // Setting frequency scaling to 100% 31 32 digitalWrite(s0,HIGH); 33 digitalWrite(s1,HIGH); 34 35 lcd.begin(16, 2); 36 37 lcd.clear(); 38 lcd.setCursor (3,0); 39 lcd.print("Welcome To"); 40 lcd.setCursor 41 (1,1); 42 lcd.print("Color Detector"); 43 delay(2000); 44 lcd.clear(); 45 46} 47 48void loop(){ 49 getColor(); 50 printData(); 51 showDataLCD(); 52} 53 54/* 55 read RGB components */ 56void readRGB(){ 57 red = 0, grn=0, blu=0; 58 59 60 int n = 10; 61 for (int i = 0; i < n; ++i){ 62 //read red component 63 64 digitalWrite(s2, LOW); 65 digitalWrite(s3, LOW); 66 red = red + pulseIn(outPin, 67 LOW); 68 69 //read green component 70 digitalWrite(s2, HIGH); 71 digitalWrite(s3, 72 HIGH); 73 grn = grn + pulseIn(outPin, LOW); 74 75 //read blue component 76 77 digitalWrite(s2, LOW); 78 digitalWrite(s3, HIGH); 79 blu = blu + pulseIn(outPin, 80 LOW); 81 } 82 red = red/n; 83 grn = grn/n; 84 blu = blu/n; 85} 86 87/***************** 88* 89 Showing captured data at Serial Monitor 90******************/ 91void printData(void){ 92 93 Serial.print("red= "); 94 Serial.print(red); 95 Serial.print(" green= 96 "); 97 Serial.print(grn); 98 Serial.print(" blue= "); 99 Serial.print(blu); 100 101 Serial.print (" - "); 102 Serial.print (color); 103 Serial.println (" detected!"); 104} 105 106///***************** 107//* 108 Showing capured data at LCD 109//******************/ 110void showDataLCD(void){ 111lcd.clear(); 112lcd.setCursor 113 (0,0); 114lcd.print("R"); 115lcd.print(red); 116lcd.setCursor (6,0); 117lcd.print("G"); 118lcd.print(grn); 119lcd.setCursor 120 (12,0); 121lcd.print("B"); 122lcd.print(blu); 123 124lcd.setCursor (0,1); 125lcd.print("Color: 126 "); 127lcd.print(color); 128} 129 130 131 132void getColor(){ 133 readRGB(); 134 135 136 if(red>9 && red<15 && grn>20 && grn<23 && blu>15 && blu<18) color = "RED"; 137//else 138 if(red>16 && red<29 && grn>20 && grn<24 && blu>19 && blu<24) color = "ORANGE"; 139else 140 if(red>17 && red<20 && grn>16 && grn<20 && blu>15 && blu<19) color = "GREEN"; 141else 142 if(red>12 && red<15 && grn>14 && grn<17 && blu>12 && blu<16) color = "BEIGE"; 143else 144 if(red>11 && red<14 && grn>9 && grn<12 && blu>7 && blu<9) color = "DARKGREEN"; 145else 146 if(red>21 && red<27 && grn>17 && grn<20 && blu>10 && blu<14) color = "BLUE"; 147else 148 if(red>9 && red<13 && grn>11 && grn<15 && blu>13 && blu<16) color = "YELLOW"; 149else 150 if(red>10 && red<14 && grn>11 && grn<15 && blu>7 && blu<12) color = "WHITE"; 151else 152 if(red>22 && red<26 && grn>22 && grn<26 && blu>17 && blu<20) color = "BLACK"; 153else 154 color = "NO_COLOR"; 155}
Downloadable files
Tutorial Video.mp4
Tutorial Video.mp4
r_hdXuOTYTr4.png
r_hdXuOTYTr4.png
Tutorial Video.mp4
Tutorial Video.mp4
r_hdXuOTYTr4.png
r_hdXuOTYTr4.png
Comments
Only logged in users can leave comments