Remarks

Sfsr02
Status Status badge: in-progress
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Distance.Sfsr02

The SF-SR02 ultrasonic sensor uses sonar to determine distance to an object (like bats). It offers excellent non-contact range detection with high accuracy and stable readings in an easy-to-use package.

Sample projects available on GitHub### Code Example

Sfsr02 sFSR02;

public override Task Initialize()
{
    sFSR02 = new Sfsr02(Device, Device.Pins.D03);
    sFSR02.DistanceUpdated += SFSR02_DistanceUpdated;

    return Task.CompletedTask;
}

public override async Task Run()
{
    while (true)
    {
        Console.WriteLine("Measure Distance:");

        sFSR02.MeasureDistance();
        await Task.Delay(1500);
    }
}

private void SFSR02_DistanceUpdated(object sender, IChangeResult<Meadow.Units.Length> e)
{
    Console.WriteLine($"{e.New.Centimeters}cm");
}

Sample project(s) available on GitHub

Characteristic Locus
Inheritance System.Object ObservableBase<Length> SensorBase<Length> > Sfsr02
Implements IRangeFinder
Inherited Members SensorBase<Length>.Updated SensorBase<Length>.samplingLock SensorBase<Length>.SamplingTokenSource SensorBase<Length>.Conditions SensorBase<Length>.IsSampling SensorBase<Length>.UpdateInterval SensorBase<Length>.RaiseEventsAndNotify(IChangeResult<>) SensorBase<Length>.Read() ObservableBase<Length>.observers ObservableBase<Length>.NotifyObservers(IChangeResult<>) Meadow.Foundation.ObservableBase<Length>.Subscribe(IObserver<>) Meadow.Foundation.ObservableBase<Length>.CreateObserver(Action<>, System.Nullable<Predicate<IChangeResult<UNIT>>>)
Namespace Meadow.Foundation.Sensors.Distance
Assembly Sfsr02.dll

Syntax

public class Sfsr02 : SensorBase<Length>, IRangeFinder

Constructors

Sfsr02(IBiDirectionalController, IPin)

Create a new SFSR02 object with an IO Device

Declaration
public Sfsr02(IBiDirectionalController device, IPin triggerEchoPin)

Parameters

Type Name Description
IBiDirectionalController device
IPin triggerEchoPin

Sfsr02(IBiDirectionalPort)

Create a new SFSR02 object

Declaration
public Sfsr02(IBiDirectionalPort triggerEchoPort)

Parameters

Type Name Description
IBiDirectionalPort triggerEchoPort

Fields

tickStart

Start time

Declaration
protected long tickStart

Field Value

Type Description
System.Int64

triggerEchoPort

Trigger/Echo Pin

Declaration
protected IBiDirectionalPort triggerEchoPort

Field Value

Type Description
IBiDirectionalPort

Properties

Distance

Returns current distance

Declaration
public Length? Distance { get; }

Property Value

Type Description
System.Nullable<Length>

MaximumDistance

Maximum valid distance in cm

Declaration
public double MaximumDistance { get; }

Property Value

Type Description
System.Double

MinimumDistance

Minimum valid distance in cm

Declaration
public double MinimumDistance { get; }

Property Value

Type Description
System.Double

Methods

MeasureDistance()

Sends a trigger signal

Declaration
public void MeasureDistance()

RaiseEventsAndNotify(IChangeResult<Length>)

Declaration
protected override void RaiseEventsAndNotify(IChangeResult<Length> changeResult)

Parameters

Type Name Description
IChangeResult<Length> changeResult

ReadSensor()

Declaration
protected override Task<Length> ReadSensor()

Returns

Type Description
Task<Length>

Overrides

Meadow.Foundation.SensorBase<Length>.ReadSensor()

Events

DistanceUpdated

Raised when an received a rebound trigger signal

Declaration
public event EventHandler<IChangeResult<Length>> DistanceUpdated

Event Type

Type Description
EventHandler<IChangeResult<Length>>