https://github.com/raspberrypi-go-drivers/hcsr04
Driver allowing to usea HC-SR04 ultrasound distance sensor
https://github.com/raspberrypi-go-drivers/hcsr04
driver go golang hc-sr04 raspberry-pi raspberrypi-drivers robotics
Last synced: about 2 months ago
JSON representation
Driver allowing to usea HC-SR04 ultrasound distance sensor
- Host: GitHub
- URL: https://github.com/raspberrypi-go-drivers/hcsr04
- Owner: raspberrypi-go-drivers
- License: mit
- Created: 2020-12-18T21:53:00.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-12-18T22:11:18.000Z (over 5 years ago)
- Last Synced: 2025-05-18T14:48:43.713Z (about 1 year ago)
- Topics: driver, go, golang, hc-sr04, raspberry-pi, raspberrypi-drivers, robotics
- Language: Go
- Homepage:
- Size: 4.88 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# HC-SR04
[](https://pkg.go.dev/github.com/raspberrypi-go-drivers/hcsr04)

[](https://goreportcard.com/report/github.com/raspberrypi-go-drivers/hcsr04)
[](https://opensource.org/licenses/MIT)
hcsr04 is a driver allowing to usea HC-SR04 ultrasound distance sensor
## Documentation
For full documentation, please visit [](https://pkg.go.dev/github.com/raspberrypi-go-drivers/hcsr04)
## Quick start
```go
package main
import (
"fmt"
"os"
"time"
"github.com/raspberrypi-go-drivers/hcsr04"
"github.com/stianeikeland/go-rpio/v4"
)
func main() {
err := rpio.Open()
if err != nil {
os.Exit(1)
}
defer rpio.Close()
h := hcsr04.NewHCSR04(17, 27)
h.StartDistanceMonitor()
for {
fmt.Println(h.GetDistance())
time.Sleep(hcsr04.MonitorUpdate)
}
}
```
## Raspberry Pi compatibility
This driver has has only been tested on an Raspberry Pi Zero WH using integrated bluetooth but may work well on other Raspberry Pi having integrated Bluetooth
## License
MIT License
---
Special thanks to @stianeikeland
This driver is based on his work in [stianeikeland/go-rpio](https://github.com/stianeikeland/go-rpio/)