Sharp IR Sensors library for Arudino by Marcal - 2014
Release 1.0 09-JANUARY-2014
Release 1.0 09-JANUARY-2014 Initial Release
Easy to use library to get steady readings from a Sharp IR Range Sensors. This library is inspired by the DistanceGP2Y0A21YK library written by Jeroen Doggen (firstname.lastname@example.org).
Download zip file here
Put the SharpIR folder in "libraries\".
Open up example project included in the zip file. Read the commented out text as it explains what the library exactly does
I have experienced that Sharp IR sensors do not deliver steady readings. To my experience 12% of the readings give values with an error up to 42% over the actual distance. What this library does is to take a bunch of measurements and calculate a mean distance, taking into account only the measurements that do not differ much from one another.
1- Import the library into your sketch (you’ve already added the library to your system):
2- Initialize the library:
SharpIR sharp(ir, 25, 93, model);
where: ir: the pin where your sensor is attached. 25: the number of readings the library will make before calculating an average distance. 93: the difference between two consecutive measurements to be taken as valid (in %) model: is an int that determines your sensor: 1080 for GP2Y0A21Y, 20150 for GP2Y0A02Y (working distance range according to the datasheets)
3- get the distance: