I've been trying to figure out a way to determine a wheel (or servo) position using an infrared sensor. Instead of getting readings from a standard black and white wheel encoder and counting how many black to white transitions have passed the sensor, I want to get the position in a single reading.
I know there are nifty little thingies that you can build in a servo using magnetism to read the servo position very accurately. But those are rather expensive (i think) and where's the fun in buying if you can build it.
First i tried using an encoder wheel with a grey-scale printout instead of black and white segments.
That didn't work so well. The greyish areas worked out sort of OK, but still not good enough. The very black and very white areas were way too noisy to distinguish between differtent angles / positions of the wheel.
After that I thought it might be possible to use linear polarized foil (like they use in 3D glasses) to get very accurate readings. If you hold to sheets of polarized foil at a 90 degree angle the light is blocked. At a 0 degree or 180 degree angle, you can see through it.
So I found myself some cheap polaroid sunglasses, cut out a more or less round piece, and set up an IR LED and phototransistor on a breadboard with the two pieces in between.
To my utter surprise, the polarized foil doesn't block IR light! I shot a lame video to demonstrate.
I guess I need to use visible light: Next up is the old trusted photoresistor.. Using the setup shown below, I get very promising results. If I dim the lights in the room, I get steady readings ranging from 85 to about 260. The low readings tend to climb up after a second or so. Strange.
The stability of the readings should improve if all this is build in a dark box or servo casing or something like that. Also: the light brightens and dims every 90 degree change. So turning a wheel the full 360 degrees gives you the same readings 4 times.
The input connected to the LDR is clamped down with a 20K resistor and the light source is a yellow LED (just trying out the available colors)
All the other stuff on the board is used to hold the pieces of polarizing foil in place.
Update 25-3 :
I did some additional testing and it appears the filter I have is able to block a little bit of infrared, but not as much as I'd like. That is: it is sometimes possible to pick it up with the sensor.
I have been searching for a phototransistor that would work with visible light because the LDR will probably not be fast enough to be very useful. All the phototransistors I found work best at 900nm wavelength, but they all should work in the 400-1100nm range which includes the visible spectrum. My red LEDs give the best result with the transistors I have, which is somehow not entirely unexpected.
I noticed that a lot of light is blocked by the filter no matter which way they are oriented. As my filters used to be clip-on sunglasses and are probably tinted: that should not come as a surprise. I ordered a couple of 3D glasses (only €0,99 each). I am hoping the 3d glasses have thinner filters and will not be tinted. Perhaps they can be used to filter IR, but I don't expect that.
Update 30-3 :
Got my 3D glasses today. They are indeed less tinted than the polarizers I already had, but they dont block IR light either. They also have another filter (quarter wave?) that makes them react differently depending on which way you hold them. Hold them one way and no matter how you turn them, no light is blocked. Flip them around and they work like normal linear filters.
I'm sticking this project in a drawer for a while.
Todo:
- build it in a dark box or servo case
- make it smaller (as always)
- figure out a nice way to read which quarter of the full rotation has been read
https://www.youtube.com/watch?v=iaSSvgz_KWo?version=3