public class UltrasonicHCSR04 extends GPIOComponent
The basic principle of work:
distance = (high level time X velocity of sound (340M/S) / 2
Datasheet: HCSR04
Note: for accuracy reasons, we need to directly use WiringPi functions instead of pi4j to control the pins, probably because pi4j is too slow to react (higher level).
Examples of use: UltrasonicHCSR04Example
and UltrasonicSensorsComparison
gpio
Constructor and Description |
---|
UltrasonicHCSR04(GPIOPin trigPin)
Constructor for a variant of ultrasonic sensor HCSR04 using a signle Gpio pin for trigger and echo signals.
|
UltrasonicHCSR04(GPIOPin trigPin,
GPIOPin echoPin)
Constructor for an ultrasonic sensor HCSR04 using a specific Gpio trigger pin
and a specific Gpio echo pin.
|
Modifier and Type | Method and Description |
---|---|
double |
getDistance()
Get the calculated distance from the ultrasound sensor.
|
getType
public UltrasonicHCSR04(GPIOPin trigPin, GPIOPin echoPin)
trigPin
- the pin to use to trigger signals.echoPin
- the pin to use to detect echo signals.public UltrasonicHCSR04(GPIOPin trigPin)
trigPin
- the Gpio pin used for trigger and echo signals.