Ultrasonic — Object Counter
Count things as they pass — like a door sensor or factory line
Ultrasonic
Counter
State
Industrial
What you will learn
- What edge detection is (only react when a value CROSSES a threshold, not when it stays above it)
- Why state variables are essential for any "memory" in a program (counters, modes, alarms)
- How to drive a 5-LED bar-graph display from a single count variable
- How ultrasonic sensors are used in industry for counting, not just distance
What you will need
| Component |
|---|
| 1× Arduino Uno R3 |
| 1× HC-SR04 ultrasonic |
| 7× 220Ω resistor |
| 1× green LED |
| 1× red LED |
| 5× yellow LEDs (count display) |
| 1× breadboard |
| 25× jumper wires |
Step by step
Take it further
- Add a third LED that lights when the count crosses 10, 20, 50 (a "milestone" indicator).
- Use the red LED to count up in binary (blink a pattern) every 5 objects.
- Print the count to Serial Monitor ONLY when it changes, not every loop (already done — but also add a "Total: X" message once per second regardless).
Practise it before you build it
Wire this circuit in the ThinkEdge Learn simulator first. The simulator runs a real Arduino sketch against a modified-nodal-analysis solver, so the LED on screen actually lights when the current is right — no hardware, no burnt components, and a class can try it in a browser.
Related projects
Ultrasonic — Reverse Parking SensorBeep faster as you get closer
Ultrasonic — Pitch by DistanceCloser = higher pitch
Arduino — Ultrasonic Distance on SerialRead distance with HC-SR04 and print the cm on Serial Monitor
Arduino — Ultrasonic Radar ScannerA servo sweeps the ultrasonic sensor to scan the room
Police SirenAlternating red + blue LEDs with a wailing 600–1500 Hz buzzer
LDR — Light-Following Robot (Solar Tracker)It always faces the brightest spot
Guides that use this project
2 guides on the site build this project as part of a longer explanation. The guide says why the circuit works; this page says how to wire it.
How to Build a RobotHow to build a robot from scratch: one motor and a switch, then sensors, then a line-follower that steers itself. Every stage runs in a browser simulator first.
Robotic Lawn Mowers: Boundary, Blades and BalanceHow robotic lawn mowers find the edge of the grass, why the blade motor causes brownouts, and what a $30 ultrasonic sensor can and cannot do.
Where this project sits
It is also part of these lists, which is how a class usually finds it.
Arduino LED projects for beginners36 projects in this list
Arduino ultrasonic distance sensor projects10 projects in this list
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.