Remarks

Hcsen0040
Status
Source code GitHub
NuGet package

The HCSENS0040 is a microwave motion detector commonly found on the RCWL-0516 board. It detects relative motion using the doppler effect. It uses a single GPIO pin to notify Meadow when motion is detected.

Code Example

public class MeadowApp : App<F7Micro, MeadowApp>
{
    Hcsens0040 sensor;
    Led blueLed;

    public MeadowApp()
    {
        sensor = new Hcsens0040(Device.CreateDigitalInputPort(Device.Pins.D05));
        sensor.OnMotionDetected += ParallaxPirOnMotionStart;

        blueLed = new Led(Device.CreateDigitalOutputPort(Device.Pins.OnboardLedBlue));
    }

    //here's an example where it's ok to use async void
    //the method signature is required to be void because of the event
    async void ParallaxPirOnMotionStart(object sender)
    {
        Console.WriteLine($"Motion started {DateTime.Now}");
        blueLed.IsOn = true;

        await Task.Delay(2000);

        blueLed.IsOn = false;
    }
}

Sample projects available on GitHub

Wiring Example

To wire a Hcsens0040 to your Meadow board, connect the following:

Hcsens0040 Meadow Pin
GND GND
TriggerOut D05
VCC 3V3
Characteristic Locus
Inheritance System.Object > Hcsens0040
Inherited Members System.Object.ToString() System.Object.Equals(System.Object) System.Object.Equals(System.Object, System.Object) System.Object.ReferenceEquals(System.Object, System.Object) System.Object.GetHashCode() System.Object.GetType() System.Object.MemberwiseClone()
Namespace Meadow.Foundation.Sensors.Motion
Assembly Hcsens0040.dll

Syntax

public class Hcsens0040

Constructors

Hcsens0040(IDigitalInputPort)

Create a new Parallax PIR object connected to a interrupt port.

Declaration
public Hcsens0040(IDigitalInputPort digitalInputPort)

Parameters

Type Name Description
IDigitalInputPort digitalInputPort

Hcsens0040(IIODevice, IPin)

Create a new Parallax PIR object connected to an input pin and IO Device.

Declaration
public Hcsens0040(IIODevice device, IPin pin)

Parameters

Type Name Description
IIODevice device
IPin pin

Events

OnMotionDetected

Event raised when motion is detected.

Declaration
public event Hcsens0040.MotionChange OnMotionDetected

Event Type

Type Description
Hcsens0040.MotionChange