Skip to main content

Hc Sr04 – How it works

The Qwiic compatibility is made possible with the Atmel ATTINY404-F. When using Qwiic, you are essentially communicating with an onboard ATTINY404-F MCU via I2C communication, and the MCU controls the Trig and Echo pins of the sensor.

ATiny404-F on board
ATTINY404-F on board

User Guide

For an in-depth look at the technical specifications of the ultrasonic sensor itself, refer to the official HC-SR04 User Guide:

HC-SR04 User Guide

User guide for the HC-SR04 ultrasound sensor


How the sensor works

The HC-SR04 is an affordable and easy-to-use distance-measuring sensor that has a range from 2cm to 400cm.

The sensor is composed of two ultrasonic transducers. One is a transmitter that outputs ultrasonic sound pulses, and the other is a receiver that listens for reflected waves.

Sensor receiver and transmitter
Sensor receiver and transmitter

Piezoelectric crystals are used as sensor elements. They oscillate at high frequencies when electrical energy is applied to them. Piezoelectric crystals generate an electrical signal when an ultrasound wave hits the sensor surface in reverse.

Construction of the sensor itself
Construction of the sensor itself

The trigger pin is used to initiate the ultrasonic sound pulses, and the echo pin produces a pulse when the reflected signal is received. The length of the pulse is proportional to the time it takes for the transmitted signal to be detected.

How the echo and trigger pins work
How the echo and trigger pins work

Qwiic I2C communication

This product uses the onboard ATTINY404-F MCU to implement I2C communication. The breakout board operates with a default I2C address of 0x30 but can be changed with onboard switches. To change the breakout board's address, check out the Address selection. When detected, the ATTINY404-F receives data from the sensor and passes it to the main MCU using the I2C data line.