- 01Echo duration
- 02Millimetres
- 03State policy
- 04LED display
Build a tabletop display
Move a flat object in front of an ultrasonic sensor. Red means close, yellow means caution and green means clear within this lab's configured range. A missing or out-of-range echo produces unknown with all three LEDs off and a serial explanation.
This is a desk experiment. Its readings and timing do not establish a vehicle-parking aid, collision-avoidance system or reliable control system.
The sensor returns an echo duration in microseconds. Sound travels out and back; using a nominal 343 m/s gives echo_us * 343 / 2000 millimetres. Temperature, surfaces, angle and timing affect a physical reading, so measure against a ruler later.
Begin with the C++ policy
Download and unzip the project. On a computer with a C++ compiler run:
c++ -std=c++17 -Wall -Wextra -Werror test_beacon.cpp -o test_beacon
./test_beaconThe executable checks distance bands, invalid input, echo conversion and scheduling arithmetic. It does not flash a board or measure a real echo.
Try it
Define outputs for 0, 79, 100, 250 and 4001 mm before reading the implementation. Then ask what should happen around a boundary if successive measurements differ by a few millimetres.