Moisture Meter for Plants using SIM7600G-H 4G LTE, ESP32, and Blynk, IoT Project
Table of Contents
Moisture Meter for Plants:
Moisture Meter for Plants using SIM7600G-H 4G LTE, ESP32, and Blynk, IoT Project- In today’s article, you will learn how to make an IoT based Soil Moisture Meter for Plants using a capacitive soil moisture sensor, SIM7600G-H 4G LTE Module, ESP32 WiFi + Bluetooth Module, a Relay module, and Blynk application.
If you have read my previous two articles on the SIM7600G-H then I am sure you guys would already have an idea of how powerful the Lilygo T-SIM7600G-H 4G LTE GSM module is.
SIM7600G-H Getting Started article
SIM7600G-H based GPS tracking System
Because, in previous videos and articles, I practically demonstrated how to control 220Vac bulbs and how to generate feedback messages each time a bulb is turned ON or turned OFF. Along with this, I also monitored a sensor “a potentiometer” through a text message via a simple request command.
After that, I used the SIM7600G-H 4G LTE module as a Car GPS Tracker. I would simply send a text message with the location command, and then the ESP32 would send me a Google Maps URL link using the SIM7600G-H module, including the longitude and latitude values. By clicking on the Google Maps link, I was able to track the location of my car.
The GPS is very accurate, and the interesting thing is that it can connect with GPS satellites even from inside a room. So far, I am fully satisfied with all the tests I have conducted on this module.
As you know SIM7600G-H is a 4G LTE module. So, using this module you can provide internet connectivity to the ESP32 module and this way you can remotely monitor your sensors and control your electrical loads in real-time from anywhere in the world and this is what we are going to cover in this article.
For the practical demonstration, I have made this Soil Moisture Meter for Plants using the Capacitive Soil Moisture Sensor, SIM7600G-H 4G LTE Module, ESP32 WiFi + Bluetooth, this IoT development board already has an ESP32, one-channel relay module, and Blynk application.
You can power up this project using a solar panel, you can also use a lithium Ion Battery exactly the same way as demonstrated in my Car GPS Tracking system. You can also use a 5V power supply just like me; I used my designed 5V and 3A power supply.
Anyway, for the initial experiments, you can also your laptop to power up this entire project.
Product Links:
Product | Source | Source |
LILYGO® SIM7600G-H | Official product page | |
SIM7600G-H | Amazon | AliExpress |
Capacitive Soil Moisture Sensor | Amazon | AliExpress |
5V SPDT relay | Amazon | AliExpress |
5V Solid-State Relay | Amazon | AliExpress |
*Disclosure: These are affiliate links. As an Amazon Associate I earn from qualifying purchases.
Capacitive Soil Moisture Sensor:
The Capacitive Soil Moisture Sensor Module determines the amount of soil moisture by measuring changes in capacitance to determine the water content of soil. This can be used in an automatic plant watering system or to signal an alert of some type when a plant needs watering.
KEY FEATURES OF CAPACITIVE SOIL MOISTURE SENSOR MODULE:
- Analog output of moisture content
- More corrosion resistant than resistive type of sensor
- 3 or 5V operation. Low power so may be driven from digital pin on MCU
This soil moisture sensor module uses capacitance rather than resistance to determine the water content of soil. The main down-side to the common fork type resistance sensor is that the probes inserted into the soil must be conductive bare metal and the small electrical current that flows between them results in corrosion of the probes through electrolysis over time.
The capacitive probe improves that situation because the sensor metal inserted into the soil can be covered in solder resist to minimize corrosion and electrical current is not flowing through the soil to induce electrolysis. The main weakness in the lifespan of the probe is the uncoated cut sides of the PCB which can absorb moisture over time as well as the exposed electronics at the top of the probe if they get splashed by water. The customer can add further protective coating such as clear fingernail polish or similar coating if desired without seriously affecting the performance of the probe.
Theory of Operation
The module uses a TL555I CMOS timer to create a 1.5MHz clock. The TL555I is similar to the ubiquitous NE555 but is newer CMOS technology with a higher frequency capability and other improvements.
A peak voltage detector converts the waveform from the TL555I into a DC voltage that can be read by the ADC input of a microcontroller.
When the probe is exposed to moisture, it affects the capacitance of the circuit which in turn affects the peak amplitude of the signal and therefore the DC voltage output that is being monitored by the MCU. Higher moisture = lower DC voltage output.
Moisture Meter for Plants Wiring:
The wiring is very simple. Connect the VCC and GND wires of the Capacitive Soil Moisture sensor to the ESP32 3.3V and GND pins. Connect the output signal wire to the ESP32 GPIO 15.
Connect the VCC and GND of the 5V Relay module to the vBus and GND. Connect the relay input to the ESP32 GPIO 12.
The SIM7600G-H 4G LTE module and the ESP32 WiFi + Bluetooth Module are already wired up for you. I have explained this in the getting started video and article.
if you want to make your own 5V and 3A power supply then you can read my article on the 5V and 3A power supply. Now, let’s start with the Blynk Web Dashboard setup.
Blynk Web Dashboard Setup:
- While you are logged-in into your Blynk account.
- Click on the New Template.
- Write the Template Name.
- While ESP32 is selected as the Hardware type.
- Select the connection type as GSM.
After this, all the steps are exactly the same. The only difference this time is that we selected GSM instead of WiFi in the connection type. Anyway, next click on the Datastreams.
Then click on the New Datastream and select the Virtual Pin
Then enter the required credentials and click on the create button.
Then again click on the New Datastream
Then enter the required credentials for relay virtual pin
Then click on the web dashboard and double click on the switch to add it in the dashboard
Click on the switch setting and in the Datastream select the Relay and click on the save button
Double click on the gauge it will be added on the web dashboard and click on the setting
Now select the soil moisture and click on the save button
The switch and gauge are added to the Web Dashboard
Now click on the devices
Now click on new device and click on From template
Now select the template “Soil Moisture Monitoring”
After selecting the template click on the create button
Then copy the credentials
Paste these credentials in the code
Moisture Meter for Plants, ESP32 Programming:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
#define BLYNK_TEMPLATE_ID "TMPL6q6zgM6Oz" #define BLYNK_TEMPLATE_NAME "Soil Moisture Monitoring" #define BLYNK_AUTH_TOKEN "TXS49bavc5F4vLY7KfnseDlCe1w5K807" #define RXD2 26 #define TXD2 27 #define powerPin 4 // Select your modem: #define TINY_GSM_MODEM_SIM7600 int Relay = 12; int moisturesensor = 15; // Default heartbeat interval for GSM is 60 // If you want override this value, uncomment and set this option: //#define BLYNK_HEARTBEAT 30 #include <BlynkSimpleTinyGSM.h> #include <Arduino.h> #include <Wire.h> int rx = -1; #define SerialAT Serial1 String rxString; int _timeout; String _buffer; BlynkTimer timer; // You should get Auth Token in the Blynk App. // Go to the Project Settings (nut icon). char auth[] = BLYNK_AUTH_TOKEN; // Your GPRS credentials // Leave empty, if missing user or pass char apn[] = "ufone.pinternet"; char user[] = ""; char pass[] = ""; int moisturevalue = 0; const int AirValue = 3280; const int WaterValue = 1275; bool reply = false; TinyGsm modem(SerialAT); void setup() { pinMode(powerPin, OUTPUT); digitalWrite(powerPin, HIGH); delay(1000); digitalWrite(powerPin, LOW); delay(1000); Serial.begin(115200); delay(100); SerialAT.begin(115200, SERIAL_8N1, RXD2, TXD2); pinMode(moisturesensor,INPUT); pinMode(Relay,OUTPUT); delay(2000); Serial.println("Modem Reset, Please Wait"); SerialAT.println("AT+CRESET"); delay(1000); SerialAT.println("AT+CRESET"); delay(2000); SerialAT.flush(); Serial.println("Echo Off"); SerialAT.println("ATE0"); delay(1000); SerialAT.println("ATE0"); rxString = SerialAT.readString(); Serial.print("Got: "); Serial.println(rxString); rx = rxString.indexOf("OK"); if (rx != -1) Serial.println("Modem Ready"); delay(1000); Serial.println("SIM card check"); SerialAT.println("AT+CPIN?"); rxString = SerialAT.readString(); Serial.print("Got: "); Serial.println(rxString); rx = rxString.indexOf("+CPIN: READY"); if (rx != -1) Serial.println("SIM Card Ready"); delay(1000); String name = modem.getModemName(); delay(500); Serial.println("Modem Name: " + name); Blynk.begin(auth, modem, apn, user, pass); // Setup a function to be called every second //timer.setInterval(1000L, sendSensor); } void loop() { Blynk.run(); timer.run(); moisturevalue = analogRead(moisturesensor); Serial.println(moisturevalue); int soilpercent=map(moisturevalue, AirValue, WaterValue, 0, 100); if ( soilpercent < 0) { soilpercent = 0; } Serial.println(soilpercent); Blynk.virtualWrite(V0,soilpercent); } BLYNK_WRITE(V1) // From Blynk to the ESP32, to control a Relay { int pinValue = param.asInt(); digitalWrite(Relay , pinValue); } |
Don’t forget to change the GPRS Credentials.
If this is your first time using the ESP32 WiFi + Bluetooth module then you will also need to install the ESP32 board in the Arduino IDE. For this, you can read my Getting Started article on the ESP32 WiFi + Bluetooth Module.
Next, you will also need to install the entire Blynk library package. For this simply go to the Sketch Menu, then to Include Library, and click on the Manage Libraries. Type Blynk in the search box.
You can see I have also installed this library. It works with over 400 boards. Finally, you can upload the program, in my case I have already uploaded this program. Next, you can start with the Blynk IoT Application setup on your smartphone.
Blynk IoT App setup on Smartphone:
Open the blynk App on your smartphone and click on the soil moisture monitoring.
Then click on the setting button to enter to the developer mode
Now, simply add the widgets and assign the virtual variables or datastreams we created.
If you face any issues then you can watch video tutorial given at the end of this article.
Anyway, our application is also ready, now let’s start the practical demonstration.
Moisture Meter for Plants, Demonstration:
I have powered up the project using a 12V adaptor. I have connected this 12V adaptor to a 5V and 3A power supply which is then connected through a USB Type C cable to the ESP32 IoT development board. “I highly recommend, you should watch the video for practical demonstration”.
Right now, you can see it’s connected to the GSM network. In my area, the 4G network is fully functional; so, as soon as I power up this project, the SIM7600G-H immediately connects to the network. However, if the 4G network weren’t functional in my area, I could still use it because it’s also fully compatible with 3G and 2G networks.
For now, I have not connected any load to the relay, however, as you can see, there’s an LED that will turn ON or OFF when the relay is activated or deactivated. This relay can be used to control a water pump or any other device.
My Blynk application is also connected to the Internet. So, let’s add some water.
I can monitor the soil moisture in real-time, by the way, how much soil moisture should be maintained for which plants; I have already explained this in my previous soil moisture monitoring projects. So, with this soil moisture meter, now I can monitor the soil moisture and control the water pump from any part of the world. So, that’s all for you.