An Arduino library for ESP32 development board that can measure distance from an analog Sharp IR sensor.
- GP2Y0A21YK0F
- Adding the library to the sketch
#include <ESP32SharpIR.h>
- Creating an istance
SharpIR sensorName(sensorModel, sensorPin);
sensorName : the name of the object
sensorModel : the model code of the sensor (e.g. GP2YA41SK0F)
sensorPin : the analog pin where the sensor Vout pin is attached
- Acquiring data
sensorName.getDistance();
sensorName.getDistance( avoidBurstRead );
avoidBurstRead : can be true or false
The above method returns an uint8_t type value that is the distance in centimeters from the sensor and the object in front of it.
By default burst reads are avoided but this causes a delay of 20ms on every call.
In order to speed up the sketch is possible to allow bust reads by setting the parameter avoidBurstRead to false, in this way:
sensorName.getDistanceFloat();
sensorName.getDistanceFloat( avoidBurstRead );
Above method returns the distance in cm, as a float value filtered by exponent filter.
sensorName.getRawDistance();
sensorName.getRawDistance( avoidBurstRead );
Above method returns just the raw distance read by the sensor, without applying any filter in cm.
sensorName.setFilterRate(float rate);
rate : a value from the range from 0.01 to 0.99.
0.01 equal to sampling 100 values and getting the average.
The SharpIR Library by Nuwan Jaliyagoda is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License
The library is based on the library 'Arduino_SharpIR', written by Giuseppe Masinos