Home Arduino Projects Arduino Projects: Ultrasonic Distance Sensor

Arduino Projects: Ultrasonic Distance Sensor

by Nikodem Bartnik

In one of our previous Arduino project, we used the sensor HC-SR04 to allow a robot to see obstacles while moving and to act accordingly. The HC-SR04 is a very popular ultrasonic sensor and you should definitely learn how to make use of it.

This project will be subdivided into two parts. We want to build a device that will sense the distance from a moving object, send that distance to the serial port and display the distance on an LCD screen. And it is important that the distance is in meter so we can easily apprehend and comprehend it.

To make the project simpler we will use an LCD with an I2C converter so we will need just 4 cables to connect it to Arduino. We will also need to add an additional library to the sketch, but worry not! it is easy to download.

Ultrasonic distance sensor

Here are the needed part:

Arduino Projects: Ultrasonic Distance Sensor

Let’s start with something simple. How do we display a distance on the serial port?

You first have to make the connections as shown on the schematic below. We do not need to add the LCD yet.

Arduino Projects: Ultrasonic Distance Sensor

This is how it should look like, very simple right? just 4 cables, the Arduino Uno board and the ultrasonic sensor.

Arduino Projects: Ultrasonic Distance Sensor

Code

And this is what you should see on the serial port

Arduino Projects: Ultrasonic Distance Sensor

Ok, half of the project is ready, let’s now add an LCD, here is how you should connect it.

Arduino Projects: Ultrasonic Distance Sensor

Then we have to download the library. You can download it from the Arduino IDE. Simply open Sketch >> Include Library >> Manage Libraries and then find LCD I2C.

Arduino Projects: Ultrasonic Distance Sensor

The code we have to upload is somewhat similar to the first one at the difference that this time instead of displaying on the serial, we display the values on the LCD.

Arduino Projects: Ultrasonic Distance Sensor

And There you have it!

Very fun, simple and useful project. I hope you have become a better maker after reading this tutorial. Do not hesitate to show me what you have been able to build in the comment section below.

You might also like:

Related Posts

Leave a Comment

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

Privacy & Cookies Policy