The HC-SR04 must be run on 5V. Running it with 3,3V will show very weak results or nothing at all.
Beware: Do not connect 5V directly to the ESP!
It should be mentioned that this sensor has a small metering angle of +/- 30°.
Best results are reached with objects in a straight line in front of the sensor.
Due to laws of acoustics objects with a hard surface give better results
then soft, sound absorbing surfaces.
Connecting via Levelshifter
Connecting with a Voltage Divider
This is a bit of an overkill anyways. A level converter is a bidirectional device converting signals from
higher voltage to lower and vice versa. The "Trigger" input works quite well with 3.3V. The output goes
only from higer voltage (5V) to lower voltage (3.3V) so a voltage divider will do the job.
Beware: Do not connect the "Echo" output directly to the ESP!
Connecting using a Zener Diode
A second possible way is using a zener diode to cut voltages above 3.3V:
Settings for Distance
Set up the ESPEasy task according to the screenshot.
If you have chosen other GPIO pins set them accordingly.
Settings for Threshhold
Sometimes it might be necessary to switch something if a person or object
gets near below a certain distance or if a water level raised to a limit.
This can be done by programming a rule. But here is an easier way:
Change the "Value" into "State" and submit. An additional field "Threshold"
opens up. Enter the distance you want for switching, in the shown example it is 30 cm.
Now the sensor shows "0" as result if nothing is near. If something gets
near below 30 cm it shows "1".