I am going to show you how you can use an RGB LED and a Cds photocell as a colour sensor for a micro-controller. I will illustrate the method to retrieve a colour using Arduino, and I will show you a how you can verify the colour being scanned with a small Processing sketch.

We will be making this colour sensor on a breadboard, but it is easily transferred onto a prototyping board, and for those who fab their own boards, this would be an awesome kit that is super cheap to throw together. I am sure it would only take about two minutes to write a gerber file for this circuit and make a nice little finished sensor.

Step 1: Gather Some Parts

For this sensor you will need
  • a breadboard (not required, but it is how I will walk you through it.)
  • an RGB LED (alternatively you could use 3 LEDs)
  • A 220 ohm resistor
  • A CdS photocell (these can be salvaged out of all kinds of things like nightlights or garden lamps)
  • An Arduino, or a clone. I am using a RBB in this example

Tools you will need
  • A computer
  • a cable to upload to your Arduino
<p>Hi! Super cool project! I followed your instructable, uploaded my code, and &quot;balanced&quot; for white and black. However, even after balancing the serial monitor was reporting crazy values (in the thousands and negative) for each of the colors. I was wondering if anyone else had this problem or if you have any ideas of what could be going wrong. I have included a photo of my setup and the code is just the one posted. </p>
Can i detect the colour of an led with this project? Or do we need any modification help please need urgently.
<p>Good question, I'm looking to do this too so hope it can be done. My LED detection needs to be quite quick as LEDs are only on for a short time.</p>
<p>Hi,<br>This looks like a really exciting project and I'd like to ask you something.<br>I'd like know how accurate the color detection is. Sorry if this is a stupid question, I have no experience in the field. I'm a graphic designer and illustrator and lately I've been feeling a dire need for a real life color picker. A few devices like that exist already, but they all come from Kickstarter (which is okay by itself, but I avoid first generation Kickstarter gadgets because of past experiences).</p><p>So what I'd like to know is whether I can trust the color detection device to pick the color of say a person's skin and use that color in illustration work.<br></p>
<p>Not working for me, any common problems i should address?</p>
<p>Hi! I just want to say that this is one of the cleanest, most helpful instructables I've ever seen! The way you presented the code makes perfect sense, and I wish it became a standard practice for all Arduino texts. I am relatively new, and I didn't even need to build this (although I plan to!) to understand exactly how it works, thanks!!</p>
<p>good job </p>
<p>Thanks a lot.</p><p>I made a few adjustments, like a continual update in colour that was sensed by using three photocells (one for each colour). The code and explanation of it really helped a lot.</p>
<p>why not just put the call to <strong>setBalance() </strong>in startup?<br><br>Amazing project :) I'm working on a PCB for it now, so I can use this in some of my upcoming projects :D</p>
<p>How small can the object be for the photocell to detect the color? Could this model be used to detect the wavelength of something in a solution, like a protein?</p>
<p>No reason why not, as long as you can get it into a light proof box. I've seen it done before...</p>
<p>I really love this and i just tried it and works greaaat !!!! and this is very well explained, i only have one question,<br>can you explaine to me how did you find this please ? <br>c<strong>olourArray[i] = (colourArray[i] - blackArray[i])/(greyDiff)*255</strong></p>
<p>this is excelent !!!!!! and very well explained !!</p><p>I tried it and it works very good !! :D thank youu !!</p><p>does the balancing need to be done each time runing the programme ?</p>
<p>Thanks for the exerted effort ; but there is something i don't get - Excuse me i'm a beginner - ... what 's the use of the three leds ( red , green and blue ) ? iam not using RGB led ... are they indicators for the values read from the photocell depending on the colors applied and detected and though will be lightening separately ? or they are already working in the beginning of the code and we are using them for calibration ??</p>
<p>hi,</p><p>can you send me the schematic or the circuit diagram? renel14@yahoo.com</p><p>thank you.</p>
<p>It looks like the author already put the schematic in the tutorial.</p>
<p>I used this code as a general example for my color sensor. I'm still learning a few things about arduinos and coding, so I have just a few questions for curiosity.</p><p>1) Where did you derive the equation to find the actual color in the check color function?</p><p>2) Why did you use the tally in the for loop in the getreading function? why didn't you just use reading?</p><p>Thanks!! Also, great tutorial!!!</p>
<p>Hi dear, i have need of this project how can built it and i was also tried to make this type of project named {Arduino magic light with touch foil} and this named project you can search in google, but i couldn't make it. and you project is so simple so can you send me overall discriptioins of your project at bcs.waseem@yahoo.com. please</p>
<p>can u send me the more specific schematic? ive tried the schematic given but it wont work. email: farzul_92@yahoo.com</p>
If I put red in front the R value is highest, same for G and B. How do I detect black? Or white?
so that means you will use the RGB LED to detect colors. Isn't it? <br>Also your idea is an awesome one. But it will be better if it can sense colors with a white led by using the technique of the RGB combination. I am going to make one with three LDRs and a small RGB LED to show which color it is.
hi there.. im an undergrad doing a project with sensors.. and I find this very useful.. but I just wanna check is this sensor able to detect different shades of colour.. for example, blue.. can it detect different shades of blue like coral blue/navy blue/royal blue.. and for red..
Hey it is a very helpful tutorial. I too wanna make one but the color output to be in an audio form. The one like my speaking colour sensor. What should be special requirements for that?
hello..could you pls send me a schematic of this project..because i want to put a LCD to show the color that is being detected, so that i can know where should i put it
thank you for the idea!!!
My son is color blind. Often times he'll ask us what color something is. Could this help with that. Is it able to detect colors that are not real brigh, such as in clothing?
This is excellent! <br> <br>Have you seen any problems with the red color - due to the spike in sensitivity that the LDR has?
Not so much, balancing against the white and black is important. Basically you are subtracting the reflection recieved from the black (theoretically 'no reflection') before deciding what colour you are seeing. each colour is flashed seperate and has its own balancing value. This does a fairly decent job at correction. <br>If you are having difficulty with a certain range, you can 'trick' it to perform better by changing your black balance. Might have been a good idea to add a pot for fine tuning without rescanning. Thanks for the compliment. Not much to it, throw one together and play. Cheers.
This is pretty neat! Thanks for sharing and good luck in the contest. :)
Hello, <br><br>I have a project and I need to detect White Red Blue and green colors.<br>The PIC microcontroller code is done, i just need the schematic to build my project <br>I must also use 4 sirenges (one for each color) for the color mixing part<br>I appreciate your prompt help, i need it for my project. <br> Plzzz<br><br>Thank you :D
Sounds like an interesting project, but it is well beyond the scope of this instructable.
Hello, <br><br>I have a project and I need to detect White Red Blue and green colors.<br>I must also use 4 sirenges (one for each color) <br>I appreciate your prompt help.<br><br>Thank you :D
This sensor will help you with detecting the colours.
This is a great project. I documented my results doing the same here http://uscee.wordpress.com/
Great Job!! Glad to see that everything works well. Nice documentation too.<br> Did you try out the processing sketch? It is a quicker way to see the colour.<br> I noticed that you will be working on getting an LED to light the same colour next, check out my <a href="http://www.instructables.com/id/Magical-Chameleon-Lamp/" rel="nofollow">Magical chameleon lamp</a> project if you need any pointers.<br> Cheers!
Nicely written - <br><br>I will put it together and try it, but until then - curious if know how surface finish/texture of the object being scanned effects the reading. Also, as a derivative of that question, will it sense equally well through a clear film, glass, etc?<br><br>Thanks
It should work fine through a film so long as no frequecies are being blocked. Reflectivity will play with the readings a bit.<br>Cheers.
I think it should be noted that the colors output are qualitative only. The RGB values output by this device are from it's own non-standard color space that is not the same as sRGB (i.e. the RGB displayed by a monitor). Your code also assumes that LEDs and photoresistors have linear responses which they do not. Calibration should only need to be done once, if the calibration values are stored in the EEPROM. However, it might be interesting to see what strange colors you get when you calibrate using a non-white target.
I don't claim that the values output by the sensor are the the same output as a monitor, only that it is easy to ouput the colour that the sensor 'sees' to the monitor, given that the values are in the same range. Have you tried it out? Or are you finding flaws in theory? I find that it gives quite accurate results. I.e the colours being displayed on the monitor very closely resemble the object being scanned. <br>You can certainly mess with the readings by providing a yellow sample in place of white. But that would be true of just about anything. Just try wearing a pair of yellow ski goggles around and see how effective your own colour perception becomes. <br>
I'm not saying that this device doesn't work. I'm sure it works well enough. I'm saying that it should be noted that the results are qualitative only. It can't be used to take accurate, quantitative measurements because of nonlinearites and its unknown color space. Your intro image makes it look like you are using your device to measure sRGB, which it can't do as is. It's not my intention to disparage your work, but simply to clarify your device's limitations.<br><br>Also, I suggested calibrating on a non-white target not as a criticism but as a fun way to play with your device.
Try it out. then we can discuss the limitations. It works fantastically, not moderately well. The colour put in front of it IS accurately displayed to the screen. 'nuff said.<br>I notice that we are in some of same competitions. ;) Cheers.
LEDs can be used as sensors, too.
Yes they can, but I don't think they would have the sensitivity for this. Maybe if you took a reading from a Red housing one, a green housing one, and a blue housing one(do they make those) and really padded the numbers.......hmmm, I might look into it in the future. But my gut says that it probably would not have the sensitivity of this setup.
I want to incorporate this into a robot run greenhouse so it can tell me when the tomatoes and peppers are ripe.
Cool idea, I want to see that.
Very nice instructable!
Perfect Instructable. I've have everything except for the CDS cell. Making a run to the Shack tomorrow. Very well written - covers the subject very thoroughly. Thanks. Hope you win something with this. I'm now a follower and I voted.<br>Dennis, KC9PYD
Cool, thank you. Let us know how it turned out.
A stop light interpreter for blind drivers! I know a few who need this badly. Neat device, great work.

About This Instructable




Bio: Dad, maker, dreamer, hacker, painter.
More by fjordcarver:Make A 2D Video Game with UnityAcoustic/Electric Cookie Tin UnitarMake a Keepsake Book of your Child's Artwork
Add instructable to: