A few months ago, I saw an instructable by fjordcarver on how to build a color sensor 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:
- The sensor should have as few pins as possible.
- It should work as a stand-alone device. All calculations should be done on the device.
- It should have a triggered mode and a continuous mode.
- All parameters should be programmable.
- Calibration parameters should be stored in the EEPROM of the microcontroller.
- Firmware updates should be made possible
- 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 at tiny is that it doesn’t have a build in boot loader sector. So I needed to find a boot loader that would work on it. I tried a few and most didn’t work for me, until I stumbled on the tiny loader boot loader. 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 of course make yours with thru-hole parts
Step 1: How Does It Work?
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 colors.
With our led we send 3 different wavelengths 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 color.
These 3 bytes can then be used to reconstruct the color.
Read More: Build your own (at)tiny color sensor.