Microcontroller Tutorials

Arduino, Raspberry Pi, PIC, Beaglebone Resources

WiFi Soil Moisture Sensor with Arduino Program

Plants need enough water to survive. But what if you forgot to water the plants? This multi-part tutorial aims to provide a simple soil moisture sensor that reminds you, via WiFi, that your flora needs a shower.

Soil Moisture Sensor

The soil moisture sensor for this project is an inexpensive sensor that reads the resistance of the soil.

Soil moisture is inversely proportional to its resistance, i.e., the higher the water content in the soil, the lower its resistance. The sensor is designed as an electrode whose resistance varies with both the moisture and how deep it is plunged into the soil.

The type of soil and temperature are other factors that determine soil moisture. Thus, reading soil moisture through this sensor might not be enough for more complex applications or scientific researches. However, for our intended purpose -- which is to simply notify the user if the plant needs watering -- this sensor fits the bill.

The sensor comes with a LM393 module that helps give out a digital or an analog signal. If the soil moisture reaches a value (adjustable through the potentiometer on the module), the digital pin (D0) goes high and the D0-LED on the module turns on. On the other hand, the analog pin (A0) gives a voltage proportional to the soil moisture. The higher the soil moisture, the lower this voltage goes.

 

Sending  Sensor Values through WiFi

For a user to be able to read the soil moisture through WiFi, a microcontroller with wireless network capabilities is required. For this project, I will be using the ESP8266 microcontroller, particularly the NodeMCU V2.0 board.

The soil moisture sensor connects to the NodeMCU like this:

Soil moisture sensor to ESP8266

Next, load the sketch below to the NodeMCU. Modify lines 6 and 7 according to your WiFi SSID and password. Make sure your NodeMCU can be programmed with the Arduino IDE.

Upload the sketch and if successful, open serial monitor (make sure baud rate is set to 115200!). The serial monitor displays the IP address of the NodeMCU.

Using your preferred browser, visit that IP address. The soil moisture value is now on the web page!

The disadvantage of the given sketch is that you need to refresh the page to get updates. You can check out my AJAX tutorial for dynamically changing sensor values on a web page. Also, what does those numbers mean? We'll make our project better in the next part of this tutorial!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.