Build your own (at)tiny colour sensor. by janw
Featured
SAM_1052.JPG
SAM_1098.JPG
SAM_1046.JPG
SAM_1099.JPG
SAM_1107.JPG
SAM_1109.JPG



A few months ago, I saw an instructable by fjordcarver on how to build a coloursensor with an RGB led and an LDR. It inspired me to try whether I could improve his design.

Here are the things that I wanted:
  1. The sensor should have as few pins as possible.
  2. It should work as a stand-alone device. All calculations should be done on the device.
  3. It should have a triggered mode and a continuous mode.
  4. All parameters should be programmable.
  5. Calibration parameters should be stored in the EEPROM of the microcontroller.
  6. Firmware updates should be made possible
  7. And finally: size does matter ⇒ The smaller the better.

I did choose an smd attiny85 as the brain of the sensor. It has a small footprint but a large enough flash for the calculations. It also has just enough pins for the project (all eight pins are used).

One of the problems of the attiny is that it doesn't have a build in bootloader sector. So I needed to find a bootloader that would work on it. I tried a few and most didn't work for me, until I stumbled on the tinyloader bootloader. It's fast and only 256 bytes long and it did the trick. It also allowed me to make a sensor with only 4 pins : Vcc, GND, TX and RX.

I made my sensor with smd parts but you can ofcourse make yours with thru-hole parts



 
Remove these adsRemove these ads by Signing Up

Step 1: How does it work?

kleur.jpg
Colour is nothing more than different wavelengths of light that are reflected by objects. Each material will reflect a different combination of wavelengths, resulting in different colours.
With our led we send 3 different wavelenghts to a surface (aka red, green and blue). The LDR measures how much of each wavelength is reflected and sets its resistance accordingly. The LDR is set up with a 10K resistor as a voltage divider. The resulting voltage for each wavelength is read by the ADC of the microcontroller and the results are 3 bytes, one for each colour.
These 3 bytes can then be used to reconstruct the colour.
janw (author) says: Jan 12, 2013. 4:44 AM
You surely can use some other microcontrollers or an arduino.
kazoza says: Jan 11, 2013. 2:13 PM
Great instructable, but sadly we don't have attiny in the market here in Egypt any other recommended micro that can replace it?
fjordcarver says: Jun 8, 2012. 3:55 PM
Nice Instructable!! I haven't been on in a while, good work, it looks great.
Bot1398 says: Apr 2, 2012. 4:40 AM
We would like to see a video!!And where did you get those small RGB LED's
janw (author) says: Apr 2, 2012. 4:42 AM
I bought them at Leds-buy.nl
diy_bloke says: May 17, 2012. 5:12 AM
kreeg ik eerder al een handig adresje van jou van de smdshop, Leds-buy is ook verdomd handig om te hebben.
Vraagje, hoe programmeer jij practisch je smd microcontrollers? met een dil kan ik hem in een voetje steken en later weer in de desbtrefefnde schakeling maar met SMD gaat dat wat lastig. Enige tips?
Ik wil, als is het maar om het weer eens een keer te proberen, een smd versie van een attiny85 schakeling proberen.
diy_bloke says: May 17, 2012. 6:37 AM
(facepalm) ik had even verder noeten lezen, dan was al veel duidelijk geworden. Bedankt voor je antwoord
janw (author) says: May 17, 2012. 5:30 AM
Ik gebruik 3 verschillende methodes afhankelijk van het project:

Als het een project is waar genoeg ruimte is op de print, voorzie ik gewoon programeerpinnen zodat ik een programmer op de print kan aansluiten. Dit werkt gemakkelijk en je kan altijd nog herprogrammeren indien nodig.

Ik heb ook een aantal converters van smd naar dil daanmee kan je je smd microcontroller gewoon inpluggen in je breadboard en daar programmeren en testen. Nadeel is wel dat als de controller eenmaal gesoldeerd is, hij niet meer te programmeren valt.

