T ThinkEdge Learn

Arduino ultrasonic distance sensor projects

The HC-SR04 measures distance with sound — here it parks a car, counts objects, sounds a pitch and sweeps a radar.

10 projects Easy first Arduino uno, Arduino nano

The HC-SR04 sends a pulse of sound and listens for the echo, and the time between the two is the distance. It is the clearest example on the site of a sensor that measures something real in the world, and the number on screen is the number the physics gives you — which means a wrong wiring and a wrong reading look the same, and that is worth a whole lesson.

The parking sensor is the classic first build because the feedback is immediate and funny: the beep gets faster as you approach. The object counter and the radar scanner take the same sensor somewhere new. The pet feeder combines it with a servo, which is the moment a class realises a measurement can cause an action.

What you need

The parts below are the ones the most of these projects share. Each project page lists the full set for that build.

PartUsed byWhy
Breadboard5Holds the circuit together without solder
1× breadboard5Holds the circuit together without solder
1× HC-SR04 ultrasonic sensor5Reads something about the world
1× buzzer4The output you can hear working
1× Arduino Uno R34The board that runs the sketch
1× HC-SR043The part this project needs

All 10 arduino ultrasonic distance sensor projects

Easiest first. Each card links to the project's own page with the wiring, the parts and the code written out.

Smart Recycling Bin

Ultrasonic sensor detects when the bin is full

Tier 2 · Logic & Sensors · Easy · 30 min
Ultrasonic — Distance Sensor

Measure how far away an object is

Tier 2 · Logic & Sensors · Intermediate · 35 min
Arduino Nano — Parking Sensor

4 distance zones — 1 slow low beep far, 2 fast high-pitch beeps close (like a real car reversing buzzer)

Tier 2 · Sensor Projects · Intermediate · 30 min
Ultrasonic — Reverse Parking Sensor

Beep faster as you get closer

Tier 3 · Combined Projects · Intermediate · 40 min
Ultrasonic — Pitch by Distance

Closer = higher pitch

Tier 3 · Combined Projects · Intermediate · 30 min
Ultrasonic — Object Counter

Count things as they pass — like a door sensor or factory line

Tier 3 · Combined Projects · Intermediate · 30 min
Arduino — Ultrasonic Distance on Serial

Read distance with HC-SR04 and print the cm on Serial Monitor

Tier 3 · Combined Projects · Advanced · 35 min
Arduino — Ultrasonic Radar Scanner

A servo sweeps the ultrasonic sensor to scan the room

Tier 3 · Combined Projects · Advanced · 45 min
Smart Fan — Temperature + Distance

Only blows when it is hot AND someone is within 100 cm

Tier 4 · Capstone · Advanced · 60 min
Pet Feeder — Distance-Triggered Servo

When the pet is near, drop food

Tier 4 · Capstone · Advanced · 60 min

How to use these with a class

These 10 projects run from about 30 minutes to 60 minutes each, and 0 of them are Tier 1 — one component and one idea, which is what a class can finish in a single period.

Each project page carries the full build — the concept, the parts, the wiring one step at a time and the sketch — so a class can work through it without the teacher having to explain every wire.

Every one of them can be practised in the browser simulator first, with the real sketch and a real circuit solver behind it, and the first 15 projects are free with no account.

Common questions

Why does the reading say 0 cm when nothing is in front of the sensor?

The HC-SR04 cannot hear its own echo. Point it at a soft surface — a hand or a piece of cardboard — from more than about 20 cm away, and the reading appears. The ultrasonic project pages all show the measurement live in the simulator.

How accurate is it?

About a centimetre or two on a clean, flat surface at a metre. Angles, soft materials and a moving target all make it worse, which is why the projects use it for thresholds — "closer than 30 cm" — rather than for a precise distance.

Can one sensor do two things at once?

The speed of sound is the limit: the sensor cannot hear a new echo until the first one has come back, so a full round trip needs roughly 23 ms. That is why the radar scanner sweeps with a servo instead of trying to read continuously.

Related

All the projectsThe complete catalogue The guidesHow the ideas behind these work Arduino projects for beginnersThe board-specific builds Arduino simulator in the browserTry any of these without hardware

Try the full simulator with your class

103 guided circuit projects, 21 lessons and an in-browser Arduino simulator. The first 15 projects are free, no account needed. One licence covers a whole school.