nanoFramework.Iot.Device.Hcsr501 1.0.277-preview.126

Prefix Reserved
This is a prerelease version of nanoFramework.Iot.Device.Hcsr501.
There is a newer version of this package available.
See the version list below for details.
dotnet add package nanoFramework.Iot.Device.Hcsr501 --version 1.0.277-preview.126                
NuGet\Install-Package nanoFramework.Iot.Device.Hcsr501 -Version 1.0.277-preview.126                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="nanoFramework.Iot.Device.Hcsr501" Version="1.0.277-preview.126" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add nanoFramework.Iot.Device.Hcsr501 --version 1.0.277-preview.126                
#r "nuget: nanoFramework.Iot.Device.Hcsr501, 1.0.277-preview.126"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install nanoFramework.Iot.Device.Hcsr501 as a Cake Addin
#addin nuget:?package=nanoFramework.Iot.Device.Hcsr501&version=1.0.277-preview.126&prerelease

// Install nanoFramework.Iot.Device.Hcsr501 as a Cake Tool
#tool nuget:?package=nanoFramework.Iot.Device.Hcsr501&version=1.0.277-preview.126&prerelease                

HC-SR501 - PIR Motion Sensor

HC-SR501 is used to detect motion based on the infrared heat in the surrounding area.

Documentation

sensor

Usage

using(Hcsr501 sensor = new Hcsr501(hcsr501Pin, PinNumberingScheme.Logical))
{
    // detect motion
    bool isDetected = sensor.IsMotionDetected;
}

From the HC-SR501 sample, we can do comething more complete:

GpioController ledController = new GpioController();
ledController.OpenPin(27, PinMode.Output);

using (Iot.Device.Hcsr501.Hcsr501 sensor =
    new Iot.Device.Hcsr501.Hcsr501(17))
{
    while (true)
    {
        // adjusting the detection distance and time by rotating the potentiometer on the sensor
        if (sensor.IsMotionDetected)
        {
            // turn the led on when the sensor detected infrared heat
            ledController.Write(27, PinValue.High);
            Debug.WriteLine("Detected! Turn the LED on.");
        }
        else
        {
            // turn the led off when the sensor undetected infrared heat
            ledController.Write(27, PinValue.Low);
            Debug.WriteLine("Undetected! Turn the LED off.");
        }

        Thread.Sleep(1000);
    }
}

Hardware Required

  • PIR Motion Sensor - HC-SR501
  • LED
  • 220 Ω resistor
  • Male/Female Jumper Wires

Circuit

circuit

HC-SR501

settings

  • VCC - 5V
  • GND - GND
  • OUT - GPIO 17

LED

  • VCC & 220 Ω resistor - GPIO 27
  • GND - GND

Result

result

Product Compatible and additional computed target framework versions.
.NET Framework net is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.631 71 8/28/2024
1.2.590 74 7/17/2024
1.2.570 76 6/14/2024
1.2.560 85 5/29/2024
1.2.548 65 5/15/2024
1.2.436 281 11/10/2023
1.2.416 117 11/8/2023
1.2.329 204 5/26/2023
1.2.313 162 5/12/2023
1.2.297 182 5/3/2023
1.2.217 354 1/6/2023
1.2.203 325 12/28/2022
1.2.159 401 11/14/2022
1.2.153 403 11/5/2022
1.2.141 422 10/25/2022
1.2.122 458 10/12/2022
1.2.114 415 10/8/2022
1.2.95 455 9/22/2022
1.2.87 519 9/15/2022
1.2.73 434 9/8/2022
1.1.116.8772 467 6/24/2022
1.1.113.2032 445 6/23/2022
1.1.58.10097 468 5/23/2022
1.1.3 486 4/15/2022
1.1.1 460 4/14/2022
1.0.300 468 3/31/2022
1.0.277-preview.126 120 3/25/2022
1.0.277-preview.125 111 3/25/2022
1.0.277-preview.112 109 3/19/2022
1.0.277-preview.110 107 3/18/2022
1.0.277-preview.105 112 3/15/2022
1.0.277-preview.99 116 3/10/2022
1.0.277-preview.98 117 3/8/2022
1.0.277-preview.77 108 2/18/2022
1.0.277-preview.41 124 1/28/2022
1.0.277-preview.32 131 1/27/2022
1.0.277-preview.17 127 1/24/2022
1.0.277-preview.15 116 1/21/2022
1.0.277-preview.13 122 1/21/2022
1.0.277-preview.1 125 1/11/2022
1.0.259 330 12/9/2021
1.0.218 193 10/18/2021
1.0.155 339 8/31/2021
1.0.135 361 7/16/2021
1.0.134 168 7/15/2021
1.0.133 178 7/14/2021
1.0.125 193 7/5/2021
1.0.121 199 6/29/2021
1.0.119 220 6/28/2021
1.0.105 267 5/29/2021
1.0.13 179 5/21/2021