Een derde methode is met een bootloader zoals beschreven in deze instructable. Ik gebruik het voetje om een bootloader in de controller te programmeren en daarna heb ik maar 2 pinnen nodig op mijn printje om te kunnen programmeren. Dit is handig op extreem kleine printjes en het zorgt er ook voor dat je de reset-pin kan gebruiken voor andere doeleinden. Nadelen zijn dat de bootloader plaats inneemt (hoewel dat op een attiny85 geen probleem mag zijn) en dat je, doordat je de reset-pin afsluit, een high voltage programmer nodig hebt wil je later een andere bootloader ofzo inlezen.

smd8 naar dil8 voetjes zijn voor minder dan 10 euro te koop op ebay en meestal nog gratis verzonden.
SAM_1178.JPGSAM_1177.JPG
diy_bloke says: May 17, 2012. 6:15 AM
OK bedankt. Ik kan hem gewoon in en uit dat voetje halen en als hij geprogrammeerd is in een schakeling solderen.
Als ik daar dan ook de SPI pinen in heb, is hij ook in die schakeling weer te progarmmeren neem ik aan :-)

Bootloader voor de 85, ja, misschien moet ik dat ook eens proberen. Gaat mij erom dat ik een heel klein schakelingetje kan maken. Nou is het met DIL ook wel klein te maken, maar wilde na 35 jaar weer eens smd proberen. Bovendien hebben ze bij smdshop leuke componenten. Enige wat ik er niet kon vinden was een 5V regulator die meer dan 100-150 mA kan leveren
Nogmaals bedankt
Chinasaur says: Mar 29, 2012. 1:19 PM
Cool design, I guess you are SMD soldering by hand!? It's nice to do SMD boards with all the SMD mounts on one side so that you can do hot plate reflow. You can still use the back face for ground plane or more complicated routing, so most simple designs can be refactored to work this way.

Thanks for info on bootloaders too.
janw (author) says: Mar 29, 2012. 10:40 PM
I solder by hand with solderpaste and a hot air solderingstation. I decided to have parts on both side to save space.
destroyer2012 says: Mar 29, 2012. 12:37 PM
I have some experience working with this idea as I am building a rubicks cube solver using an arduino micro and two of similar color sensors to detect edge face colors. One thing that I've noticed is that ambient light makes a huge difference on the result and even "blanking" the photoresistor with the LED off before sampling with the LED on doesn't help. I've sort of put that project on the back burner but I'm hoping there's a way to filter out this noise in software, OR a parallax barrier type of shield on top of the photoresistor to block external light.

How much have you experimented with different casings for the color sensor?
janw (author) says: Mar 29, 2012. 12:44 PM
Ambient light is indeed the sensors biggest enemy. I mainly used a black case for it.
destroyer2012 says: Mar 29, 2012. 2:02 PM
What I've done is wrapped black electrical tape all around the sensor and LED in like a tunnel that presses almost up the to cube's face. SO even with that setup the noise is significant.
vmgaspar55 says: Mar 29, 2012. 9:22 AM
Did you think already that can be useful for people who are blind, if the identification is made by sound types ?

janw (author) says: Mar 29, 2012. 11:21 AM
That's a very interesting thought indeed.
ynze says: Mar 26, 2012. 5:19 AM
Very nice project. Again!
janw (author) says: Mar 26, 2012. 8:31 AM
Thanks!!
stringstretcher says: Mar 25, 2012. 11:21 PM
I have often wondered about this idea for color recognition. What kind of range is possible? If you use a lens can you extend that range? I'm so new to Arduino programming that I don't think I can contribute to your code, but that doesn't mean I don't LOVE it!! I have seen it done in gas chromo devices that spin a colored filter wheel in front of a calibrated filament, sort of a reverse version of yours. Perhaps a position indicator on the wheel to coordinate the timing? Can those LEDS be read as sensors instead? They will respond to light with a charge. Do they respond to their colors? That would allow you to skip the LDR.
janw (author) says: Mar 25, 2012. 11:33 PM
It is indeed a rather crude sensor. It is capable to recognize a basic set of colours so don't expect it to sense every shade possible. I was intrigued by the original version of Fjordcarver but also a bit sceptical. But when I build it and tried it, it workt pretty good.
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!