Interfacing NodeMCU with soil moisture sensor

Soil is a mixture of organic matter, minerals, gases, liquids, and organisms that together support life. Also, it has a moisture level in it that reflects the health of the soil as well as the plants planted on it that needs to take care. So to know the moisture level in the soil is an advantage to treat soil well as per the conditions.

In this blog, you will learn about such a sensor that will help you to check the moisture level in the soil. The sensor that we will use in this blog is a soil moisture sensor. Now let’s begin and start by interfacing the soil moisture sensor with NodeMCU. Here is the pin diagram of the soil moisture sensor :

Image result for soil moisture sensor pinout

Now you can see in the pin diagram above that we are using a module with this sensor to get its value in both forms (digital as well as analog) so as to use it appropriately. Now let’s see how do we interface the soil moisture sensor with NodeMCU so as to check the moisture level in the soil to treat soil well. Here is the interfacing circuit of NodeMCU with soil moisture sensor :

Image result for interfacing nodemcu with soil moisture sensor

So in the circuit above you can see we have made the connection in which Vcc and ground of soil moisture sensor are connected to 3v and ground of NodeMCU respectively. And we are also connecting the AO pin of the sensor to A0 of NodeMCU to get the precise reading of the sensor so as to get the best result from the sensor and to display it on the serial monitor. Now we are done with the hardware interfacing of NodeMCU with soil moisture sensor. So now let’s move to the next step to write a program to read the values of soil moisture sensor and to display it on our computer screen in terms of percentage.

To start writing our code Open Arduino IDE and create a new sketch. Now write below code to read the values from the soil moisture sensor and to display it on the monitor screen. formula to convert ADC value read from soil moisture sensor to percentage is :

Moisture level in percentage(%) = 100-((ADC value/1023)*100)


#define soil A0

void setup() {

    pinMode (soil, INPUT);

void loop() {

    double Moisture = 100-((analogRead(soil)/1023.0)*100);
    Serial.print(“Moisture level in percentage(%): “);

Now you are done with the coding part. Let’s save the program and upload it to Arduino to see the humidity level on the serial monitor. After the code is uploaded to Arduino then open the serial monitor to see the results like it is shown below.

You can also check the video tutorial for the same to get better clarification about the topic.

This was the complete interfacing of NodeMCU with a soil moisture sensor. I hope I was able to explain you all the things clearly but still if you are having any query related to the topic then do let me know below in the comment section and also share your valuable feedback to help me provide you the best tutorial.

2 thoughts on “Interfacing NodeMCU with soil moisture sensor”

Leave a Reply

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