Saturday, January 4, 2014

When Do I Water My Plants? (Soil Hygrometer Sensor)

Today's project is reading a soil hygrometer in a house plant to determine the moisture level. We are using a SainSmart UNO developer board with extra rows of Gnd and 5v headers. The sensor we are using is the Sunkee Soil Hygrometer, which has analog and digital output. It is marked VCC (5v), Gnd, D0, and A0. We are using the analog outputs so that we can see the moisture percentage and turn on a pump, but you can also use the digital output to turn on a pump or indicate dry/wet. If you use fertilizer, your percentage reading can be higher than normal (makes the soil more conductive), and the sensor itself will become less conductive (reading dryer) over time as it degrades. Different kinds of plants want different moisture levels.

I dropped the sensor into a glass of water, with the water level the same level as the soil would be on the sensor. The value printed (Serial.println(sensorValue);) became the number I used in the constrain statement and the map statement (485). I then commented out the Serial.println(sensorValue); line as I no longer wanted to see the raw value. The dry sensor value would be 1023. The map command takes a value of 485-1023 and turns it into 100-0%.

Turning on a pump when the moisture level drops below a certain point and running it for a certain amount of time would be a simple addition to this project.

Here is the sketch and the output:

And more photo's of the project:

int soil=0;

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  sensorValue = constrain(sensorValue, 485, 1023);
  // print out the value you read:

  //map the value to a percentage
  soil = map(sensorValue, 485, 1023, 100, 0);
  // print out the soil water percentage you calculated:

  delay(1000);        // delay in between reads for stability


  1. Stumbled upon your site. Been working on (frustrated by, actually...) merging several sensors together to get my garden irrigation idea to work how I need it to. Like your conversion to percentage idea. now, if only I could get my code to wor, lol...