Skip to content
Circuits Playground
Menu
BeginnerRule-checked

Arduino Ultrasonic Distance Meter with LCD

Measure distance with an HC-SR04, show it on a 16×2 I2C LCD and beep when something gets too close.

Board
Arduino Uno R3
Build time
40 min
Status
Rule-checked
Last revised

Passed the automatic wiring rules. Not yet physically built and tested.

Quick answer

To build the Arduino Ultrasonic Distance Meter with LCD you need a Arduino Uno R3 and HC-SR04 Ultrasonic Distance Sensor, 16×2 LCD with I2C Backpack (PCF8574), Active Buzzer Module, 11× Jumper wires + breadboard. It is a beginner project with 11 connections, takes about 40 min and costs roughly ₹720–₹1,080 in parts.

Everything in this project runs at 5 V, which makes the Arduino Uno a comfortable first board for the HC-SR04: no voltage divider is needed on the ECHO line.

The LCD uses the Uno's only I2C pins, A4 (SDA) and A5 (SCL).

Arduino Uno R3IOREFRESET3.3V5VGNDGNDVINA0A1A2A3A4A5AREFGNDD13D12D11D10D9D8D7D6D5D4D3D2D1D0HC-SR04VCCTrigEchoGND16×2 LCDGNDVCCSDASCLBuzzerVCCI/OGND
Circuit diagram for Arduino Ultrasonic Distance Meter with LCD (revision 2026-11-12). Wire colours: red = power, grey = ground, blue = signal, purple = I2C, green = analog, orange = switched load.

Download

Parts list

QtyPartNotesBuy
1Arduino Uno R3ATmega328P board with 5 V logic, 14 digital and 6 analog pins.Amazon.inRobu.in
1HC-SR04 Ultrasonic Distance SensorUltrasonic ranging module, about 2 cm to 400 cm, 5 V supply.Amazon.inRobu.in
116×2 LCD with I2C Backpack (PCF8574)Character LCD with PCF8574 I2C backpack and backlight; 5 V module.Amazon.inRobu.in
1Active Buzzer ModuleBuzzer module with built-in oscillator and transistor driver; sounds when the input is driven.Amazon.inRobu.in
11Jumper wires + breadboardMale/female jumpers as required by the modules' headers.Amazon.inRobu.in

Estimated cost: ₹720–₹1,080 including a breadboard and jumper wires (typical Indian online prices, 2026-11). Some links may be affiliate links, they cost you nothing extra and help keep this site free.

Pin-to-pin wiring

FromPinToPinType
16×2 LCDGNDArduino Uno R3GNDground
16×2 LCDVCCArduino Uno R35Vpower
16×2 LCDSDAArduino Uno R3A4i2c
16×2 LCDSCLArduino Uno R3A5i2c
BuzzerVCCArduino Uno R35Vpower
BuzzerI/OArduino Uno R3D8signal
BuzzerGNDArduino Uno R3GNDground
HC-SR04VCCArduino Uno R35Vpower
HC-SR04TrigArduino Uno R3D9signal
HC-SR04EchoArduino Uno R3D10signal
HC-SR04GNDArduino Uno R3GNDground

Step-by-step build

  1. 1

    Make a 5 V and GND rail

    Run the Uno's 5V and GND to the breadboard power rails; all three modules connect to them.

  2. 2

    Wire the HC-SR04

    VCC → 5V, Trig → D9, Echo → D10, GND → GND.

  3. 3

    Wire the LCD

    GND → GND, VCC → 5V, SDA → A4, SCL → A5.

  4. 4

    Wire the buzzer

    VCC → 5V, I/O → D8, GND → GND.

  5. 5

    Adjust contrast

    Power up and turn the blue potentiometer on the LCD backpack until the characters are visible.

AI code-generation prompt

Paste this into Gemini, ChatGPT, Claude or another coding assistant. It includes the exact pin map. Treat the generated code as untested until you have run it.

You are an experienced embedded firmware engineer. Write complete, compilable firmware for the project below.

## Project
Title: Arduino Ultrasonic Distance Meter
Description: HC-SR04 distance on a 16x2 I2C LCD with proximity beeper.
Board: Arduino Uno R3, 5 V logic
Development environment: Arduino IDE
Connectivity: none (runs offline)

## Required behaviour
Measure distance 10 times per second, median-filter the last 5 readings and show the distance in cm on line 1 of the LCD. On line 2 show a bar proportional to distance. When the distance is under 20 cm, beep with a rate that increases as the object gets closer. Show 'Out of range' when no echo is received within 30 ms.

## Components
- 1 × Arduino Uno R3
- 1 × HC-SR04 Ultrasonic Distance Sensor
- 1 × 16×2 LCD with I2C Backpack (PCF8574)
- 1 × Active Buzzer Module

