Skip to content

gadhagod/EZDist

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EZDist

An Arduino library to make usage of the HC-SR04 as easy as blinking an LED.

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.

Installation

  1. Download as a zip file from GitHub.

  2. Open Arduino IDE. On the top bar, select Sketch > Include > Library > Add .ZIP Library. Select the downloaded folder.

Usage

  1. Include library.
#include <EZDist.h>
  1. Create instance of class EZDist with pin numbers.
EZDist EZDist(trigPin, echoPin);
  1. Begin the serial monitor.
void setup() {
    Serial.begin(9600);
}
  1. Print data.
void loop() {
    Serial.println("Inches: " + String(EZDist.inch()) + ", Centimeters: " + String(EZDist.cm()));
}

Functions

Examples

  1. Under File > Examples > EZDist, select an example.
  2. Make the following circuit:

3. Run the example.

Files