Any Framework
Iot.Device.Hcsr501 assembly for .NET nanoFramework C# projects
Published
Sep 15, 2022
4y ago
Total Downloads
26.7K
26,716
Install
dotnet add package nanoFramework.Iot.Device.Hcsr501 --version 1.2.87
No framework information available.
README
HC-SR501 - PIR Motion Sensor
HC-SR501 is used to detect motion based on the infrared heat in the surrounding area.
Documentation

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

HC-SR501

- VCC - 5V
- GND - GND
- OUT - GPIO 17
LED
- VCC & 220 Ω resistor - GPIO 27
- GND - GND
Result

Changes from Previous Version
No structural changes between v1.2.73 and v1.2.87.
Adoption Assessment
A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.
No SPDX license expression is published. Review the license text and your organisation's policy before redistribution.No target framework metadata is available. Confirm compatibility in a representative project before standardising on this package.
Related Guides & Workflows
Learn how to evaluate, integrate, or audit this package in your .NET project.