View Source Hcsr04 (es_Hcsr04 v0.2.0)

A module to interface with the HC-SR04 ultrasonic distance sensor.

WARN: Linux based systems are not fast enough to keep up with the short frequency of modulation based GPIO interfaces like the HC-SR04.

If you need more accurate measurements, especially over time, you should favour an I2C based distance sensor.

wiring

Wiring

The HC-SR04 sensors has 4 pins. VCC and GND are a given.

ECHO is a input pin receiving the signal modulation when the measurement is completed. TRIG is a output pin triggering the measurement process.

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

Reads the distance in millimeters.

Starts the Hcsr04 process linked to the current process.

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Reads the distance in millimeters.

examples

Examples

iex> Hcsr04.read(pid)
154.2352463

Starts the Hcsr04 process linked to the current process.

options

Options

  • :trigger - GPIO pin number for trigger pin
  • :echo - GPIO pin number for echo pin