This is a simple tutorial on how to interface rainwater or soil moisture level sensor with nodemcu esp8266-12e WiFi module. Monitoring your garden's status via WiFi earns the title of smart garden design. We will monitor the composition of rainfall and soil moisture levels. The user can see the status of their garden now on their desktop or mobile phone. Simple and popular humidity level sensor is used in the project.
Water Moisture Level Sensor
|
The sensor consists of two legs. Sensor works with power supply from 3.3 volts to 5 volts. A conductive material, usually nickel or copper, is glued to each leg. An electrical energy is supplied through the legs. One leg is connected to + of the power supply and the other leg is connected to – of the supply. Both legs are separated from each other. Under normal conditions, no charge flows through the legs because the circuit is open. As soon as we insert the legs into the ground, the moisture in the ground decreases the resistance between the legs and depending on the moisture level voltage flows between the complete circuit. If the moisture composition is high, the resistance between the legs will be low and more voltage will pass through the legs. If the humidity level is low, little voltage will flow through the legs.
Another module provided with the legs is the voltage control circuit. It houses a variable resistance and an lm393 operational amplifier. |
It has four pins. Two power pins and two sensor output pins. The sensor output pins are
- A0 – Analog output pin. Outputs analog voltage that corresponds to soil moisture level or water rain detection. For what purpose is the sensor used.
- D0 -Digital output signal. We define the limit value by the variable resistor present on the sensor control board. Now when the humidity level increases or decreases, the digital pin threshold value becomes high.
I will use the two output pins in the project. Typically, many tutorials on the internet only use one output pin and leave the other empty. From A0 I will measure the soil moisture level. A threshold value is defined and D0 is used to generate alert whenever the sensor value reaches the threshold.
Project circuit diagram
The Nodemcu works on 3.3 volts and the soil moisture rainwater leak sensor also works on 3.3 to 5 volts. Therefore, we can power the same circuit using the same power source. The water leak sensor can also be powered with Nodemcu output power. Analog channel 0 of the nodemcu is connected to the A0 output of the rainwater sensor. Nodemcu digital pin #13 is connected to the D0 output of the soil moisture level sensor.
Rainwater Soil Moisture Sensor with Nodemcu WiFi Module
Coming to the code. Let's remember the functionality of the project. Whenever a user types a certain IP into their desktop or mobile browser, a page will be displayed that contains the status of the humidity level or rainwater detection. Both the nodemcu and the cell phone/desktop on which you want to see the status must be connected to the same WiFi network. If someone is on another network, the page will not be displayed. Nodemcu is working as a server. It is serving a web page, so the server and client must be on the same network to communicate correctly. First, enter the SSID and password of the network you want your nodemcu to be connected to.
const char* ssid = “Your SSID”;
const char* password = “Your Wifi password”;
Next, the analog channel and digital pins of the nodemcu are defined, which are used to read the output data from the rainwater sensor. In the configuration function the WiFi is turned on and an IP is requested to be assigned by the router to which we are connecting our nodemcu. When the full IP is assigned successfully, the nodemcu starts its server and displays the server address on the Arduino IDE's serial monitor. In the loop function I am waiting for the client's request when a request arrives I calculate the analog value, convert it to a percentage, check if the limit has been reached and pass this value to the page. Nodemcu sends the page back to the client and closes the connection.
In the code, the visible title and button are due to the html code present in the nodemcu arduino ide code.
The end result will be something like below
Nodemcu Water Rain and Soil Moisture Sensor over WiFi Monitoring
Whenever the “Update humidity level” button is pressed, the instantaneous sensor values will be displayed on the web page.
Limitations
The copper and nickel conductance of the soil sensor will disappear soon, approximately in 3 months. Everything in the soil is eaten by soil bacteria or undergoes a chemical reaction with the soil contents. The same goes for the ground sensor legs. They lose their conductance very easily and within a few months. It may be necessary to replace the sensor every 3 months. Another limitation is that the user needs to refresh the page (press the update humidity level button) every time they need to see the updated value. The page can be updated automatically using node js instead of related HTML.
Future work
You can extend the above project by activating a water valve whenever the soil moisture level is low. This way you can automatically water your garden plants. The only thing that needs to be modified is to drive a relay with nodemcu to which you can connect a valve. A demo project of interface and relay control via WiFi with nodemcu is below. You use the relay project code with this tutorial and can build a smart garden project.
Limitations
The copper and nickel conductance of the soil sensor will disappear soon, approximately in 3 months. Everything in the soil is eaten by soil bacteria or undergoes a chemical reaction with the soil contents. The same goes for the ground sensor legs. They lose their conductance very easily and within a few months. It may be necessary to replace the sensor every 3 months. Another limitation is that the user needs to refresh the page (press the update humidity level button) every time they need to see the updated value. The page can be updated automatically using node js instead of related HTML.
Future work
You can extend the above project by activating a water valve whenever the soil moisture level is low. This way you can automatically water your garden plants. The only thing that needs to be modified is to drive a relay with nodemcu to which you can connect a valve. A demo project of interface and relay control via WiFi with nodemcu is below. You use the relay project code with this tutorial and can build a smart garden project.
Download the project code. The folder contains the .ino file of the Arduino ide project. Please provide us with your feedback on the project. Write your queries and comments in the comments section below.
Code/Files