loading

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!

<p>Hello again I'm trying to add a pump to this project operated via a relay on pin A1</p><p>but I'm having problems with the value being stuck at 100% after adding the lines</p><p>to switch the relay</p><p>/* Arduino Tutorial - How to use a Soil Hygrometer Module</p><p>Dev: Michalis Vasilakis // Date: 18/05/2016 // www.ardumotive.com */</p><p>//Constants</p><p>const int hygrometer = A0; //Hygrometer sensor analog pin output at pin A0 of Arduino</p><p>int pump = A1; //pump on off</p><p>//Variables</p><p>int value;</p><p>void setup(){</p><p>pinMode (pump, OUTPUT); //SETS PIN A1 as output</p><p>Serial.begin(9600);</p><p>}</p><p>void loop(){</p><p>// When the plant is watered well the sensor will read a value 380~400, I will keep the 400</p><p>// value but if you want you can change it below.</p><p>value = analogRead(hygrometer); //Read analog value</p><p>value = constrain(value,300,160); //Keep the ranges!</p><p>value = map(value,300,160,100,0); //Map value : 400 will be 100 and 1023 will be 0</p><p>// if (value = 0) digitalWrite(pump, HIGH); // sets the pump on</p><p>// if (value = 100) digitalWrite(pump, LOW); // sets the pump off</p><p>Serial.print(&quot;Soil humidity: &quot;);</p><p>Serial.print(value);</p><p>Serial.println(&quot;%&quot;);</p><p>delay(2000); //Read every 2 sec.</p><p>}</p>
<p>found this to work hope it helps others</p><p>/* Arduino Tutorial - How to use a Soil Hygrometer Module</p><p> Dev: Michalis Vasilakis // Date: 18/05/2016 // www.ardumotive.com */</p><p>//Constants </p><p>const int hygrometer = A0; //Hygrometer sensor analog pin output at pin A0 of Arduino</p><p>int pump = A1; //pump on off</p><p>//Variables </p><p>int value;</p><p>int pumpvalue;</p><p>void setup(){</p><p> pinMode (pump, OUTPUT); //SETS PIN A1 as output</p><p> Serial.begin(9600);</p><p>}</p><p>void loop(){</p><p> // When the plant is watered well the sensor will read a value 380~400, I will keep the 400 </p><p> // value but if you want you can change it below. </p><p>value = analogRead(hygrometer); //Read analog value </p><p>value = constrain(value,300,160); //Keep the ranges!</p><p>value = map(value,300,160,100,0); //Map value : 400 will be 100 and 1023 will be 0</p><p>pumpvalue = value;</p><p>if (pumpvalue &lt; 1)</p><p>{</p><p>digitalWrite(pump, LOW); // sets the pump off</p><p>}</p><p>else if (pumpvalue &gt;= 99)</p><p>{</p><p>digitalWrite(pump, HIGH); // sets the pump on</p><p>}</p><p> Serial.print(&quot;Soil humidity: &quot;);</p><p> Serial.print(value);</p><p> Serial.println(&quot;%&quot;);</p><p> Serial.println (&quot;pumpvalue:&quot;);</p><p> Serial.println(pumpvalue);</p><p> delay(2000); //Read every 2 sec.</p><p>}</p>
<p>hello I'm a noob and I'm having problems with errors</p><p><strong>(sketch file) <a rel="nofollow">[arduino-tutorial] Soil hygrometer module.ino:25:17:</a> </strong><strong>error: </strong><strong>expected expression</strong><br> Serial.println(%);<br><strong> ^<br></strong><strong>(sketch file) <a rel="nofollow">[arduino-tutorial] Soil hygrometer module.ino:25:18:</a> </strong><strong>error: </strong><strong>expected expression</strong><br> Serial.println(%);<br><strong> ^<br></strong>2 errors generated.</p><p>I'm using a arduino uno connected via usb</p><p>Regards</p><p>Stevie p</p>
<p>That's because it doesn't recogenize the % as a variable. Format it between quotation marks like this:</p><p>Serial.println(&quot;%&quot;);</p>
<p>thank you</p>
<p>Thanks for this tutorial!</p>

About This Instructable

3,906views

47favorites

License:

Bio: Arduino Tutorials by Codebender.cc Team
More by codebender_cc:How to use a magnetic door switch / sensor with Arduino How to Measure LUX With Arduino How to Control an RGB LED Strip - Arduino Tutorial 
Add instructable to: