Color Sensor

LESSON 15: Super Cool Arduino Color Sensor Project

This first video shows just the results of this extremely exciting project!  Watch the first video if you want a quick summary showing the working project.

The second video, below shows an in depth step-by-step tutorial on how to make the project work.

OK, in the first 14 lessons we were laying the ground work for circuits and programming. Now it is time we had a little fun. This project will show you how to do an insanely cool circuit based on what you have learned already. This time we are going to use the RGB LED circuit you worked on in Lesson 13 and Lesson 14,  but this time you will set the color based on the color seen by a color sensor! That is right, we will incorporate a color sensor into the circuit. If the color sensor sees red, the LED will turn red. If it sees blue, the LED will turn blue. Our challenge in this project is to make the sensor match as many colors as well as possible.

Arduino Color Sensor
We will use an arduino color sensor to set the color of the RGB LED

There are a couple of things you will need for this project in addition to the arduino, breadboard, and RGB LED we have been using so far. The good news is the components are very affordable and can be easily ordered from amazon. First up you will need the Virtuobotix Color Sensor which you can order HERE. To connect the color sensor to your arduino you will need some male/female connecting wires, which you can order HERE.  You probably have the rest of the things you need, but I will give a complete list at the end of this lesson.

For the LED side of things you will want to use the same circuit from Lesson 13 and Lesson 14.  As a refresher, here is the schematic;

RGB LED Circuit
Circuit used to control RGB LED from an arduino

Now for this project, instead of getting the desired color from the user via the serial port, we will set the LED color by having it match colored cards we place in front of the sensor. So, we will need to figure out how to operate the sensor. It is really pretty straighforward. First up, we have to hook it to the arduino. That is probably easiest done by following this table, rather than me trying to draw a picture:

Connecting the Color Sensor to the Arduino

Color Sensor Pin
Arduino Pin
S0 GND
S1 5V
S2 pin 7
S3 pin 8
OUT pin 4
VCC 5V
GND GND

Hopefully that is clear. Remember, you must use the male/female wires described above to connect the Color Sensor to the Arduino. Unfortunately, the sensor is too big to connect to a standard size breadboard. Use the table above to carefully make the connections, but after you are done your circuit should look like this:

Color Sensor
Color Sensor and RGB LED connected to the Arduino

There are lots of wires, so double check your work against the table above.

Now,  this is the way the senor works. It will make three different readings indicating the relative “strength” of the three primary colors  . . . Red, Green and Blue.  Never fear, if you know the strength of the primary colors, you can figure out any color as they will just be different “mixes” of red,  green and blue.

Which color is read depends on the voltages you write to the S2 and S3 pins, according to this table:

S2
S3
Color Read
LOW LOW Red
LOW HIGH Blue
HIGH HIGH Green

