Unstable sharp sensor readings

Hello I have a problem with 2 GP2Y0A02YK0F ir sharp sensors . 

Both are put on the same lvl 25 cm from the ground so I want when to tilt the lvl the two sensors are to be able to tell 

from which side is turned and the angle . But I get unstable readings here is an example 

where is sensor is the substract of the 2 values and where is ouput is the substract of the mapped values .

 

sensor = -8 output = -2

sensor = -8 output = -2

sensor = -8 output = -2

sensor = -9 output = -2

sensor = -13 output = -3

sensor = -63 output = -16

sensor = 2 output = 0

sensor = -7 output = -2

sensor = -9 output = -3

sensor = 44 output = 11

sensor = 1 output = 1

sensor = -7 output = -1

sensor = 50 output = 13

sensor = -85 output = -21

sensor = -12 output = -3

sensor = -9 output = -2

sensor = -46 output = -11

sensor = -1 output = 0

sensor = 50 output = 13

sensor = -54 output = -13

sensor = 48 output = 12

sensor = 3 output = 0

sensor = -7 output = -2

sensor = -7 output = -2

sensor = -11 output = -3

sensor = 65 output = 16

sensor = -86 output = -21

sensor = 46 output = 12

sensor = 2 output = 1

sensor = -5 output = -1

sensor = -8 output = -2

sensor = -9 output = -2

sensor = -27 output = -6

sensor = -87 output = -21

sensor = -6 output = -2

sensor = -9 output = -2

You see even if the structure is stable the difference differs from times to times also once in a while one big value gets in the way .
What can I do to smooth these results ...

The correlation of your

The correlation of your sensor to output readings is near perfect so I presume your problem is temporal stability. bdk6 suggests good straightforward solutions to which I add taking a median of the three most recent values rather than an average of more. You can then get a quite stable temporal run with reduced lag from raw reading to filtered reading, compared with using an average which needs more readings for stability. This may be important for real time reading or control.

The trade-off with any form of filtering is that when there is a “true” spike in the data you will not or will hardly notice it.


Does it make a diference if i put it on the arduino pins cause I power them from the same pins in parallel ?

Also what about reflective surfaces do they really affect the results …

Hmm

I too had similar problems while working with lm35 temperature sensor.(The problem was poor connections of pins to the breadboard and the large gauge wire I used).Also I get such stray readings when I serial read from an arduino analog pin when the pin is left floating.I suggest you check your connections.

Also to filter out stray reading(though I have not worked with sharp) but speaking from experience working with ping sensors,I would evade stray readings using program code by putting an if ( value_from_Pin > 0 ){ //rest of your code}