I notice that there is a library currently for the gp2d120(or was that the GP2Y0A21), but not gp2d12. has anyone figured out the equation for converting the ir readings from the gp2d12 to ‘real’ distances?
I wanted to compare what i have so far, which after two sets of tests, yields the following two equations
range in inches = ( 2.8203 / ir ) ^ 1.08814
range in inches = ( 2.6576 / ir ) ^ 1.11982
When tested in real-time, both of equations yield results that are pretty close below ~20 inches, but then start deviating more above that mark and by the time i hit 30in, they are off about 1 to 2 inches (one over, the other under).
The other question i have is…do these have to be recalculated for each board? (I used the cerebuino to gather the measurements to figure out the best fit equations…)
I believe so, yes. That’s why Sharp doesn’t give values in the datasheet.
Also, it’s my (possibly wrong) understanding that they’re not exactly supposed to be high-precision distance measurement tools. They’re essentially the sort of thing used to detect when someone is standing in front of a urinal.
Make sure you put a cap close to the sensor also to filter out any noise. Even at that those sensors are pretty random at longer range. Due to triangulation you can also get the same reading for something at 10cm and 5 feet (depending on the sensor).
For a urinal they might work ok, all you really care about is something breaking the beam (not how far away they are). GP2Y0A21YK is up to 80cm which is probably what you would need.
Remember when using these type of sensors never average the distance, use a median and many readings. Sort the readings (assuming you do 50) and use reading 25.
i’ve had a GP2Y0A21YK for some time, but i’ve never used it. i am using the gpd2d12 for corners. i have been doing something similar to what you mention…which is am taking multiple readings and throwing out high/low and doing the avg, as i do notice occasionally a reading that it is way off (probably interference of some kind).
i’m not hardware guy at all (i know software much better than i know hardware). What exactly does “put a cap close to the sensor” mean? how does it help filter out noise? i’ve read folks mention the same about motor controllers as well.