Sensor is composed of two legs. Sensor works on 3.3 volt to 5 volt power supply. On each leg a conducting material is pasted, normally nickel or copper. An electric power is supplied across legs. One leg is connected to + of power supply and other leg is connected to – of supply. Both the legs are set a part from each other. In normal condition no charge flows through the legs because the circuit is open. As soon as we insert the legs in ground the moisture in ground lowers the resistance between legs and depending on the moisture level the voltage flows between the completed circuit. If moisture composition is high resistance between legs will be low and more voltage comes across legs. If moisture level is low little voltage will flow across the legs.
Another module supplied with the legs is voltage control circuit. It houses a variable resistance and lm393 op amp on it.
- A0 – Analog output pin. Outputs analog voltage which corresponds to the moisture level of soil or about water rain detection. For which purpose sensor is use.
- D0 -Output digital signal. We set threshold value by variable resistor present on the sensor control board. Now when the moisture level increased or decreased the threshold value digital pin becomes high.
I am going to use both the output pins in the project. Normally many tutorials on the internet use only one output pin and left the other vacant. From A0 i am going to measure the moisture level in soil. A threshold value is set and D0 is used to generate alert when ever the sensor value reaches the threshold.
Project circuit diagram
const char* ssid = “Your SSID”;
const char* password = “Your Wifi Password”;
Just make the above circuit and download the code in nodemcu. After downloading the code open the serial monitor from arduino ide at 115200 bps baud rate. You will see the nodemcu is connecting to your router, starting its server and after server initialization it will display and IP on the screen. This address or IP is the page on which nodemccu is displaying soil moisture level status. The IP will look some thing like this. One has to enter this IP in his/her mobile, desktop, laptop or notebook browser to see the garden soil moisture status.
Soil sensor copper and nickel conductance will vanish soon approximately in 3 months. Every thing in soil is eaten by the bacteria in soil or undergoes a chemical reaction with soil content. Same happens with the soil sensor legs. Their loose their conductance very easily and in few months. You might need to replace the sensor after every 3 months. Another limitation is that user needs to refresh the page(Press the update moisture level button) every time he needs to see the updated value. Page can be refreshed automatically by using node js instead of HTML relaod.
One can extend the above project by activating a water valve when ever the moisture level of soil is low. This way one can automatically water his plants in garden. The only thing that needs to be modified is driving a relay with nodemcu to which you can connect a valve. A demo project of interfacing and controlling relay over WiFi with nodemcu is below. You use the code of relay project with this tutorial and can build a smart garden project.
Filed Under: Electronic Projects, ESP8266, Microcontroller Projects