Chirp soils moisture sensor

Hi I’m trying to run the Chirp! moisture sensor with this connections

Chirp pin 1 - no connection
Chirp pin 2 - Arduino VCC
Chirp pin 3 - Arduino A5 (SCL)
Chirp pin 4 - Arduino A4 (SDA)
Chirp pin 5 - Arduino pin 2
Chirp pin 6 - Arduino GND

and with this code

#include <I2CSoilMoistureSensor.h>
#include <Wire.h>

I2CSoilMoistureSensor sensor;

void setup() {
  Wire.begin();
  Serial.begin(9600);

  sensor.begin(); // reset sensor
  delay(1000); // give some time to boot up
  Serial.print("I2C Soil Moisture Sensor Address: ");
  Serial.println(sensor.getAddress(), HEX);
  Serial.print("Sensor Firmware version: ");
  Serial.println(sensor.getVersion(), HEX);
  Serial.println();
}

void loop() {
  while (sensor.isBusy())
    delay(5000); // available since FW 2.3
  Serial.print("Soil Moisture Capacitance: ");
  Serial.print(sensor.getCapacitance()); //read capacitance register
  Serial.print(", Temperature: ");
  Serial.print(sensor.getTemperature() / (float)10); //temperature register
  Serial.print(", Light: ");
  Serial.println(sensor.getLight(true)); //request light measurement, wait and read light register
  delay(3000);
  sensor.sleep(); // available since FW

I only get this measures:

Soil Moisture Capacitance: 9983, Temperature: -0.10, Light: 265
Soil Moisture Capacitance: 12287, Temperature: -0.10, Light: 264
Soil Moisture Capacitance: 12543, Temperature: -0.10, Light: 263
Soil Moisture Capacitance: 11775, Temperature: -0.10, Light: 265
Soil Moisture Capacitance: 14079, Temperature: -0.10, Light: 265
Soil Moisture Capacitance: 14335, Temperature: -0.10, Light: 265
Soil Moisture Capacitance: 15359, Temperature: -0.10, Light: 264
Soil Moisture Capacitance: 5887, Temperature: -0.10, Light: 265
Soil Moisture Capacitance: 16895, Temperature: -0.10, Light: 265
Soil Moisture Capacitance: 16639, Temperature: -0.10, Light: 264
Soil Moisture Capacitance: 17151, Temperature: -0.10, Light: 264
Soil Moisture Capacitance: 8447, Temperature: -0.10, Light: 264
Soil Moisture Capacitance: 10751, Temperature: -0.10, Light:

Anybody knows what could be the problem?

Thanks in advance for your help. I really appreciate any help you can provide.

(deleted)

Which Arduino. What sort of wire between sensor and Arduino, and how long. Does the data in setup() print ok.

Is that the right code for the sensor. The latest Chirp! boards I see online have SPI, not I2C. Leo..

spycatcher2k: Did you add pull up resistors?

Yes, i probe different resistance values.

Wawa: Which Arduino. What sort of wire between sensor and Arduino, and how long. Does the data in setup() print ok.

Is that the right code for the sensor. The latest Chirp! boards I see online have SPI, not I2C. Leo..

Arduino Uno with 20 cm long dupont wires

This is the sensor that i'm using

https://www.aliexpress.com/item/CJMCU-Plant-Watering-Alarm-Alerter-Humidity-Moisture-Sensor-Module-Soil-Sensor-Module-New-Arrival/32842054964.html

Please answer ALL the questions. And what version Chirp!. Leo..

Setup print

I2C Soil Moisture Sensor Address: 20 Sensor Firmware version: 1

Chirp! v.2.4

Can't find any power supply info for this sensor. How do you power it now. Did you share ground with the Arduino. Post an image of the setup. Leo..

Does it even show up on an I2C scanner? That'd be the first test, as it tells you whether the wiring is in working order and the connections are correct.


  • For Chirp! v.2.4 ONLY !!!*

class I2CSoilMoistureSensor {
public:
I2CSoilMoistureSensor();

uint8_t begin();
unsigned int getCapacitance();
void resetSensor();
uint8_t getVersion(){ return m_version;}

private:
uint8_t readVersion();
uint8_t m_version;
void writeI2CRegister8bit(int addr, int value);
void writeI2CRegister8bit(int addr, int reg, int value);
uint16_t readI2CRegister16bitUnsigned(int addr, byte reg);
int16_t readI2CRegister16bitSigned(int addr, byte reg);
uint8_t readI2CRegister8bit(int addr, int reg);
};

#include <Wire.h>
#define SOILMOISTURESENSOR_GET_CAPACITANCE 0x00 // (r) 2 bytes
#define SOILMOISTURESENSOR_GET_VERSION 0x07 // (r) 1 bytes
I2CSoilMoistureSensor::I2CSoilMoistureSensor()
{
}
uint8_t I2CSoilMoistureSensor::begin() {
uint8_t ver;
Wire.begin();
readI2CRegister16bitUnsigned(SOILMOISTURESENSOR_DEFAULT_ADDR, SOILMOISTURESENSOR_GET_CAPACITANCE);
for(int i=0; i<10; i++)
{
delay(100);
m_version = readVersion();
if (m_version == 1)
return m_version;
}
return 0;
}
unsigned int I2CSoilMoistureSensor::getCapacitance() {
if(m_version)
return readI2CRegister16bitUnsigned(SOILMOISTURESENSOR_DEFAULT_ADDR, SOILMOISTURESENSOR_GET_CAPACITANCE);
return 0;
}
uint8_t I2CSoilMoistureSensor::readVersion() {
return readI2CRegister8bit(SOILMOISTURESENSOR_DEFAULT_ADDR, SOILMOISTURESENSOR_GET_VERSION);
}

void I2CSoilMoistureSensor::writeI2CRegister8bit(int addr, int value) {
Wire.beginTransmission(addr);
Wire.write(value);
Wire.endTransmission();
}

void I2CSoilMoistureSensor::writeI2CRegister8bit(int addr, int reg, int value) {
Wire.beginTransmission(addr);
Wire.write(reg);
Wire.write(value);
Wire.endTransmission();
}
uint16_t I2CSoilMoistureSensor::readI2CRegister16bitUnsigned(int addr, byte reg)
{
uint16_t value;

Wire.beginTransmission((uint8_t)addr);
Wire.write((uint8_t)reg);
Wire.endTransmission();
delay(20);
Wire.requestFrom((uint8_t)addr, (byte)2);
value = (Wire.read() << 8 ) | Wire.read();

return value;
}
uint8_t I2CSoilMoistureSensor::readI2CRegister8bit(int addr, int reg) {
Wire.beginTransmission(addr);
Wire.write(reg);
Wire.endTransmission();
delay(20);
Wire.requestFrom(addr, 1);
return Wire.read();
}