You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+64Lines changed: 64 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,6 +24,70 @@ This library provides a simple interface that enables the following functionalit
24
24
* Turn the on-board LED on and off
25
25
* Change the I2C address of the sensor - if you want to avoid a conflict, or used multiple moisture sensors together.
26
26
27
+
## General Use
28
+
29
+
The following outlines the general use of the library in an Arduino Sketch.
30
+
31
+
### Declaration
32
+
33
+
At the start of your sketch, the library header file is included using the following statement:
34
+
35
+
```c++
36
+
#include"SparkFun_Soil_Moisture_Sensor.h"
37
+
```
38
+
39
+
Before the arduino ```setup()``` function, create a Soil Sensor object in your file with the following declaration:
40
+
41
+
```c++
42
+
SparkFunSoilMoistureSensor mySoilSensor; // Create an instance of the sensor class
43
+
```
44
+
45
+
### Initialization
46
+
47
+
In the Arduino ```setup()``` function, initialize the sensor by calling the begin method. This method is called after the Arduino `Wire` (I2C) library is initialized.
48
+
49
+
```c++
50
+
if (mySoilSensor.begin() == false)
51
+
{
52
+
Serial.println("Soil Moisture Sensor not detected at default I2C address. Verify the sensor is connected. Stopping.");
53
+
while (1)
54
+
;
55
+
}
56
+
```
57
+
58
+
The begin method returns true if the sensor is connected and available, and false if it is not. If a value of ```false``` is returned in the above example, the sketch execution is halted.
59
+
60
+
### Usage
61
+
62
+
#### Read Value
63
+
To read the value from the sensor, the ```readMoistureValue()``` method is called on the sensor object.
The value returned is from 0 (100% wet) to 1024 (0% web - "dry"). The value is a measurement of resistance between the sensors two probes. The value range is based on the capabilities of the Analog to Digital converter (ADC) on the sensors microcontroller - it's 10 bits with a max value of 2^10 = 1024.
70
+
71
+
#### Control the On-Sensor LED
72
+
73
+
The Soil Sensor has user controllable LED and the library has two methods to control if the LED is on or off. The following example shows how to *wink* the LED.
74
+
75
+
```c++
76
+
// Wink the LED during the reading
77
+
mySoilSensor.LEDOn();
78
+
delay(100);
79
+
mySoilSensor.LEDOff();
80
+
81
+
```
82
+
83
+
## Examples
84
+
85
+
The following examples are provided with the library
86
+
87
+
- [Basic Readings](examples/Example_01_BasicReadings/Example_01_BasicReadings.ino) - Setup and read the soil moisture from the sensor
88
+
- [Readings and LED](examples/Example_02_ReadingsAndLED/Example_02_ReadingsAndLED.ino) - Flash the sensor LED when reading the moisture value
89
+
- [LED Flash Based on Moisture Percentage](examples/Example_03_LEDFlashMoisture/Example_03_LEDFlashMoisture.ino) - Vary the sensor LED flash rate based on the moisture percent sensed. The flash rate increases the drier the sensed value
90
+
27
91
## Documentation
28
92
29
93
The full API and use documentation for this library is provided [here](docs.sparkfun.com/SparkFun_Soil_Moisture_Arduino_Library/). For a quick reference, the main methods available in the library are listed [here](https://docs.sparkfun.com/SparkFun_Soil_Moisture_Arduino_Library/functions.html).
0 commit comments