C library for the HC-SR04 ultrasonic sensor designed for use with an Arduino Nano (ATmega328P).
This project reads distance measurements from the sensor and displays the results on a 20×4 LCD display. After each measurement, the processor enters sleep mode for 4 seconds to conserve power.
The HC-SR04 library provides a simple and modular interface to:
- Trigger the ultrasonic sensor
- Measure the echo pulse duration
- Convert the pulse to distance in centimeters
- Display the result on a connected 20×4 LCD
- Enter a low-power sleep mode between measurements
The project demonstrates sensor interfacing, power management, and LCD integration in embedded systems.
- Trigger and read distance from HC-SR04 ultrasonic sensor
- Display distance on a 20×4 LCD (HD44780-compatible)
- Automatic low-power sleep for 4 seconds after each measurement
- Modular code for easy reuse in other projects
- Tested with Arduino Nano / ATmega328P
- Microcontroller: ATmega328P (Arduino Nano)
- Development environment: Atmel Studio
- Sensor: HC-SR04 ultrasonic distance sensor
- Display: LCD 20×4 (HD44780-compatible)
- Connect the HC-SR04 sensor to the Arduino Nano (VCC, GND, Trigger, Echo pins).
- Connect the 20×4 LCD to the microcontroller using the LCD library.
- Initialize the sensor and LCD in your code.
- Call the library function to measure distance and display it.
- After each measurement, the microcontroller sleeps for 4 seconds to save power.
✔️ Stable — tested on Arduino Nano with 20×4 LCD.
This project is open-source and intended for educational and embedded development use.