Introduction: How to Use the Soil Hygrometer Module - Arduino Tutorial
In this tutorial we will use one soil hygrometer module to measure soil moisture of a pot.
The module can give us a digital signal when the soil need watering and this output can be adjusted by the potentiometer. Or it can give us an analog signal of current soil moisture!
In this tutorial we will use the analog signal output of this module and we will change it in percentage value. Finally we will print in serial monitor the current percentage value of soil moisture.
So, let's get started!
Step 1: What You Will Need
For this tutorial you will need:
- Arduino uno
- Breadboard
- Soil hygrometer module
- some breadboard cables
And some soil for testing
Step 2: The Circuit
The connections are pretty easy, see the above image with the breadboard circuit schematic.
Step 3: The Code
Here's the code, embedded using Codebender!
Try downloading the Codebender plugin and clicking on the "Run on Arduino" button to program your Arduino board. And that's it, you've programmed your Arduino with this sketch!
You can keep playing with that by clicking the "Edit" button and start making your own modifications to the code.
Step 4: Serial Monitor - Testing
Put the sensor in dry soil for testing. Press the connect button below to start the serial communication.
Now throw some water on the soil and observe how the value changes
Step 5: Well Done!
You have successfully completed one more "How to" tutorial and you learned how to use the saoil hygrometer module with Arduino.
Check this Arduino Automatic Watering System
I hope you liked this, let me know in the comments!
7 Comments
Question 1 year ago
why doesnt it work
Question 4 years ago
Out of curiosity, why did you constrain the hygrometer's analog value to a set of numbers and then map it to yet another set of numbers? Why not just deal with the analog value directly?
6 years ago
Hello again I'm trying to add a pump to this project operated via a relay on pin A1
but I'm having problems with the value being stuck at 100% after adding the lines
to switch the relay
/* Arduino Tutorial - How to use a Soil Hygrometer Module
Dev: Michalis Vasilakis // Date: 18/05/2016 // www.ardumotive.com */
//Constants
const int hygrometer = A0; //Hygrometer sensor analog pin output at pin A0 of Arduino
int pump = A1; //pump on off
//Variables
int value;
void setup(){
pinMode (pump, OUTPUT); //SETS PIN A1 as output
Serial.begin(9600);
}
void loop(){
// When the plant is watered well the sensor will read a value 380~400, I will keep the 400
// value but if you want you can change it below.
value = analogRead(hygrometer); //Read analog value
value = constrain(value,300,160); //Keep the ranges!
value = map(value,300,160,100,0); //Map value : 400 will be 100 and 1023 will be 0
// if (value = 0) digitalWrite(pump, HIGH); // sets the pump on
// if (value = 100) digitalWrite(pump, LOW); // sets the pump off
Serial.print("Soil humidity: ");
Serial.print(value);
Serial.println("%");
delay(2000); //Read every 2 sec.
}
Reply 6 years ago
found this to work hope it helps others
/* Arduino Tutorial - How to use a Soil Hygrometer Module
Dev: Michalis Vasilakis // Date: 18/05/2016 // www.ardumotive.com */
//Constants
const int hygrometer = A0; //Hygrometer sensor analog pin output at pin A0 of Arduino
int pump = A1; //pump on off
//Variables
int value;
int pumpvalue;
void setup(){
pinMode (pump, OUTPUT); //SETS PIN A1 as output
Serial.begin(9600);
}
void loop(){
// When the plant is watered well the sensor will read a value 380~400, I will keep the 400
// value but if you want you can change it below.
value = analogRead(hygrometer); //Read analog value
value = constrain(value,300,160); //Keep the ranges!
value = map(value,300,160,100,0); //Map value : 400 will be 100 and 1023 will be 0
pumpvalue = value;
if (pumpvalue < 1)
{
digitalWrite(pump, LOW); // sets the pump off
}
else if (pumpvalue >= 99)
{
digitalWrite(pump, HIGH); // sets the pump on
}
Serial.print("Soil humidity: ");
Serial.print(value);
Serial.println("%");
Serial.println ("pumpvalue:");
Serial.println(pumpvalue);
delay(2000); //Read every 2 sec.
}
6 years ago
hello I'm a noob and I'm having problems with errors
(sketch file) [arduino-tutorial] Soil hygrometer module.ino:25:17:error: expected expression
Serial.println(%);
^
(sketch file) [arduino-tutorial] Soil hygrometer module.ino:25:18:error: expected expression
Serial.println(%);
^
2 errors generated.
I'm using a arduino uno connected via usb
Regards
Stevie p
Reply 6 years ago
That's because it doesn't recogenize the % as a variable. Format it between quotation marks like this:
Serial.println("%");
Reply 6 years ago
thank you