The distance sensor needs several lines of code to perform the simple task of returning the distance of the closest object, but now you can do this in one line! In addition, you can get the distance in centimters or inches.
-
Download as a zip file from GitHub.
-
Open Arduino IDE. On the top bar, select Sketch > Include > Library > Add .ZIP Library. Select the downloaded folder.
- Include library.
#include <EZDist.h>
- Create instance of class
EZDist
with pin numbers.
EZDist EZDist(trigPin, echoPin);
- Begin the serial monitor.
void setup() {
Serial.begin(9600);
}
- Print data.
void loop() {
Serial.println("Inches: " + String(EZDist.inch()) + ", Centimeters: " + String(EZDist.cm()));
}
- Under File > Examples > EZDist, select an example.
- Make the following circuit:
- Source: EZDist.cpp
- Header: EZDist.h
- Examples: