Skip to content

How to use HC-SR04 ultrasonic module with Arduino to measure distance in cm and inch

 

 


Hello there, here we are using the HC-SR04 ultrasonic module to measure distance, it’s a classic Arduino project to get you started, this module can measure up to 5m (16ft) it’s quiet accurate and easy to calibrate as we saw in the video, you can integrate it in your projects, especially robots to detect obstacles or measure distance too while moving… (we don’t talk too much here) so here’s the wiring I used it’s only one wiring: 

  1. Arduino Uno board
  2. HC-SR04 ultrasonic sensor
  3. LCD i2c screen (tutorial =  Arduino LCD I2C simple use and direct write from serial monitor)
  4. Some jump wires and a breadboard

Below we gonna check how to measure using Serial monitor or LCD in both metric and imperial units.

HC SR04

The module’s look make it interesting for robots projects, it has four pins VCC/GND for power (5VDC) and Trigg/Echo are for Sending/Receiving signal.

N.B:

Before you use it in any project, make sure to do some test first on the surface you want to detect if it reflects the ultrasound back or not, also the shape of the surface can affect the correct measurements.


Wiring:

HC SR04 wiring with LCD i²c

 

The LCD i²c is optional in case you want to use it, otherwise remove it and slightly modify the code.

Library:

Download LCD i2c library  here

Codes:

Download all codes .ino format here or check the following:

Code 1: Direct test and distance measuring in cm, with display on the Serial Monitor

 

Code 2: Display the measured values in cm on the LCD i²c screen

 


Code 3: Display the measured values in inches on the LCD i²c screen

 

Yassine View All

Automation and Electrical Engineer, Electronics amateur trying to share my little projects.

3 thoughts on “How to use HC-SR04 ultrasonic module with Arduino to measure distance in cm and inch Leave a comment

Leave a Reply

Discover more from SURTR TECHNOLOGY

Subscribe now to keep reading and get access to the full archive.

Continue reading