Sharp IR Distance Sensor

../../_images/sharp-ir-1.svg

Specs (Click to Open)
Sharp IR Specs

Function

Min

Nom

Max

Input Voltage

4.5VDC

5.0VDC

7.0VDC

Output Voltage

-0.3VDC

VIN + 0.3VDC

Range

10 cm

80 cm

Current

30mA

40mA

Operating Temperature

-10˚C

60˚C

Storage Temperature

-40˚C

70˚C

Programming

 1//import the Analog Library
 2import edu.wpi.first.wpilibj.AnalogInput;
 3
 4//Create the Analog Object
 5private AnalogInput sharp;
 6
 7//Constuct a new instance
 8sharp = new AnalogInput(port);
 9
10//Create an accessor method
11public double getDistance()
12{
13    return (Math.pow(sharp.getAverageVoltage(), -1.2045)) * 27.726;
14}

The accessor method will output the range in cm.

Note

The valid Analog ports are 0-3