To actually make a measurement, you need to select which color strength you want to read by doing digital writes to pins S2 and S3 according to the pins above. Then you read the color strength on the sensor OUT pin, which we have connected to Arduino pin 4. To make the measurement, you need to make a pulseIn measurement at pin 4 on the arduino. The pulseIn measurement is an arduino command that looks at the pin you specify, and looks for a pulse, and returns to you a number representing the length in microseconds of the pulse seen at the pin specified. For example, lets say we already declared a variable pulseWidth to hold the measured value. The following code would allow us to measure the pulseWidth at the outPin (make sure you have declared both variables, and you should set the pinMode of outPin to be an INPUT,  since you are reading from it;

 This measurement will return a value between 0 an 102,400. Because of this, you need to be sure to declare pulseWidth variable an unsigned int. Normal integers can only hold numbers up to +/- 32,768 an unsigned int allows only positive numbers but allows numbers up to 4,294,967,295. 

The number that is returned which we put in the variable pulseWidth above can be interpreted as such: The lower the number, the stronger the color being read. The larger the number, the weaker the color.

We need to somehow convert this rather odd number into something that means something in the real world. Well, when we write values to an RGB LED we want them to be between 0 and 255.  Also, that is a fairly standard scale to report RGB colors . . . by giving the relative strength of the compoents of R, G, and B on a scale from 0 to 255. First we need to convert 0 to 102,400 to this range.  102,400/400 = 256. Almost exactly what we want! But we need to subtract one. So, we could say that rColorStrength = (pulseWidth/400) – 1. That gets us a number between 0 and 255. Only problem is, remember that in the original pulseWidth, big numbers mean weak colors and small numbers mean strong colors, so we need to fix that. We could fix it by now saying:

rColorStrength = (255 – rColorStrength);

That simply adjusts things so that big numbers now mean strong colors. Also, you can see this example would be for reading red. You would need to repeat by setting S2 and S3 to also create gColorStrenght and bColorStrength for green and blue.

So, with this little bit of math we should have what we need to actually read R, G, and B values that fairly accurately represent the color the sensor is seeing. In the video I go through the code. I am not posting the code on this one because you need to think through it and if you get stuck, the video shows you each step.

65 thoughts on “LESSON 15: Super Cool Arduino Color Sensor Project”

  1. Hi,

    This color sensor is so amazing. I am doing a color sensor too which detects red and blue only by using TCS230. I need a clear circuitry including the sensor, may I? It is blurry by just looking at the video. I am using the code which the video is up to around 45 mins which is enough for detecting red and blue.
    Also I have a question: TCS230 has a pin OE. Why don’t we use the pin?

    1. Fiona Ting,
      I believe OE is the pin that enables the sensor, so you must connect it to HIGH when you want the sensor to work. I’m trying this with the TCS230 too, so I’ll notice you if that works for me.

    2. hi thanks paul sir for your efforts for this tutorial and Flona Ting the OE pin on tcs230 is a active low pin which enables the sensor for operation u need to connect it to ground.Ialso got cheap one one not getting accurate output.

  2. Dear Paul,
    Can you please check amazon.in or ebay.in and suggest me a good colour sensor as I am from India and the Virtuobotix Color Sensor is not available here.

    1. Joel, the only one I have experience with is the Virutabotix. The color sensor is a tricky one, and I have had several I could not make work. Sorry I can not be more helpful.

  3. I have got it using a colour sensor I got from a nearby store.Pls tell me what should be the voltage I should be supplying if I am not using my computer and instead using an adaptor of varying voltage between 1.5V to 12V.

    Thnx

    1. Hi Joel!
      I am also from india . Can you please tell me specifically which sensor did u used ….in case virtuobotix sensor is not available…please do reply

  4. Dear Paul,

    Thank you very much for your excellent Arduino tutorials! You love what you do and enjoy passing on your knowledge.

    One question on your clever color sensor project concerning sensor scaling: in the Uno environment a signed integer fits in a two-byte word, occupying 15 bits plus one for its sign. This allows values from -32,768 to +32,767. Wouldn’t type unsigned int still use those two bytes but with the sign bit as value, permitting a range of -65,536 to +65,535? I do not understand how you get to over 4 billion. If this is true then truncation might explain some of the scaling issues that pop up later in your video.

    Many thanks again!

    1. After playing with this elegant project some more, I found it helpful to calibrate the RGB Led to produce white light. Since “Green” is always the weak sibling of the three colors Leds can produce, I first turned up “Green” all the way by sending it “255” and then, using the potentiometer, mixed in the correct amount of “Red” to produce exact “Yellow.” I did the same for “Green” plus “Blue” to render the proper shade of “Cyan.” This got me RGB values of 55, 255, and 38, which I use to scale inputs to this particular RGB Led going forward.

      Some helpful information in color mixing can be found here:

      http://www.sketchpad.net/basics4.htm

  5. Do you share your code for this project anywhere on the site?
    I purchased 2 of this sensor from Amazon and I am getting very unreliable results from the sample code.

    Thanks!

    1. I go over the code in the video. I make these videos for my high school classes, and show how to do it, but dont want students to just copy and paste code. You should be able to follow the how to on the video. These color sensors can have variations, so you might have to tweak some of the parameters. Also, virtuabotix has some sample code on their site, and you might play with that.

  6. Hi Paul,I’m just wondering. What is the name of black parts on the Color Sensor? Is there any website that sell it?

    1. That creates a little bit of a pinhole lens. It really is what makes these color sensors work. Dont know anyone who sells them, but that is why I recommend the virtuabotix sensor . . . it comes with them on it.

  7. Have you tried icluding S2 HIGH, S3 LOW. This should give you the White Balance and might improve the scaling parameters. I am going to try give it a try when I try this lesson, just to see.

  8. I followed the video for writing the code, its compiling fine but the sensor reading on the Serial Monitor shows the number as follows:
    256, 256, 256
    256, 256, 256
    256, 256, 256………

    is the problem the code or the sensor?
    help please!!!!!!!!

    int redPin=11; // red ping
    int greenPin=10; // green pin
    int bluePin=6; // blue pin

    int S2=7; // Color sensore pin S2 to Arduino pin 7
    int S3=8; // Color sensor pin S3 to Arduino pin 8
    int outPin=4; // color Sensor OUT to Arduino pin 4

    int rColorStrength;
    int gColorStrength;
    int bcolorStrength;

    unsigned int pulseWidth;

    void setup() {
    Serial.begin (9600); //Turn on serial port

    pinMode(redPin, OUTPUT);
    pinMode(greenPin, OUTPUT);
    pinMode(bluePin, OUTPUT);

    pinMode(S2, OUTPUT);
    pinMode(S3, OUTPUT);
    pinMode(outPin, INPUT);

    }

    void loop() {
    // Lets star by reading Red component of the color
    // S2 and S3 should be set LOW

    digitalWrite(S2,LOW);
    digitalWrite(S3,LOW);

    pulseWidth = pulseIn(outPin,LOW);

    rColorStrength = pulseWidth/400. -1;

    rColorStrength = (255- rColorStrength);

    // Lets read green component of the color
    // S2 and S3 should be set LOW

    digitalWrite (S2,HIGH);
    digitalWrite (S3,HIGH);

    pulseWidth = pulseIn(outPin,LOW);

    gColorStrength = pulseWidth/400. -1;

    gColorStrength = (255- gColorStrength);

    // Lets read blue component of the color
    // S2 and S3 should be set LOW and HIGH Repectively

    digitalWrite(S2,LOW);
    digitalWrite(S3,HIGH);

    pulseWidth = pulseIn(outPin,LOW);

    bcolorStrength = pulseWidth/400. -1;

    bcolorStrength = (255- bcolorStrength);

    Serial.print(rColorStrength);
    Serial.print(“, “);
    Serial.print(gColorStrength);
    Serial.print(“, “);
    Serial.print(bcolorStrength);

    Serial.println(“”);

    delay(100);

    1. Hello
      I faced the same problem
      I do believe that we need a shield for the photodiode.
      I suggest you to try this :

      int s0=3,s1=4,s2=5,s3=6;
      int flag=0;
      int counter=0;
      int countR=0,countG=0,countB=0;
      void setup()
      {
      Serial.begin(115200);
      pinMode(s0,OUTPUT);
      pinMode(s1,OUTPUT);
      pinMode(s2,OUTPUT);
      pinMode(s3,OUTPUT);
      }
      void TCS()
      {
      digitalWrite(s1,HIGH);
      digitalWrite(s0,LOW);
      flag=0;
      attachInterrupt(0, ISR_INTO, CHANGE);
      timer2_init();
      }
      void ISR_INTO()
      {
      counter++;
      }
      void timer2_init(void)
      {
      TCCR2A=0x00;
      TCCR2B=0x07; //the clock frequency source 1024 points
      TCNT2= 100; //10 ms overflow again
      TIMSK2 = 0x01; //allow interrupt
      }
      int i=0;
      ISR(TIMER2_OVF_vect)//the timer 2, 10ms interrupt overflow again. Internal overflow interrupt executive function
      {
      TCNT2=100;
      flag++;
      if(flag==1)
      {
      counter=0;
      }
      else if(flag==2)
      {
      digitalWrite(s2,LOW);
      digitalWrite(s3,LOW);
      countR=counter/1.051;
      Serial.print(“red=”);
      Serial.println(countR,DEC);
      digitalWrite(s2,HIGH);
      digitalWrite(s3,HIGH);
      }
      else if(flag==3)
      {
      countG=counter/1.0157;
      Serial.print(“green=”);
      Serial.println(countG,DEC);
      digitalWrite(s2,LOW);
      digitalWrite(s3,HIGH);

      }
      else if(flag==4)
      {
      countB=counter/1.114;
      Serial.print(“blue=”);
      Serial.println(countB,DEC);
      digitalWrite(s2,LOW);
      digitalWrite(s3,LOW);
      }
      else
      {
      flag=0;
      TIMSK2 = 0x00;
      }
      counter=0;
      delay(2);
      }
      void loop()
      {
      delay(10);
      TCS();
      if((countR>10)||(countG>10)||(countB>10))
      {
      if((countR>countG)&&(countR>countB))
      {
      Serial.print(“red”);
      Serial.print(“\n”);
      delay(1000);
      }
      else if((countG>=countR)&&(countG>countB))
      {
      Serial.print(“green”);
      Serial.print(“\n”);
      delay(1000);
      }
      else if((countB>countG)&&(countB>countR))
      {
      Serial.print(“blue”);
      Serial.print(“\n”);
      delay(1000);
      }
      }
      else
      {
      delay(1000);
      }
      }

  9. Which type of voice sensor should I use and how I should it use.I really enjoy your all vedio and learn many things. Please keep moving on for us as motivation .

  10. Can someone tell me if I can use tcs230 for differentiating between different shades of the color RED? I plan on using this sensor with STM 32 microprocessor to tell whether an apple has reached it’s fully ripened stage or not. I want to know what sort of output will the sensor give and how to interpret the output??

    Pretty please…….Thanking in advance

  11. hi,
    i made the code according to your video
    but yet in serial it shows 256 , 256, 256
    can you help please
    this is my code-
    int redPin=11;
    int bluePin=6;
    int greenPin=10;

    int S2=7;
    int S3=8;
    int outPin=4;

    unsigned int pulseWidth;

    int rColorStrenght;
    int bColorStrenght;
    int gColorStrenght;

    void setup() {
    // put your setup code here, to run once:

    Serial.begin(9600);
    pinMode(redPin, OUTPUT);
    pinMode(bluePin, OUTPUT);
    pinMode(greenPin, OUTPUT);

    pinMode(S2, OUTPUT);
    pinMode(S3, OUTPUT);
    pinMode(outPin, INPUT);

    }

    void loop() {
    // put your main code here, to run repeatedly:
    digitalWrite(S2, LOW);
    digitalWrite(S3, LOW);

    pulseWidth = pulseIn(outPin, LOW);

    rColorStrenght = (pulseWidth/400)-1;

    rColorStrenght = (255- rColorStrenght);

    digitalWrite(S2, HIGH);
    digitalWrite(S3, HIGH);

    pulseWidth = pulseIn(outPin, LOW);

    gColorStrenght = (pulseWidth/400)-1;

    gColorStrenght = (255- gColorStrenght);

    digitalWrite(S2, LOW);
    digitalWrite(S3, HIGH);

    pulseWidth = pulseIn(outPin, LOW);

    bColorStrenght = (pulseWidth/400)-1;

    bColorStrenght = (255- bColorStrenght);

    if(rColorStrenght > gColorStrenght && gColorStrenght > bColorStrenght) {
    rColorStrenght= 255;
    gColorStrenght= gColorStrenght/2;
    bColorStrenght= 0;
    }
    if(rColorStrenght > bColorStrenght && bColorStrenght > gColorStrenght) {
    rColorStrenght= 255;
    bColorStrenght= bColorStrenght/2;
    gColorStrenght= 0;
    }
    if(gColorStrenght > rColorStrenght && rColorStrenght > bColorStrenght) {
    gColorStrenght= 255;
    rColorStrenght= rColorStrenght/2;
    bColorStrenght= 0;
    }
    if(gColorStrenght > bColorStrenght && bColorStrenght > rColorStrenght) {
    gColorStrenght= 255;
    bColorStrenght= bColorStrenght/2;
    rColorStrenght= 0;
    }
    if(bColorStrenght> rColorStrenght && rColorStrenght > gColorStrenght) {
    bColorStrenght= 255;
    rColorStrenght= rColorStrenght/2;
    gColorStrenght= 0;
    }
    if(bColorStrenght > gColorStrenght && gColorStrenght > rColorStrenght) {
    bColorStrenght= 255;
    gColorStrenght= gColorStrenght/2;
    rColorStrenght= 0;
    }

    analogWrite(redPin, rColorStrenght);
    analogWrite(bluePin, bColorStrenght);
    analogWrite(greenPin, gColorStrenght);

    Serial.print(rColorStrenght);
    Serial.print(“,”);
    Serial.print(bColorStrenght);
    Serial.print(“,”);
    Serial.print(gColorStrenght);
    Serial.print(“,”);
    delay(500);

    }

  12. very good tutorial, but I see a BIG MISTAKE! an int variable in Arduino Uno is 2byte – then we have 0 to 65.535 max value in unsignet int. For an int value we have the same max number but is start from – 32,768 to 32,767 , for Arduino DUE Int value have 4byte, then we have 4,294,967,295 total number ETC. And all of the problem came from this mistake “minimum value of 210- – have to use a long, for yor pulseWidth. unsigned int will have only ~65% from 102.500 total of the sensor v. This mistake is repeated in other examples – 21 lesson is another ex:. Otherwise, tutorial it is of very good quality

  13. Hi Paul

    Thank you very much for this tutorials , I have a suggestion..
    I think you need to put the sensor in tube to eliminate the surrounding lights form interfering with the color reflected by the examined colored card ..that will reduce the readings of the other colors when reading a red card for example

  14. Hi, Thanks for this tutorial. I have a question for you..
    I have a TCS3200 Color sensor… I want to programming with arduino… is Your code same the my color sensor(TCS3200)?
    Can I take the return R,G,B values from color sensor?When measuring ambient light effective?
    Thank you,have a nice day…

  15. Dear Paul Sir,
    I’m at vacation for some weeks and I had all the parts that are needed for this but, one part I forgot to bring that was the RGB LED…can I use 3 LEDS instead of the RGB LED?

    PLEASE ANSWER BACK SOON
    I like your teaching 🙂

    1. You could not get different colors, each LED would just be whatever color it is, so unless you have a R a G and a B LED, you probably are stuck.

  16. what is the applications and future scope of this project??
    can we use TCS3200 colour sensor for this project??

    1. The project is pretty much done. The purpose was to teach students, not any particular project. I know the sensor I list works, so am not sure about other ones.

  17. Hi, my name is mario, did anyone solved the problem about the 256,256,256 in the serial?
    I wrote the same code you made on the video.
    By the way I am using arduino mega I think it should not matter but I am runnin out of options and still cannot figure out what could it be.
    Greetings from Mexico

    1. I show you how to do it in the video! The purpose of the videos is to encourage YOU to learn to write code, not copy and paste. Give it a try, I think you can do it.

  18. Hello,
    first thanks for your great videos.
    On the Uno and other ATMEGA based boards, unsigned ints (unsigned integers) are the same as ints in that they store a 2 byte value. Instead of storing negative numbers however they only store positive values, yielding a useful range of 0 to 65,535.

    But the Arduino DUE stores a 4 byte (32-bit) value, ranging from 0 to 4,294,967,295.

    https://www.arduino.cc/en/Reference/UnsignedInt

  19. Hi Paul,

    Amazing tutorial videos . They have been of great help. I am facing a issue wherein I am using TCS3200 for color sensing and using the same principle as taught by you but the resultant output is 256,256,256
    256, 256, 256… continuously on the serial monitor. I would request you to suggest a solution for the same.

    Regards,
    Anurag Bansal

  20. Very informative site across the board. Found it while looking for potential help trying to sense colors to light multiple LEDs. As an absolute beginner is it possible (eventually) to use the sensor/arduino control system in the tutorial to light more than one LED with different colors? I.e. LED #1 could sense red and be lit red; then sense a different color and light another LED# 2 yellow, etc.
    Thanks. I genuinely admire your hands on approach to a better world. Continue on.

  21. Sir, this is Krish and I am really Loving your Lessons. I wish that you would explain me the reason behind attaching the pins(on sensor) to whatever pins(on arduino) So that if I use anoother sensor i could know how to go about it

  22. Will the color sensor detector color on a screen?

    Also, if mine isn’t detecting unless it is very close, do you have any tips to fix that?

    Thanks for awesome video!

  23. Hello Sir,
    I am having just one doubt

    How can I make UNO to work independently. I mean, without PC
    Is it possible?
    Hope to listen from you soon

  24. Sir,
    One thing I want to tell you. After watching your videos , really I fell in love with Arduino
    . Really sir you are awesome …. I watched till lesson 13. The way you explain in detail .love it .. I am the beginners. However I order UNO TODAY ONLY ..so that I can do some serious projects in temperature controller

    Sir how I learn the command? Can you put video, specially on Arduino command . It’s a request

    Thanks a lot , hope you will upload some more videos…

  25. What are the functions of following:

    void color (unsigned char red, unsigned char green, unsigned char blue) // the color generating function
    {
    analogWrite(redPin, red);
    analogWrite(bluePin, blue);
    analogWrite(greenPin, green);
    }

  26. Hi
    Thanks for great quality videos!
    I also used a color sensor based on TCS230 (ZX-Color http://olimex.cl/website_MCI/static/documents/Datasheet_ZX-Color.pdf), but is very different. So, while sensor of the example has 7 pins, ZX-Color has only 3 pins (one for 5v, one for ground and one for output signal). The output must be conected to analog input pin in Arduino UNO. I couldn’t find any information about how to obtain the separates R, G, B signals. Please, any help will be aprecciated

  27. Dears .

    Nothing wrong with the code .
    I had the 256,256,256 “problem” as well at first .
    After some testing I discovered I had used the analog ports on the arduino mega ( A1 -A15) instead of the digital ones ..
    Works fine once you switch the cables to the other side … 🙂
    Hopes this helps .

    Grtz

  28. Helo sir, im trying to make a colour sensor by using RGB and LDR.. is it the coding will just similar as the sensor that you used? or the LDR will affect the coding program ? can you teach me ?

  29. I used the TCS230 and didn’t have any problems. Anyone using the TCS230 that did have problem was not following the video. When you actually compare the TCS230 to the Virtuobotix Color Sensor it’s literally the same sensor. The only difference is, that there is a plastic cap on the Virtuobotix sensor. This probably does help to display colors more accurately, but it worked well enough get the colors and follow the video without it.

    You can buy this for about $2 shipped on AliExpress.
    https://www.aliexpress.com/item/Free-shipping-color-recognition-sensor-TCS230-TCS3200-Color-sensor-recognition-module/1879439760.html

  30. sir i am recently learning this arduino in u r class it is very niz and in the project color sensor i am getting a trouble like in the starting in the serial monitor it is printing 255,0,198,etc, after few min it is printing 255,251,253 like that plz help me sir and reply to it i am studying in school before it is reopened i should learn it pls sir

    int redled=11;
    int greenled=10;
    int blueled=6;

    int S3=8;
    int S2=7;
    int outpin=4;

    unsigned int plusewidth;

    int rcolour ;
    int gcolour ;
    int bcolour ;

    void setup() {
    Serial.begin(9600);
    pinMode(redled,OUTPUT);
    pinMode(greenled,OUTPUT);
    pinMode(blueled,OUTPUT);

    pinMode(S3,OUTPUT);
    pinMode(S2,OUTPUT);
    pinMode(outpin,INPUT);
    Serial.print(“red”);
    Serial.print(“,”);
    Serial.print(“blue”);
    Serial.print(“,”);
    Serial.println(“green”);

    }

    void loop() {
    // read red
    digitalWrite(S2,LOW);
    digitalWrite(S3,LOW);

    plusewidth= pulseIn(outpin,LOW);
    rcolour=plusewidth/400.-1;
    rcolour=(255-rcolour);

    // read green
    digitalWrite(S2,HIGH);
    digitalWrite(S3,HIGH);

    plusewidth= pulseIn(outpin,LOW);
    gcolour=plusewidth/400.-1;
    gcolour=(255-gcolour);

    // read blue
    digitalWrite(S2,LOW);
    digitalWrite(S3,HIGH);

    plusewidth= pulseIn(outpin,LOW);
    bcolour=plusewidth/400.-1;
    bcolour=(255-bcolour);

    if(rcolour>bcolour && bcolour>gcolour){
    rcolour=255;
    bcolour=bcolour/2;
    gcolour=0;
    }
    if(rcolour>gcolour && gcolour>bcolour){
    rcolour=255;
    gcolour=gcolour/2;
    bcolour=0;
    }
    if(gcolour>bcolour && bcolour>rcolour){
    gcolour=255;
    bcolour=bcolour/2;
    rcolour=0;
    }
    if(gcolour>rcolour && rcolour>bcolour){
    gcolour=255;
    rcolour=rcolour/2;
    bcolour=0;
    }
    if(bcolour>rcolour && rcolour>gcolour){
    bcolour=255;
    rcolour=rcolour/2;
    gcolour=0;
    }
    if(bcolour>gcolour && gcolour>rcolour){
    bcolour=255;
    gcolour=bcolour/2;
    rcolour=0;
    }
    Serial.print(rcolour);
    Serial.print(“,”);
    Serial.print(bcolour);
    Serial.print(“,”);
    Serial.println(gcolour);
    Serial.println(” “);
    Serial.println(“”);

    delay (250);

    }

    it is the program which is typed by me sir
    plzzzzzzzzzzzzz reply to it sir

  31. Sir i have a major problem i have not the same color sensor as you have i have a 5 pin color sensor with red , green blue pin and a vcc and gnd… what should i do ?

  32. If you are having problems with values (RGB Reading 255,255,255).
    It’s because some sensors just return 0-255 values, so dividing /400 it’s not needed.

    So change:
    rColorStrength = pulseWidth/400. -1;
    gColorStrength = pulseWidth/400. -1;
    bColorStrength = pulseWidth/400. -1;

    To:
    rColorStrength = pulseWidth;
    gColorStrength = pulseWidth;
    bColorStrength = pulseWidth;

    And put “OE” pin to GND.

  33. Hi Paul
    I want to say thanks for the way in which you teach the course material. I feel it’s so important not to skip any steps when introducing new material to learners of every age, especially to old codgers like myself. The internet is full of so called instructors trying to get their point across, but none do a better job of sharing their knowledge than you. It would be very easy to loose a student’s interest when the material learned has to be of a cumulative type.
    I do have a couple of questions with regards to Lesson 15.
    I did some research on the TCS3200 color sensor and discovered pins S0, 1nd S1 are used to scale the output frequency which has a typical range of 2 Hz to 500KHz,
    such that
    S0 =L, S1 =L, Power Down
    S0 = L, S1 = H, 2%
    S0 = H, S1 = L, 20%
    S0 = H, S0 = H, 100%
    You show in your table to wire S0 to Gnd, and S1 to +5V
    which would produce an Output Scaling of 2%.
    My question is, where did you come up with the range of 0 to 102,400? My project works as desired, but that number keeps nagging at me like last year’s tooth ache. ….
    Thank You.
    Is there a way to send a private email to you as well?
    Steve

  34. Hi,
    I have a big problem with output values of the sensor shown on serial interface.
    I trying several time with this codes. But it is shown more than 255 values as a output value.I know it is impossible.
    Another problem i was faced in colour recognition values.
    when I put a red paper in front of the sensor, values like this ( 255,358,492). It is shown more value than red colour. i tested it several time with different arduino board and 4 sensor.
    I can’t fix it up to now.
    can u help me to sole this problem….?
    plz…?

Leave a Reply

Your email address will not be published. Required fields are marked *