hcsr04

package
v0.0.0-...-e7e8f10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2019 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package hcsr04 : Library for working with the Ultrasonic Ranging Module HC - SR04

From the datasheet: Ultrasonic ranging module HC - SR04 provides 2cm - 400cm non-contact measurement function, the ranging accuracy can reach to 3mm. The modules includes ultrasonic transmitters, receiver and control circuit. The basic principle of work:

(1) Using IO trigger for at least 10us high level signal,
(2) The Module automatically sends eight 40 kHz and detect whether there is a

pulse signal back.

(3) IF the signal back, through high level, time of high output IO duration is

the time from sending ultrasonic to returning. Test distance = (high level time×velocity of sound (340M/S) / 2,

You can calculate the range through the time interval between sending trigger signal and receiving echo signal. Formula: uS / 58 = centimeters or uS / 148 =inch; or: the range = high level time * velocity (340M/S) / 2; we suggest to use over 60ms measurement cycle, in order to prevent trigger signal to the echo signal.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HCSR04

type HCSR04 struct {
	EchoPin    rpio.Pin
	TriggerPin rpio.Pin
}

HCSR04 : Model to keep track the GPIO pins to use

func NewHCSR04

func NewHCSR04(echoPin int, triggerPin int) HCSR04

NewHCSR04 : Sets up a new HC-SR04 sensor

Uses the BCM number system

func (*HCSR04) Measure

func (sensor *HCSR04) Measure() float64

Measure : Takes a measurement then returns the distance in centimeter

Sensor has a resolution of 0.3cm. Returing the results of the calulation. Leaving the formatting of the number to the calling code.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL