Arduino Forum

I am starting this topic to inform you about a small lookup table based library for the Sharp GP2Y0A21YK analog IR distance sensor.The main goal is to provide a library that simplifies the usage of this particular sensor in Arduino projects.

Usage

Download the source

Place the DistanceGP2Y0A21YK folder in your Arduino1.0+ "libraries" folder

So this lib is pretty usefull. But i wonder, how can I interpret a distance measurement with a displacement at the same time? Like having a xx mm/sec or inch/min. Just like a feed rate If you may have a hint, i'm stall on this and have not much idea.

Sample the sensor from time to time and use "millis()" to calculate the time that has passed and then calculate the average displacement

Sample the sensor using fixed timing, e.g. 10 samples per second, using a periodic wake-up of the board, and then calculate the average displacement. Periodic wake-up can be achieved using this nice library: https://github.com/rocketscream/Low-Power

Have you checked my multimap article - http://arduino.cc/playground/Main/MultiMap - Wrote that because the standard map function could not handle the non-lineair function.Multimap uses two small lookup tables with interpolation between points.

You could try to make your lib more generic by keep the device specific stuff separate.

Is was not aware of your multimap code, but it might be interesting to add your approach as an extra option since it will result in a smaller code size, at the expense of some execution speed.

What you are doing in the multimap function is almost what I did in a spreadsheet to calculate my LUT values.I measured some values and calculated the intermediate points using two polynomial approximation of the tranfer function. (one for 80 to 20 cm, an other one for 20 to 5 cm).You can find the (messy) spreadsheet here: (the comments are in Dutch): http://code.google.com/p/gp2y0a21yk-library/source/browse/Calculations/CalculationsDistanceSensorTransferfunctionLUT.xls

How exactly would this make the lib more generic? Since the only hardware specific code is the actual LUT.I plan to make one generic "DistanceSensor" lib, that supports other distance sensors. (e.g. http://code.google.com/p/srf04-library ('sonar' sensor))

I currently have 5 sensors that are tied together sitting on my desk. My plan is to do this runtime testing/calibration using 5 sensors to check for inter-sensor differences. I haven't done the experiment yet because I needed some extra wires + breadboard, to connect them all at the same time.

It think the best approach would be conditional compilation with 3 options:

speed optimized: my current code

code size optimed: the multimap version using your approach

default: 4(?) bit LUT combined with multimap

A more (too?) complex solution might be:

a standard generic LUT: 8 bits

+ a 'differential' LUT for each individual sensor: using calibrated values: 4 bits

Hi Doggenj, I am newbi in Arduino Program.Now I want to make detection obstacle using arduino and 3 pieces IR Sensor GP2Y0A21YK.the IR will be working one by one by them self on 1 board Arduino.They can detect the obstacle when IR near of the obstacle.