Skip to content

Arduino Library for HC-SR04 Ultrasonic Ranging Module

Notifications You must be signed in to change notification settings

fderrico/HC_SR04

Folders and files

NameName
Last commit message
Last commit date

Latest commit

27bb287 · Jan 20, 2017

History

11 Commits
Jan 15, 2017
Jan 20, 2017
Jan 16, 2017
Jan 19, 2017

Repository files navigation

HC_SR04

DESCRIPTION: 

Arduino Library for HC-SR04 Ultrasonic Ranging Module with MULTI MODULE SUPPORT  

  • Library uses interrupts for measuring sound reflection times. 
  • Library uses only SI measurement units and imperial units.   
  • Sound speed in meters is set to: standard approximated value at 20°C 340m/s

LICENSE:

This program is release according to Creative Commons Share Alike License and Attribution by F.D'Errico.

CREDENTIALS: 

Author: Fiorenzo D'Errico 

GitHub: https://github.com/fderrico/HC_SR04.git

Interface

HC_SR04()

Description

Overloaded constructor setting up configuration parameters for library and measurement. They all are stored in the private variables. 

Syntax   

HC_SR04(int p_TrigPIN, int p_EchoPIN, int p_Upper_Limit_Range_cm); 

HC_SR04(int p_TrigPIN, int p_EchoPIN);

PARAMETERS:

  • p_TrigPIN    Arduino digital pin number where "Trigger" pin of HC-SR04 will be connected
  • p_EchoPIN      Arduino digital pin number where "Trigger" pin of HC-SR04 will be connected
  • p_Upper_Limit_Range_cm  maximal accepted measured distance in cm. (Default Value = 400 cm)

RETURN:

Instance object of the ultrasonic measurement module HC-SR04.

Example

HC_SR04 module1(9,10);  // module1 connected on digital pins 9 (Trigger PIN) and 10 (Echo PIN)
HC_SR04 module2(6, 7, 100); //the second module is connected on pins 7 and 9 and limited to 100 cm measuring range

Back to interface

getDistance_in_cm()

Description

The method measures distance from the sensor a reflecting obstacle based on measuring ultrasonic pulses sequence time sent to it and returned back.

Syntax   

long getDistance_in_cm();

Parameters

None

Return

Distance in centimeters

See also

HC_SR04()

getDistance_in_inch

Back to interface

getDistance_in_inch()

Description

The method measures distance from the sensor a reflecting obstacle based  on measuring ultrasonic pulses sequence time sent to it and returned back.

Syntax   

long getDistance_in_inch();

Parameters

None

Return

Distance in inches

See also

HC_SR04()

getDistance_in_cm

Back to interface

About

Arduino Library for HC-SR04 Ultrasonic Ranging Module

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages