Ultrasonic distance meter on ATtiny1616 (2.4 mm RMSE)
Ultrasonic distance meter on an ATtiny1616, measuring 10–50 cm with ~2.4 mm RMSE. A hybrid method: coarse time-of-flight from the 40 kHz echo envelope, refined by carrier phase (Goertzel filter), with NTC temperature compensation. Firmware in pure register-level AVR-GCC (no Arduino), ~0.9 mW sleep power. Bill of materials: €10.
- Błąd RMSE
- 2,4 mm
- Zakres
- 10–50 cm
- Pobór mocy
- 0,9 mW
Overview
The goal was a cheap, accurate ultrasonic rangefinder on a single 8-bit MCU — millimetre accuracy and power low enough for battery operation. Built for the "Wygraj Indeks WETI 2026" engineering contest.
Method
I used a Pulse-Phase Ranging hybrid: coarse time-of-flight (ToF) from the echo envelope, refined by the 40 kHz carrier phase computed with a Goertzel filter.
How the measurement works
- The MCU emits a 40 kHz burst (exact transducer resonance), driven by a BC817.
- The echo is amplified by a two-stage MCP6002 front-end (band-pass ~40 kHz), gated by a P-MOSFET to save power.
- The ADC samples the echo envelope; the echo onset (40 % of peak, interpolated) gives the flight time, measured by the TCB0 counter (100 ns/tick).
- A Goertzel filter extracts the carrier phase, snapping the result to the λ/2 ≈ 4.3 mm grid.
- An NTC thermistor corrects the speed of sound: c(T) = 331.3 + 0.606·T.
Goertzel filter (phase)
Power
Between measurements the MCU sleeps in Standby, woken by the RTC/PIT; the analog front-end is powered only during a measurement. Idle draw: 0.9 mW.
Outcome
Results
- 2,4 mm
- Błąd RMSE
- 10–50 cm
- Zakres
- 0,9 mW
- Pobór mocy
- 43,73 zł
- Koszt BOM