Arduino Hygrometer or humidity sensor

Recently I’ve acquired a hygrometer – humidy – sensor for a project I’m working on . I’ve bought it from .

To really know when to water the garden, tests needed to be made.

I’ve started with 3 cups fill with dirt – all equal with the same type of soil – from the garden I’m going to water


Next, I pored water in two of them – one half of water and the other until water is above the dirt

Test cups


Connecting the sensor



The hygrometer itself only has 2 pins to connect to another sensor. The next sensor has 4 PINS – Vcc, GND, D0 (digital) and A0 (analog).

I’ve connected GND, VCC and Analog. Analog will give more exact values and digital.

After connecting the sensor, I start reading the values.

When the hygrometer is not inserted in any cup, the values returned are 1023 – this is the max value.

Dry soil


With the sensor inserted in the dry soil cup, the sensor returned values around 968. That will my control value – dry soil will return values around 968.

Soil with some water


After pouring water in the cup – not getting wet – I get values around 344 – This is the target value after watering the garden.

Wet soil


This is the worst case scenario – probably after it rains – never let the watering system to reach this state. Like this, the sensor  returns values around 270 !

After analyzing these results, I’m targeting for values between 500 and 300 !

Arduino sketch

// define humidity variable to hold the final value
int humidity = 0;
void setup() {
void loop() {
 // read soil moisture from sensor
 int sensorValue = analogRead(A0);
 /* constraint function will limit the values we get so we can work better with map
 * since I only need values in the bottom limit of 300, will make it the outer limit and 1023 the other limit
 sensorValue = constrain (sensorValue, 300,1023);
 // print the values returned by the sensor
 // create a map with the values
 // You can think we have the 100% to 300 and 0 % to 1023 wrong, but no !
 // 300 - or 100 % - is the target value for moisture value in the soil
 // 0% of humidity - or moisture - is when the soil is dry
 humidity = map (sensorValue, 300, 1023, 100, 0);
 Serial.print (humidity);
 Serial.println ("%");
 delay(1000); //collecting values between seconds

More information about Constrain and Map in the Arduino playgound .