Skip to content
raspberrypi-go-driversPublic

About

Driver allowing to usea HC-SR04 ultrasound distance sensor

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

HC-SR04

Go Reference golangci-lint Go Report Card License: MIT

hcsr04 is a driver allowing to usea HC-SR04 ultrasound distance sensor

Documentation

For full documentation, please visit Go Reference

Quick start

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

About

Driver allowing to usea HC-SR04 ultrasound distance sensor

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Contributors

Languages