Subscribe to Arduino Academy and start learning today for FREE!

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.

Become the Maker you were born to be. Try Arduino Academy for FREE!

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

Become the Maker you were born to be. Try Arduino Academy for FREE!

Notify of
Inline Feedbacks
View all comments
7 years ago

thanks mate.. worked like charm

7 years ago

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…

5 years ago

Im trying to get this sensor to work with blynk, but i can only get values like high or down, as in "on" and "off". Im trying to use the 8266 esp01S, anyone knows hot to read values? not in a 0 or 1 fashion way but in actual values like 500 1023 etc… i know that when connected to the gpio2 of the esp01s, the led from the esp recieves/reads a value to the led because this act in progressive way, not in the like on or off sense… any help ideias ?

5 years ago

I need to know howit works internally n terms of mathematical xpressions.

Steve Spence
5 years ago

Esp8266 01 doesn't have an analog input. The -12 has one adc that takes a 0-1v input.

Steve Spence
5 years ago

The sensor has no mathematical expressions. The arduino uses the c programming language.


Would love your thoughts, please comment.x