SparkFun Soil Moisture Sensor  v1.0.1-2-g96f40cb
Library for the SparkFun Soil Moisture Sensor
Loading...
Searching...
No Matches
sfDevSoilMoisture Class Reference

Class representing the soil moisture sensor. More...

#include <sfDevSoilMoisture.h>

Inheritance diagram for sfDevSoilMoisture:

Public Member Functions

 sfDevSoilMoisture ()
 
sfTkError_t begin (sfTkIBus *theBus=nullptr)
 Initializes communication with the soil moisture sensor. More...
 
sfTkError_t LEDOff (void)
 Turns off the on-board LED. More...
 
sfTkError_t LEDOn (void)
 Turns on the on-board LED. More...
 
uint16_t readMoistureValue (void)
 Reads the moisture value from the sensor. More...
 
float readMoistureRatio (void)
 Reads the sensor value and returns the moisture ratio from the sensor. More...
 
float readMoisturePercentage (void)
 Reads the sensor value and returns the moisture percentage from the sensor. More...
 
sfTkError_t setI2CAddress (uint8_t newAddress)
 Changes the I2C address of the sensor. More...
 
uint8_t address (void)
 Returns the current address of the sensor. More...
 

Protected Attributes

sfTkIBus * _theBus
 The toolkit bus the sensor is connected to. More...
 

Detailed Description

Class representing the soil moisture sensor.

This class provides an interface to the soil moisture sensor, allowing for initialization, reading moisture values and controlling the on-board LED.

Constructor & Destructor Documentation

◆ sfDevSoilMoisture()

sfDevSoilMoisture::sfDevSoilMoisture ( )
inline

Member Function Documentation

◆ address()

uint8_t sfDevSoilMoisture::address ( void  )

Returns the current address of the sensor.

This function returns the current I2C address of the sensor if using I2C, or the Chip Select (CS) pin if using SPI.

Returns
The current I2C address of the sensor, or the CS pin for SPI

◆ begin()

sfTkError_t sfDevSoilMoisture::begin ( sfTkIBus *  theBus = nullptr)

Initializes communication with the soil moisture sensor.

This function must be called before any other methods. It establishes communication with the sensor using the provided I2C bus interface.

Parameters
theBusPointer to an I2C toolkit object. If nullptr, uses previously set bus
Returns
ksfTkErrOk if initialization succeeds
ksfTkErrBusNotInit if no valid bus interface is provided

◆ LEDOff()

sfTkError_t sfDevSoilMoisture::LEDOff ( void  )

Turns off the on-board LED.

Disables the sensor's built-in LED

Returns
ksfTkErrOk if LED was successfully turned off
ksfTkErrBusNotInit if no bus interface is configured
ksfTkErrFail if sensor doesn't respond or a communication error occurs
See also
LEDOn()

◆ LEDOn()

sfTkError_t sfDevSoilMoisture::LEDOn ( void  )

Turns on the on-board LED.

Enables the sensor's built-in LED by sending the appropriate command

Returns
ksfTkErrOk if LED was successfully turned on
ksfTkErrBusNotInit if no bus interface is configured
ksfTkErrFail if sensor doesn't respond or a communication error occurs
See also
LEDOff()

◆ readMoisturePercentage()

float sfDevSoilMoisture::readMoisturePercentage ( void  )

Reads the sensor value and returns the moisture percentage from the sensor.

This function reads the raw moisture value from the sensor and converts it to a percentage between 0 and 100%.

Returns
The moisture percentage, where 0% indicates a dry sensor and 100% indicates a wet sensor

◆ readMoistureRatio()

float sfDevSoilMoisture::readMoistureRatio ( void  )

Reads the sensor value and returns the moisture ratio from the sensor.

This function reads the raw moisture value from the sensor and converts it to a ratio between 0 and 1.0.

Returns
The moisture ratio, where 0 indicates a dry sensor and 1.0 indicates a wet sensor
Note
On error, this method returns 0

◆ readMoistureValue()

uint16_t sfDevSoilMoisture::readMoistureValue ( void  )

Reads the moisture value from the sensor.

This function reads the raw moisture value from the sensor, which is a resistance reading between 0 and 1023.

Returns
The moisture value - a resistance reading between 0 and 1023
Note
A value of 0 indicates a wet sensor, while 1023 indicates a dry sensor
On error, this method returns 0

◆ setI2CAddress()

sfTkError_t sfDevSoilMoisture::setI2CAddress ( uint8_t  newAddress)

Changes the I2C address of the sensor.

This function sets a new I2C address for the sensor. The new address will be used for all future I2C communication with the sensor. This value is persistent

Parameters
newAddressThe new I2C address to assign to the sensor
Returns
ksfTkErrOk if successful, otherwise an error code
Note
If communicating via I2C, the provided address is used for future I2C communication

Member Data Documentation

◆ _theBus

sfTkIBus* sfDevSoilMoisture::_theBus
protected

The toolkit bus the sensor is connected to.

This member variable holds a pointer to the bus interface (I2C or SPI) used for communication with the soil moisture sensor.


The documentation for this class was generated from the following files: