HC SR04 - stodev-com-br/tasmota GitHub Wiki

HC-SR04 (HC-SR04P and JSN-SR04T) is an ultrasonic ranging sensor. Provides 2cm to 400cm of non-contact measurement functionality with a ranging accuracy that can reach up to 3mm. Each HC-SR04 module includes an ultrasonic transmitter, a receiver and a control circuit. See HC-SR04 Ultrasonic Sensor for more information.

Buy example:

Configuration

Wiring

HC-SR04 ESP8266
Vcc 5V
GND GND
Trig GPIOx
Echo
use voltage divider!
GPIOy

The HC-SR04 operates at 5V and therefore the echo signal will be 5V as well. Connecting the echo pin via a voltage divider (see schematic) will divide the 5V to 3.3V, which is the operating voltage of an ESP8266.

There is a variant of the HC-SR04, called HC-SR04P. It mainly operates at 3.3V and then it doesn't need the voltage divider but you will notice a range drop of about 1 meter. image

Tasmota

In the Configuration -> Configure Module page assign:

  1. GPIOx to SR04 Tri (69)
  2. GPIOy to SR04 Ech (70)

image

Tasmota Main

After a reboot webUI displays the HC-SR04 distance.

image

Sensor sends a tele/%topic%/SENSOR JSON reponse:

{"Time":"2019-01-01T22:42:35","SR04":{"Distance":16.754}}
⚠️ **GitHub.com Fallback** ⚠️