Inhaltsverzeichnis

Distanz Sensore Sharp 2Y0A Familie

see cpp code in Githuphttps://github.com/zoubworldArduino/ZSharpIR

Sharp 2Y0A710K0F 100-500cm

Python code at https://tutorials-raspberrypi.de/infrarot-abstandsmessung-mit-dem-raspberry-pi-sharp-gp2y0a02yk0f/

Model: „100500“ [100cm to 500cm]

Based on the SHARP datasheet we can calculate the linear function:

 y = 137500x + 1125 which gives us: 1 / ((Volt - 1125) / 137500) = distance_in_cm (For distance > 100cm) 

Python code

#!/usr/bin/python
 
import spidev
 
spi = spidev.SpiDev()
spi.open(0,0)
 
 
def readChannel(channel):
  val = spi.xfer2([1,(8+channel)<<4,0])
  data = ((val[1]&3) << 8) + val[2]
  return data
  
if __name__ == "__main__":
  v=(readChannel(0)/1023.0)*3.3
  dist = 16.2537 * v**4 - 129.893 * v**3 + 382.268 * v**2 - 512.611 * v + 301.439
  print "Distanz: %.2f cm" % dist

Sharp 2Y0A21YK 10-80cm

Formel

Model: „1080“ [10cm to 80cm]

Volt Distance
2,610
2,112
1,8514
1,6515
1,518
1,3920
1,1525
0,9830
0,8535
0,7540
0,6745
0,6150
0,5955
0,5560
0,565
0,4870
0,4575
0,4280

Using MS Excel, we can calculate function (For distance > 10cm) :

Distance = 29.988 X POW(Volt , -1.173)