Distance - HC-SR04/RCW-0001/etc.

.

Plugin details

Type: Distance

Name: HC-SR04/RCW-0001

Status: NORMAL CLIMATE

GitHub: P013_HCSR04.ino

Maintainer: .

Used libraries: NewPing

Supported hardware

HC-SR04

../_images/P013_HC-SR04_1.jpg

RCW-0001

../_images/P013_RCW-0001_1.jpg

US-100

../_images/P013_US-100_1.jpg

Introduction

The HC-SR04/RCW-0001/US-100 is an ultrasonic distance sensor. It’s able to indicate distances between 2 cm up to about 300 cm at a resolution of about 0.3 cm.

Specifications:
  • Ultrasonic distance sensor

  • Measure angle: 30°

  • Ranging distance: 2cm - 300cm (some have reporting it work good up to 400 cm)

Wiring

The HC-SR04/RCW-0001/US-100 must be run on 5V. Running it with 3.3V will show very weak results or nothing at all.

ESP               HC-SR04/RCW-0001/US-100
GPIO (X)   <-->   Trigger
GPIO (X)   <-->   Echo (voltage divider!)

Power
5.0V       <-->   VCC
GND        <-->   GND

Warning

Do not connect 5V directly to the ESP! Read more about Level converter.

Setup

../_images/P013_Setup_HC-SR04_1.png

Task settings

  • Device: Name of plugin

  • Name: Name of the task (example name HCSR04), should not be empty.

  • Enable: Should the task be enabled or not

Sensor

  • GPIO –> Trigger: Set the GPIO to trigger the signal.

  • GPIO –> Echo, 5V: Set the GPIO to receive the echo signal, a voltage divider is needed.

../_images/P013_ModeOptions.png
  • Mode: Value is the most used setting, it will output the distance in centimeters. If you want the plugin to report a 1 or a 0 you use the State setting. State or Combined will open up a new field called “Threshold” which will allow you to enter a value. If the unit detects a value below the given threshold the task will be set to 1, if the detected value is above the given threshold the task will be 0. You should set the Interval to zero in case of using the state setting, just to make sure the action is triggered as soon as possible.

    A third option is to combine both the Value and State modes, to have both the distance and state values available. This mode is called Combined.

  • Threshold: Set the distance that will trigger the event for the State or Combined mode.

  • Max distance: Set the max value the task will show. If the actual value is above the max distance the max distance will be displayed. Set to 0 will disable the max distance setting. Max according to the specifications is 300 cm.

  • Unit: You can show the output value as imperial without the need to do it using the formula function.

  • Filter: The signal might be a bit shaky for some applications, try to use the Median filtering setting in that case.

  • Trigger width: For hardware that doesn’t exactly follow the timing guidelines, it may be needed to extend the pulse delay somewhat to receive a usable echo. The default is 10 microsoconds, and can be increased in small steps to max. 20 microseconds.

Data Acquisition

This group of settings are standard available configuration items.

  • Single event with all values: When this setting is enabled, all available values will be sent in a single event <TaskName>#All, with all values in order as arguments to the event.

  • Show derived values: When checked, the Devices overview page, and the /json endpoint (used for updating the Devices overview page) will include any Derived values as defined. See the TaskValueSetDerived and TaskValueSetPresentation commands.

  • Event & Log derived values: When checked, the Derived values will be generated as Events, to be handled in Rules, and sent to logging devices like the Syslog server and/or SD-card logging.

  • Send derived values: When checked, the Derived values will be sent to any enabled Controllers that support extra values like MQTT and HTTP/string value controllers.

(The derived values options are only available if String variables feature is included in the build.)


  • Send to Controller: Select the Controller(s) to send the Values to, either on a TaskRun command applied to the task, or on an Interval time action.

Send to Controller is only visible when one or more Controllers are configured.


  • Interval: How often should the task publish its value (1..5 seconds is normal for the Value or Combined settings, 0 for the State setting).

Rules examples

on HCSR04#distance do
  if %eventvalue1%<50 and %eventvalue1%>45
    GPIO,14,1 //light up LED to show that you're at the correct position
  else
    GPIO,14,0
  endif
endon

Where to buy

Store

Link

AliExpress

Link 1 ($)

Banggood

Link 2 ($)

eBay

Link 3 ($)

$ = affiliate links which will give us some money to keep this project running, thank you for using those.

Change log

Changed in version 2.0:

added Major overhaul for 2.0 release.

Added in version 1.0:

added Initial release version.