3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.


Using an RGB LED to Detect Colours

Using an RGB LED to Detect Colours
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.
 
Remove these adsRemove these ads by Signing Up
 

Step 1Gather 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
« Previous StepDownload PDFView All StepsNext Step »
44 comments
1-40 of 44next »
Apr 25, 2012. 6:29 AM_SarahC_ says:
This is excellent!

Have you seen any problems with the red color - due to the spike in sensitivity that the LDR has?
Feb 28, 2012. 12:06 PMjaxofalltrades says:
This is pretty neat! Thanks for sharing and good luck in the contest. :)
Jan 12, 2012. 9:29 PMhaidamous says:
Hello,

I have a project and I need to detect White Red Blue and green colors.
The PIC microcontroller code is done, i just need the schematic to build my project
I must also use 4 sirenges (one for each color) for the color mixing part
I appreciate your prompt help, i need it for my project.
Plzzz

Thank you :D
Jan 12, 2012. 10:51 AMhaidamous says:
Hello,

I have a project and I need to detect White Red Blue and green colors.
I must also use 4 sirenges (one for each color)
I appreciate your prompt help.

Thank you :D
Jan 5, 2012. 9:45 PMmccoywm says:
This is a great project. I documented my results doing the same here http://uscee.wordpress.com/
Jan 4, 2012. 10:56 AMSky-Monkey says:
Nicely written -

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?

Thanks
Dec 28, 2011. 12:44 PMyardleydobon says:
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.
Dec 28, 2011. 3:47 PMyardleydobon says:
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.

Also, I suggested calibrating on a non-white target not as a criticism but as a fun way to play with your device.
Dec 15, 2011. 8:20 PMendolith says:
LEDs can be used as sensors, too.
Dec 15, 2011. 7:43 PMTheDodgyLodger says:
I want to incorporate this into a robot run greenhouse so it can tell me when the tomatoes and peppers are ripe.
Dec 15, 2011. 2:42 PMwgrube says:
Very nice instructable!
Dec 17, 2011. 9:43 PMmathman47 says:
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.
Dennis, KC9PYD
Dec 18, 2011. 4:23 AMstringstretcher says:
A stop light interpreter for blind drivers! I know a few who need this badly. Neat device, great work.
Dec 15, 2011. 10:31 AMdokcal says:
Brilliant idea, and probably the best-written instructable I've ever seen!

I've only ever programmed in BASIC, but your breakdown of the Arduino code was really easy to follow. I wish more people would take the time to explain their code, rather than just presenting it as a "black box."

Dec 15, 2011. 10:20 AMrick6213 says:
Really nice instructable, the drawings are great and easy to read and understand!
Dec 13, 2011. 7:24 AMmatt.e.jenkins says:
Hey, congrats on the LED contest!!!
Dec 9, 2011. 4:43 PMthecapt says:
Great timing! I am in the process of writing a routine for a marble sorter and was just going to use a white LED. I was thinking of doing this with RGB, but since I was only concerned with 3 marble colors I assumed that the value from the white LED would vary enough based on color. If it does not, I'll have to try with this RGB style. Even if I don't, this code is a good reference tool. Thank you very much.
Dec 9, 2011. 7:29 AMjamian says:
I think there is a slight problem here.

Red LEDs work at 2v, green LEDs work at 2.1v, and blue LEDs work at 3.6v.
The resistor should not be on the GND (common). There should be an exclusive resistor per LED. Otherwise, the blue LED will most likely be dimmed in excess.

I might be wrong tho.
Dec 9, 2011. 6:25 AMEvent Horizon says:
Nice! I've done a similar thing before, but yours is nicer.
Dec 7, 2011. 11:49 AMmatt.e.jenkins says:
Very cool, Thanks for writing this out.
Dec 7, 2011. 9:16 AMrimar2000 says:
Very very interesting. For some people it is very useful, too. Thanks for sharing it.
1-40 of 44next »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
48
Followers
20
Author:fjordcarver
Dad, maker, dreamer, hacker, painter.