Wemos D1 Mini and HC SR04 Ultrasonic Sensor - FengtianGu/Sonoff-Tasmota GitHub Wiki

HC-SR04 Ultrasonic Sensor

"This is the HC-SR04 ultrasonic ranging sensor. This economical 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:

Connecting the HC-SR04 to a Wemos Mini D1

Wemos HC-SR04
GND GND
5V VCC
D6 (gpio12) Echo via voltage divider
D7 (gpio13) Trigger

The HC-SR04 operates best at 5V, 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 operation voltage of the Wemos D1 Mini. Please note 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.

Tasmota Configuration

In the Configuration -> Configure Module page, select the following:

  1. Module Type : 18 Generic
  2. D6 GPIO12 : 70 SR04 Ech
  3. D7 GPIO13 : 69 SR04 Tri

Tasmota Main

After reboot of the device the displays the HC-SR04 distance.