Skip to content

Latest commit

 

History

History
41 lines (29 loc) · 903 Bytes

README.md

File metadata and controls

41 lines (29 loc) · 903 Bytes

HC-SR04 - Ultrasonic Ranging Module

Device bindings for the HC-SR04 sonar distance sensor. Calculates the distance from an object by using the HC-SR04 distance sensor.

Documentation

Usage

using (var sonar = new Hcsr04(4, 17))
{
    if (sonar.TryGetDistance(out Length distance))
    {
        Console.WriteLine($"Distance: {distance.Centimeters} cm");
    }
    else
    {
        Console.WriteLine("Error reading sensor");
    }

    Thread.Sleep(1000);
}

Hardware Required

  • HC-SR04
  • Male/Female Jumper Wires

Circuit

Fritz diagram

  • VCC - 5V
  • GND - GND
  • Trig - GPIO 4
  • Echo - GPIO 17

The fritz diagram above depicts how you should wire your RPi in order to run the program, the resistance for R1 is 1kOhm. (Optional).