Characteristic | Locus |
---|---|
Inheritance | System.Object > FC28 |
Implements | IMoistureSensor |
Namespace | Meadow.Foundation.Sensors.Moisture |
Assembly | FC28.dll |
Syntax
public class FC28 : FilterableObservableBase<FloatChangeResult, float>, IMoistureSensor
Remarks
FC-28 Soil Moisture Sensor is a simple breakout for measuring the moisture in soil and similar materials. The sensor has two probes and measures the resistance between them, which means this sensor is of type Resistive. Since water is conductive, as moisture in the soil increases, the resistance decreases allowing the sensor to determine soil humidity.
The biggest issue of this sensor is the corrosion of the probes, not just because it is in contact with the soil but also because there is a DC current flowing which causes electrolysis of the sensors. A workararound to prolong the life of the probes is to not constantly have the sensor powered on, but activate it everytime the sensor will perform a read using a digital output port connected to the VCC pin. The code and circuit example shows you how to use it.
Examples
The following example shows how read the soil moisture every second:
using System.Threading;
using Meadow;
using Meadow.Foundation.Sensors.Moisture;
namespace FC28_Sample
{
public class Program
{
static IApp _app;
public static void Main()
{
_app = new App();
}
}
public class App : AppBase<F7Micro, App>
{
FC28 _FC28;
public App ()
{
// create a new FC-28 object connected to analog pin A01 and digital pin 14
_FC28 = new FC28(Device.Pins.A01, Device.Pins.D14);
Run();
}
async Task Run()
{
while (true)
{
float moisture = await _FC28.Read();
Console.WriteLine($"Moisture: {0}", moisture);
Thread.Sleep(1000);
}
}
}
}
Example Circuit
Constructors
View SourceFC28(IAnalogInputPort, IDigitalOutputPort, Single, Single)
Creates a FC28 soil moisture sensor object with the especified analog pin and digital pin.
Declaration
public FC28(IAnalogInputPort analogPort, IDigitalOutputPort digitalPort, float minimumVoltageCalibration = 0F, float maximumVoltageCalibration = 3.3F)
Parameters
Type | Name | Description |
---|---|---|
IAnalogInputPort | analogPort | |
IDigitalOutputPort | digitalPort | |
System.Single | minimumVoltageCalibration | |
System.Single | maximumVoltageCalibration |
FC28(IIODevice, IPin, IPin, Single, Single)
Creates a FC28 soil moisture sensor object with the especified analog pin, digital pin and IO device.
Declaration
public FC28(IIODevice device, IPin analogPin, IPin digitalPin, float minimumVoltageCalibration = 0F, float maximumVoltageCalibration = 3.3F)
Parameters
Type | Name | Description |
---|---|---|
IIODevice | device | |
IPin | analogPin | |
IPin | digitalPin | |
System.Single | minimumVoltageCalibration | |
System.Single | maximumVoltageCalibration |
Properties
View SourceAnalogInputPort
Returns the analog input port
Declaration
public IAnalogInputPort AnalogInputPort { get; protected set; }
Property Value
Type | Description |
---|---|
IAnalogInputPort |
DigitalPort
Returns the digital output port
Declaration
public IDigitalOutputPort DigitalPort { get; protected set; }
Property Value
Type | Description |
---|---|
IDigitalOutputPort |
IsSampling
Gets a value indicating whether the sensor is currently in a sampling loop. Call StartSampling() to spin up the sampling process.
Declaration
public bool IsSampling { get; protected set; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
MaximumVoltageCalibration
Voltage value of most moist soil
Declaration
public float MaximumVoltageCalibration { get; set; }
Property Value
Type | Description |
---|---|
System.Single |
MinimumVoltageCalibration
Voltage value of most dry soil
Declaration
public float MinimumVoltageCalibration { get; set; }
Property Value
Type | Description |
---|---|
System.Single |
Moisture
Last value read from the moisture sensor.
Declaration
public float Moisture { get; }
Property Value
Type | Description |
---|---|
System.Single |
Methods
View SourceMap(Single, Single, Single, Single, Single)
Re-maps a value from one range (fromLow - fromHigh) to another (toLow - toHigh).
Declaration
protected float Map(float value, float fromLow, float fromHigh, float toLow, float toHigh)
Parameters
Type | Name | Description |
---|---|---|
System.Single | value | |
System.Single | fromLow | |
System.Single | fromHigh | |
System.Single | toLow | |
System.Single | toHigh |
Returns
Type | Description |
---|---|
System.Single |
RaiseChangedAndNotify(FloatChangeResult)
Declaration
protected void RaiseChangedAndNotify(FloatChangeResult changeResult)
Parameters
Type | Name | Description |
---|---|---|
FloatChangeResult | changeResult |
Read(Int32, Int32)
Convenience method to get the current soil moisture. For frequent reads, use StartUpdating() and StopUpdating().
Declaration
public Task<float> Read(int sampleCount = 10, int sampleInterval = 40)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | sampleCount | The number of sample readings to take. Must be greater than 0. |
System.Int32 | sampleInterval | The interval, in milliseconds, between sample readings. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Single> |
StartUpdating(Int32, Int32, Int32)
Starts continuously sampling the sensor.
This method also starts raising Updated
events and IObservable
subscribers getting notified. Use the standbyDuration
parameter
to specify how often events and notifications are raised/sent.
Declaration
public void StartUpdating(int sampleCount = 10, int sampleIntervalDuration = 40, int standbyDuration = 1000)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | sampleCount | How many samples to take during a given reading. These are automatically averaged to reduce noise. |
System.Int32 | sampleIntervalDuration | The time, in milliseconds, to wait in between samples during a reading. |
System.Int32 | standbyDuration | The time, in milliseconds, to wait
between sets of sample readings. This value determines how often
|
StopUpdating()
Stops sampling the sensor.
Declaration
public void StopUpdating()
VoltageToMoisture(Single)
Declaration
protected float VoltageToMoisture(float voltage)
Parameters
Type | Name | Description |
---|---|---|
System.Single | voltage |
Returns
Type | Description |
---|---|
System.Single |
Events
View SourceUpdated
Raised when a new sensor reading has been made. To enable, call StartUpdating().
Declaration
public event EventHandler<FloatChangeResult> Updated
Event Type
Type | Description |
---|---|
System.EventHandler<FloatChangeResult> |