I2C soil moisture sensor
|Availability:||In stock (17)|
The sensor is coated in epoxy resin, cured and additionally protected by adhesive-lined heat shrink. The 1m (3 feet) long cable is pre-soldered. Light sensor is covered by heatshrink!!, so the light reading will always report total darkness.
The sensor can be read via I2C protocol and provides these features:
- Soil moisture sensing
- Light sensing
- Temperature sensing
- Reset chip
- I2C address change
- Deep sleep
- Version 2.7.5
- Supply voltage 3.3V - 5V
- Current consumption: 1.1mA @ 5V, 0.7mA @ 3.3V when idle, 14mA @ 5V, 7.8mA @ 3.3V when taking a measurement. When constantly polling sensor at full speed, current consumption averages to 4.5mA @ 5V, 2.8mA @ 3.3V
- Operating temperature 0°C - 85°C
- Moisture reading drift with temperature - <10% over full temp range
- Don't forget to provide pullups for SCL and SDA lines
- Default I2C address is 0x20 (hex)
- To read soil moisture, read 2 bytes from register 0
- To read light level, start measurement by writing 3 to the device I2C address, wait for 3 seconds, read 2 bytes from register 4
- To read temperature, read 2 bytes from register 5
- To change the I2C address of the sensor, write a new address (one byte [1..127]) to register 1; the new address will take effect after reset
- To reset the sensor, write 6 to the device I2C address.
- Do not hotplug the sensor into the active I2C bus - address change command has no protection and this might result in a random number set as an address of the sensor. Use I2C scan sketch to find out the address if the sensor stops responding with proper values.
More documentation and example code is available on github page.
The easiest way to get the sensor working on Arduino compatible environment is to use the library by Ingo Fischer it is available thru Arduino environment, make sure to use version 1.1.4 or later as it contains some fixes for address change and bus hang bugs fixed in the firmware version 2.6.
How to interpret the readings
Both light and moisture sensors give relative values. Meaning, more moisture will give you higher reading, more light, lower reading.
Moisture is somewhat linear. I test all sensors before shipping and they give about 290 - 310 in free air at 5V supply.
The light sensor gives 65535 in a dark room away form desk lamp. When it's dark, it takes longer to measure light, reading the light register while measurement is in progress will return the previous reading.
Temperature is measured by the thermistor on the body of the sensor. Calculated absolute measurement accuracy is better than 2%. The returned value is in tenths of degrees Celsius. I.e. value 252 would mean 25.2°C.
Note Upon reading the moisture or temperature value, a value form the previous read command is returned and the new measurement is started. If you do rare measurements and want to act instantly, do two consecutive readings to get the most up to date data. Also you can read GET_BUSY register via i2c - it will indicate when the measurement is done. Basically the process goes like this: read from GET_CAPACITANCE, discard results, then read from GET_BUSY until you get '0' as an answer, then read form GET_CAPACITANCE again - the returned value is the soil moisture NOW.
The sensor works fine with Arduino and RaspberryPi. Examples are available on github page.
- Arduino library: https://github.com/Apollon77/I2CSoilMoistureSensor
- Raspberry Pi library: https://github.com/ageir/chirp-rpi
- Particle proton library: https://github.com/VintageGeek/I2CSoilMoistureSensor
- Micropython library: https://github.com/scopelemanuele/pyChirpLib
Note for ESP8266 based systems
In some cases the default ESP8266 Arduino I2C library has the clock stretching timeout set too low. If you experience intermittent communication, add this to your code:
- RED - VCC
- BLACK - GND
- BLUE or GREEN- SDA
- YELLOW - SCK
Shield is not grounded on the sensor end and must be grounded on the master end.