![]() |
VOOZH | about |
dotnet add package nanoFramework.Iot.Device.Hcsr04 --version 1.2.952
NuGet\Install-Package nanoFramework.Iot.Device.Hcsr04 -Version 1.2.952
<PackageReference Include="nanoFramework.Iot.Device.Hcsr04" Version="1.2.952" />
<PackageVersion Include="nanoFramework.Iot.Device.Hcsr04" Version="1.2.952" />Directory.Packages.props
<PackageReference Include="nanoFramework.Iot.Device.Hcsr04" />Project file
paket add nanoFramework.Iot.Device.Hcsr04 --version 1.2.952
#r "nuget: nanoFramework.Iot.Device.Hcsr04, 1.2.952"
#:package nanoFramework.Iot.Device.Hcsr04@1.2.952
#addin nuget:?package=nanoFramework.Iot.Device.Hcsr04&version=1.2.952Install as a Cake Addin
#tool nuget:?package=nanoFramework.Iot.Device.Hcsr04&version=1.2.952Install as a Cake Tool
Device bindings for the HC-SR04 sonar distance sensor. Calculates the distance from an object by using the HC-SR04 distance sensor.
In most of the cases, you just need to pass the 2 pins you're going to use: the Echo and Trigger pins.
using (var sonar = new Hcsr04(4, 17))
{
if (sonar.TryGetDistance(out Length distance))
{
Debug.WriteLine($"Distance: {distance.Centimeters} cm");
}
else
{
Debug.WriteLine("Error reading sensor");
}
Thread.Sleep(1000);
}
Note: it is possible to use the same pin for both Trigger and Echo but it's not recommended.
The fritz diagram above depicts how you should wire your MCU in order to run the program, the resistance for R1 is 1kOhm. (Optional). As the HCSR04 works only with 5V and the MCU are mainly 3.3V, this resistor will help protecting the MCU. Check your MCU to see if the pin is 5V tolerant or not.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET Framework | net net is compatible. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.0.0-preview.85 | 52 | 6/1/2026 |
| 2.0.0-preview.80 | 50 | 5/27/2026 |
| 2.0.0-preview.73 | 60 | 5/20/2026 |
| 2.0.0-preview.62 | 61 | 5/13/2026 |
| 2.0.0-preview.49 | 49 | 5/4/2026 |
| 2.0.0-preview.45 | 57 | 4/29/2026 |
| 2.0.0-preview.37 | 58 | 4/22/2026 |
| 2.0.0-preview.32 | 59 | 4/20/2026 |
| 2.0.0-preview.16 | 58 | 3/10/2026 |
| 1.2.952 | 141 | 3/4/2026 |
| 1.2.931 | 315 | 11/10/2025 |
| 1.2.907 | 280 | 10/2/2025 |
| 1.2.889 | 273 | 7/28/2025 |
| 1.2.869 | 373 | 4/2/2025 |
| 1.2.864 | 354 | 4/2/2025 |
| 1.2.852 | 353 | 3/11/2025 |
| 1.2.846 | 364 | 3/10/2025 |
| 1.2.822 | 290 | 2/26/2025 |
| 1.2.775 | 327 | 2/4/2025 |
| 1.2.772 | 292 | 2/4/2025 |