Here we will be learning how to make a color sensor. my model consists of three cardboard compartments containing an LED - one red, one blue, and one green - and an OP550B phototransistor. The LED's shine simultaneously on a solid colored card. The phototransistors are connected to an Arduino Uno, which converts the relative amounts of measured reflected light of each color into RGB components which are used to light an RGB LED the same color as the card.

Video of it working:

Step 1: Materials

To make this color sensor, you will need:

* Red LED
* Green LED
* Blue LED
* 3 phototransistors - I used OP550B's, but others could be used.
* 6 220 ohm resistors
* 3 10k ohm resistors
* Cardboard or some other divider to separate the LED's
* Breadboard or circuit board and soldering materials
* wires
* Arduino and usb cord
* Computer
* Electrical tape
* Cards of various colors - I used index cards covered in electrical tape of different colors.
<p>your circuit diagram is not at all clear , and also i m using 2n5777 phototransistors which are 3terminal transistors , i connected the base with ground as usual , i m facing a problem while calibrating the whole device , every time it shows either 655,655,655 or 0,0,0 .</p><p>and i tried altering the codes a bit but that didn't helped me either , so i am hoping that if you could help me resolve this problem .</p><p>can you please get in touch (anshmanu@icloud.com) , i want to discuss more things on Arduino .</p><p>the overall project was quite nice actually :) </p>
Love this project! Working on it right now. This is my very first Arduino project and I am a bit clueless to say the least. Do you have an image of the bottom of the board so I can see the connections more clearly? Thanks!
<p>while for different color values...we are getting almost same values on the serial monitor...what could be the problm apart from the insulation</p>
<p>Thanks for sharing !</p><p>I made an SMD version of this project.</p><p><a href="https://www.instructables.com/id/Your-Own-Color-Sensor-using-LEDs/" rel="nofollow">https://www.instructables.com/id/Your-Own-Color-Sen...</a></p>
I Have just one question. <br>Of what use is comparing colors to some one who is color blind like I am, <br>if you don't tell me what colors i am looking at ???
Hi anoniemouse,<br> <br> I had not considered that use case. If you add the following code to the setColor function, it should print the name of the color in addition to changing the color of the RGB LED. I haven't tested this code (I don't currently have access to the Arduino), but it compiles. Does this help? Thanks for your interest!<br> <br> if (color == WHITE) {<br> &nbsp;&nbsp;&nbsp; Serial.print(&quot;WHITE&quot;);<br> &nbsp; } else if (color == RED) {<br> &nbsp;&nbsp;&nbsp; Serial.print(&quot;RED&quot;);<br> &nbsp; } else if (color == YELLOW) {<br> &nbsp;&nbsp;&nbsp; Serial.print(&quot;YELLOW&quot;);<br> &nbsp; } else if (color == MAGENTA) {<br> &nbsp;&nbsp;&nbsp; Serial.print(&quot;MAGENTA&quot;);<br> &nbsp; } else if (color == BLUE) {<br> &nbsp;&nbsp;&nbsp; Serial.print(&quot;BLUE&quot;);<br> &nbsp; } else if (color == GREEN) {<br> &nbsp;&nbsp;&nbsp; Serial.print(&quot;GREEN&quot;);<br> &nbsp; } else {<br> &nbsp;&nbsp;&nbsp; Serial.print(&quot;BLACK OR OFF OR UNREADABLE&quot;);<br> &nbsp; }
Could you upload your video again, please? <br> <br>When I turn on the program and show the white card, the RGB flashes a couple of colours but it does not turn off for me to switch to the black card. Any ideas? Also-to clarify, is the last section of the code required only if we want to adjust the RGB values? If we want to use the same values you wrote, then we should just keep that part of the code commented out, correct?
Hi arnabc, <br> <br>I re-uploaded the video. Did you get it working? Let me know if you have any more questions. Good luck!
Sorry about the video - I deleted my Google Plus account a few weeks after I uploaded that video, and I didn't realize that would also delete my Youtube videos. I don't have the video with me now, but I should be able to re-upload it later this week. <br> <br>This part is explained in the missing video. Sorry for the inconvenience.: <br>To do exactly what I did with the code as-is, you should have the white card showing when you start the program. The RGB LED should flash red, then green, then blue, then white for a longer time than the colors. After no more than about 2 seconds, the light should turn off. After it detects that the white card is no longer there, it should wait for 5 seconds (while you switch to the black card) and then do calculations based on the black card. After that finishes, the LED should turn white. When the LED turns white after being off, it is ready to read cards. <br> <br>Did you set OFF to {0,0,0}? Can you post any serial output from when you tried to run it? <br> <br>The last section of the code (from &quot;//comment out the rest of this loop to just display values and not use the RGB LED&quot; to the end of the if/else block) is the part that makes the RGB LED respond to the card changing. If you comment it out, it will dump RGB values to the serial output, and the LED will stay white. Is this the block of code you are referring to? None of it is commented out in the code I posted. <br> <br>To generate the numbers I used, I ran the program with that code commented out and looked at the serial output when I showed it different cards. I noted the RGB values and the variation for each color card, and hard coded the average RGB values as the values in the ICOLOR arrays. So, to calibrate it for your cards/your background lighting, you should do the same. If you want to use the same values I wrote, you should not comment anything out. Does that answer your question?

About This Instructable



More by ekc32011:Arduino Color Sensor 
Add instructable to: