Source: https://mokxi.com/teachers/ultrasonic-distance-lab
Updated: 2026-11-09

Ready-to-teach lab

# Ultrasonic sensor lab: distance with an HC-SR04

In this ultrasonic sensor lab an HC-SR04 on an Arduino Uno prints the distance to an object once a second, and students work out how a time measured in microseconds becomes a length.

Ages 13 and up, physics of sound or robotics. About 45 minutes. Students read and change an Arduino sketch.

Open this lab Assign to my class

The lesson

## Objective and parts

### By the end, students can

- Explain how an echo measures distance.
- Use the speed of sound to turn a time into a distance, and say why the path counts twice.
- Read sensor values on the serial monitor and act on them in code.

### Parts, already on the bench

- An Arduino Uno
- One HC-SR04 ultrasonic sensor: TRIG on pin 12, ECHO on pin 11
- Four jumper wires: 5 V, ground, TRIG and ECHO

Nothing to hand out or collect: the circuit opens built and wired.

Steps

## What students do

Each step is short enough to read out. Students work in the simulator beside this page.

Open this lab

- Open the lab, press Run and open the serial monitor. A distance in centimeters prints once a second.
- Click the sensor and drag its distance slider. Check that the printed number follows it.
- Set 10 cm, 50 cm and 100 cm, and for each one calculate how long the sound takes to go out and come back.
- Move the object out of range and note what the sketch prints.
- Add an LED on a free pin that lights when something is closer than 20 cm.

Questions

## Questions for students

Hand these out as they are. The expected answers are under the list, for you.

- Sound travels at about 343 m/s. How long does the echo take for an object 1 cm away?
- Why is the echo time divided by two?
- An object is 1 m away. What echo time does the sensor measure?
- On a real sensor, a soft or slanted surface often reads wrong. Why?

Answer key for the teacher

- About 58 microseconds. The sound covers 2 cm, out and back, at 0.0343 cm per microsecond.
- The time covers the trip to the object and the trip back. The distance to the object is half of the path.
- About 5.8 milliseconds: 2 m at 343 m/s.
- A soft surface absorbs the sound and a slanted one reflects it away from the sensor, so little or no echo comes back.

Go further

## For students who finish early

- Add a buzzer that beeps faster as the object comes closer, like a parking sensor.
- Print the distance in inches as well.

Your class

## Give this lab to every student

Assign to my class puts this circuit on each student’s class page as a starter. They change their own copy and hand it in, and the work comes back to you in one list.

The class tools are free for 30 days for one class of up to 20 students, with no card. Opening and running the lab needs no account and stays free.

Assign to my class Start a free class

More labs

## The other labs in the set

Ohm's law Circuits. 40 min. Series and parallel Circuits. 45 min. Voltage divider Circuits. 40 min. LED and resistor Circuits. 30 min. RC circuit Electronics. 50 min. Transistor switch Electronics. 45 min. Logic gates Electronics. 40 min. Arduino blink Arduino. 35 min. Button and LED Arduino. 40 min. Traffic light Arduino. 45 min. Servo sweep Arduino. 40 min. All labs The whole set on one page.
