From Let's Control It
Jump to: navigation, search


The ESP can also be used to measure distance with the HC-SR04 Ultrasonic sensor.

The sensor has to be connected to two GPIO pins on the ESP module. The ESP uses an interrupt routine to retrieve the echo pulse from the HC-SR04.



The HC-SR04 can be found on eBay. Please note that the sensor uses 5 volts signals and they should not directly be connected to the ESP. Use a level shifter!


WARNING: The unit uses 5 volt signals that can not be used on the ESP module. You must use a levelshifter!!! And do not connect VCC between HC-SR04 and the ESP. Power the HC-SR04 with a separate 5 volt supply!

    HC-SR04            ESP
    VCC       <-->     -
    Trig      <-->     1st GPIO (via levelshifter!!!)
    Echo      <-->     2nd GPIO (via levelshifter!!!)

ESP Easy

Use the device tab on the ESP Easy webinterface and create a new task by editing one of the available tasks. Select "Ultrasonic Sensor HC-SR04 from the dropdown box.


Enter the IDX found in the Domoticz device page. Also select the two GPIO pins that you have used to connect the HC-SR04 sensor. That should be all.

Optional settings

Use of value names