Bonezegei HCSR04: Arduino Library for Ultrasonic Distance Sensor
Batutay, Jofel ยท 2023/10/27

Introduction

Bonezegei_HCSR04 is a simple and easy-to-use Arduino library for interfacing HCSR04 ultrasonic sensor module. The library provides functions for measuring distance, setting trigger and echo pins. The library also supports multiple sensors connected to the same Arduino board. This paper shows the basic usage of the library.

Disclaimer

The code and libraries provided by Bonezegei is intended for informational and educational purposes only. Bonezegei does not own or manufacture the hardware associated with the code. The code is provided "as is" without any warranty, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and non-infringement. In no event shall Bonezegei be liable for any claim, damages, or other liability arising from the use of the code or the hardware. Users are solely responsible for ensuring that their use of the code complies with all applicable laws and regulations.


1. Get Distance

Get distance, the distance is in centimeter (CM)

/*
  This Sample is written for HCSR04 ultrasonic Module
  Author: Bonezegei (Jofel Batutay)
  Date: July 2023 
  Get ditance in CM
*/

#include <Bonezegei_HCSR04.h>

const int TRIGGER_PIN = 26;
const int ECHO_PIN = 27;

Bonezegei_HCSR04 ultrasonic(TRIGGER_PIN, ECHO_PIN);

void setup() {
  Serial.begin(115200);
}

void loop() {
  int d=ultrasonic.getDistance();
  Serial.print("Distance:");
  Serial.print(d);
  Serial.println(" cm");
  delay(100);
}

References

  • Batutay, Jofel. (2023). Bonezegei HCSR04: Arduino Library for Ultrasonic Distance Sensor. ResearchGate. http://doi.org/10.13140/RG.2.2.15259.64806.

Cite this

  • Batutay, Jofel. (2023). Bonezegei HCSR04: Arduino Library for Ultrasonic Distance Sensor. ResearchGate. http://doi.org/10.13140/RG.2.2.15259.64806.