## Exact pin map (do not change these pins)
- HC-SR04 VCC → 5V
- HC-SR04 Trig → D9
- HC-SR04 Echo → D10
- HC-SR04 GND → GND
- 16×2 LCD GND → GND
- 16×2 LCD VCC → 5V
- 16×2 LCD SDA → A4
- 16×2 LCD SCL → A5
- Buzzer VCC → 5V
- Buzzer I/O → D8
- Buzzer GND → GND

## Libraries I expect you to use
- LiquidCrystal_I2C (or hd44780)

## Assumptions
- The LCD backpack is at 0x27 (some are 0x3F).
- The buzzer module sounds when I/O is HIGH.

## Requirements for the code
- Use only the pins listed above, defined once as named constants at the top.
- Non-blocking structure using millis() (no long delay() calls in loop()).
- Put all outputs (relays, motors, buzzers) in a safe OFF state in setup() before anything else.
- Print readable debug output to Serial at 115200 baud.
- Handle sensor read failures (e.g. NaN, timeouts, missing I2C device) without crashing, and report them.
- Put thresholds and calibration values in clearly named constants with comments.

## What to return
1. The complete source file(s), ready to compile in Arduino IDE.
2. The exact libraries (with the library manager names) and board package to install.
3. A short explanation of how the code works and how to calibrate it.
4. A testing checklist I can follow step by step.

Do not invent pins, libraries or functions that do not exist. If something in this spec is ambiguous or unsafe, say so before writing code.

Troubleshooting & common mistakes

LCD shows only blocks or nothing
Adjust the contrast pot, then run an I2C scanner to confirm the address (0x27 or 0x3F).
Distance always 0
Check Trig/Echo are not swapped and use a timeout in pulseIn().
Readings jump around
Soft or angled surfaces reflect poorly; use a median filter and point the sensor at a flat target.

Safety, assumptions & checks

Safety notes

  • Low-voltage USB project; no special hazards.
  • Absolute maximum 40 mA per I/O pin; design for 20 mA or less.

Assumptions

  • The LCD backpack is at 0x27 (some are 0x3F).
  • The buzzer module sounds when I/O is HIGH.

Automatic wiring check (rules-2026.11.1)

✔ No problems found by the wiring rules.

The checker finds known wiring mistakes. It is not a simulator and cannot guarantee the circuit is safe or will work.

Viva and interview questions

Questions examiners commonly ask about the parts in this circuit, with short answers.

  1. Q1. Which microcontroller is on the Arduino Uno R3?

    The ATmega328P, an 8-bit AVR running at 16 MHz with 32 KB flash and 2 KB SRAM.

  2. Q2. Which pins are I2C on the Uno?

    A4 is SDA and A5 is SCL (also duplicated near AREF on R3 boards).

  3. Q3. How many PWM pins does the Uno have?

    Six: D3, D5, D6, D9, D10 and D11 (marked with ~).

  4. Q4. How does the HC-SR04 measure distance?

    It sends a 40 kHz ultrasonic burst and times the echo. Distance = (echo time × speed of sound) / 2.

  5. Q5. Why is the HC-SR04 Echo pin a problem for 3.3 V boards?

    The Echo pin outputs 5 V. A 3.3 V board needs a voltage divider on Echo to avoid damage.

  6. Q6. What does the I2C backpack on a 16×2 LCD do?

    A PCF8574 I/O expander converts two I2C wires into the LCD's parallel interface, saving pins.

  7. Q7. What is the difference between an active and a passive buzzer?

    An active buzzer has a built-in oscillator and beeps with DC. A passive buzzer needs a PWM tone signal.

Frequently asked questions

What components do I need for the Arduino Ultrasonic Distance Meter with LCD?

You need a Arduino Uno R3 and HC-SR04 Ultrasonic Distance Sensor, 16×2 LCD with I2C Backpack (PCF8574), Active Buzzer Module, 11× Jumper wires + breadboard, plus a breadboard, jumper wires and a USB cable.

How much does the Arduino Ultrasonic Distance Meter with LCD cost to build in India?

About ₹720–₹1,080 for new parts from Indian online stores (estimate, 2026-11). Reusing a board you already own makes it much cheaper.

How long does it take to build?

About 40 min for a beginner maker, including wiring and uploading code.

Is this project suitable as a college or school project?

Yes. It is a beginner project that suits school science exhibitions, diploma practicals and first-year engineering mini projects. Extend it with a web dashboard or data logging for a bigger project.

What should I do if: LCD shows only blocks or nothing?

Adjust the contrast pot, then run an I2C scanner to confirm the address (0x27 or 0x3F).

What should I do if: Distance always 0?

Check Trig/Echo are not swapped and use a timeout in pulseIn().

What should I do if: Readings jump around?

Soft or angled surfaces reflect poorly; use a median filter and point the sensor at a flat target.

Report a mistake in this project

Related