Remarks
Capacitive | |
---|---|
Status | |
Source code | GitHub |
NuGet package |
Capacitive Soil Moisture sensor is a simple breakout for measuring the moisture in soil and similar materials. This sensor measures moisture levels by capacitive sensing, rather then resistive sensing like other types of moisture sensor such as the FC-28.
Capacitive sensing means measuring the dielectrum that is formed by the soil and the water is the most important factor that forms the dielectrum. Even though this kind of sensor might be a little pricier, it is made of corrosion resistant material giving it a longer service of life than a resistive sensor.
The following example shows how read the soil moisture every second:
public class MeadowApp : App<F7Micro, MeadowApp>
{
Capacitive _Capacitive;
public MeadowApp()
{
// create a new Capacitive sensor object connected to analog pin A01
_Capacitive = new Capacitive(Device.Pins.A01);
Run();
}
async Task Run()
{
while (true)
{
float moisture = await _Capacitive.Read();
Console.WriteLine($"Moisture: {0}", moisture);
Thread.Sleep(1000);
}
}
}
Sample projects available on GitHub
Wiring Example
Characteristic | Locus |
---|---|
Inheritance | System.Object FilterableChangeObservableBase<FloatChangeResult, System.Single> > Capacitive |
Implements | System.IObservable<FloatChangeResult> IMoistureSensor |
Inherited Members | FilterableChangeObservableBase<FloatChangeResult, Single>._observers FilterableChangeObservableBase<FloatChangeResult, Single>.NotifyObservers(FloatChangeResult) FilterableChangeObservableBase<FloatChangeResult, Single>.Subscribe(IObserver<FloatChangeResult>) 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.Moisture |
Assembly | Capacitive.dll |
Syntax
public class Capacitive : FilterableChangeObservableBase<FloatChangeResult, float>, IObservable<FloatChangeResult>, IMoistureSensor
Constructors
Capacitive(IAnalogInputPort, Single, Single)
Creates a Capacitive soil moisture sensor object with the especified AnalogInputPort.
Declaration
public Capacitive(IAnalogInputPort analogPort, float minimumVoltageCalibration = 0F, float maximumVoltageCalibration = 3.3F)
Parameters
Type | Name | Description |
---|---|---|
IAnalogInputPort | analogPort | |
System.Single | minimumVoltageCalibration | |
System.Single | maximumVoltageCalibration |
Capacitive(IIODevice, IPin, Single, Single)
Creates a Capacitive soil moisture sensor object with the specified analog pin and a IO device.
Declaration
public Capacitive(IIODevice device, IPin analogPin, float minimumVoltageCalibration = 0F, float maximumVoltageCalibration = 3.3F)
Parameters
Type | Name | Description |
---|---|---|
IIODevice | device | |
IPin | analogPin | |
System.Single | minimumVoltageCalibration | |
System.Single | maximumVoltageCalibration |
Properties
AnalogInputPort
Returns the analog input port
Declaration
public IAnalogInputPort AnalogInputPort { get; protected set; }
Property Value
Type | Description |
---|---|
IAnalogInputPort |
IsSampling
Gets a value indicating whether the analog input port is currently sampling the ADC. 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; protected set; }
Property Value
Type | Description |
---|---|
System.Single |
Methods
Map(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
Updated
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> |