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
This program is release according to Creative Commons Share Alike License and Attribution by F.D'Errico.
Author: Fiorenzo D'Errico
GitHub: https://github.com/fderrico/HC_SR04.git
Overloaded constructor setting up configuration parameters for library and measurement. They all are stored in the private variables.
HC_SR04(int p_TrigPIN, int p_EchoPIN, int p_Upper_Limit_Range_cm);
HC_SR04(int p_TrigPIN, int p_EchoPIN);
- 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)
Instance object of the ultrasonic measurement module HC-SR04.
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
The method measures distance from the sensor a reflecting obstacle based on measuring ultrasonic pulses sequence time sent to it and returned back.
long getDistance_in_cm();
None
Distance in centimeters
The method measures distance from the sensor a reflecting obstacle based on measuring ultrasonic pulses sequence time sent to it and returned back.
long getDistance_in_inch();
None
Distance in inches