Sharp IR Distance Sensor
Specs (Click to Open)
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
1//Include the Analog and Math Library
2#include "frc/AnalogInput.h"
3#include <cmath>
4
5//Constructors
6frc::AnalogInput sharp{port};
7
8//Create an accessor function
9double getDistance(void)
10{
11 return (pow(sharp.GetAverageVoltage(), -1.2045)) * 27.726;
12}
The accessor function will output the range in cm.
Note
The valid Analog ports are 0-3