Monitor Soil Moisture Sensor Data with Nodemcu on Thingspeak
interface Resistive Soil Moisture Sensor with NodeMCU ESP8266 & OLED Display. Monitor Soil Moisture Data on Thingspeak Server. Source Code Circuit & Library
- Suitable forB.Tech/Diploma ESP8266/IoT students
- Build time1-2 weeks
- LevelBeginner
- Available atAjvika Labs, Kakinada
About this project
In this project, we are going to interface Resistive Soil Moisture Sensor with NodeMCU ESP8266 & OLED Display & Monitor Soil Moisture Data on Thingspeak Server.
Overview
In this post, we are going to interface a Resistive Soil moisture sensor FC-28 with Nodemcu ESP8266 Board & 0.96″ OLED Display. This sensor measures the volumetric content of water inside the soil and gives us the moisture level as output. The sensor is equipped with both analog and digital output, so it can be used in both analog and digital modes. Here we will use the sensor in Analog mode and measure the soil moisture in percentage.
The measured soil moisture can be sent to any IoT cloud platform. In this case, we will use Thingspeak Server.
Thinspeak
server is an open data platform and API for the Internet of Things that enables you to collect, store, analyze, visualize, and act on data from sensors. The soil moisture data from Soil Moisture Sensor can be monitored online from any part of the world.
If you want to learn about another type of soil moisture sensor, i.e Capacitive Soil Moisture Sensor v1.2, you can check here:
Capacitive Soil Moisture Sensor
Bill of Materials
Following are the components required for making this project. All the components can be purchased from Amazon. The components purchased link is given below.
S.N.
Components Name
Quantity
Purchase Links
NodeMCU ESP8266
Amazon
AliExpress
0.96" I2C OLED Display
Amazon
AliExpress
Connecting Wires
Amazon
AliExpress
Breadboard
Amazon
AliExpress
Soil Moisture Sensor
Amazon
AliExpress
Resistive Soil Moisture Sensor
The soil Moisture sensor FC-28 consists of two probes that are used to measure the volumetric content of water. The sensor works between the input voltage range of 3.3V to 5V. The output voltage given by it is 0 – 4.2V. The output signal appears both in analog form and in digital form.
The soil Moisture sensor FC-28 has four pins
VCC
: For power
A0
: Analog output
D0
: Digital output
GND
: Ground
The Module also contains a potentiometer that will set the threshold value and then this threshold value will be compared by the LM393 comparator. The output LED will light up and down according to this threshold value.
Working of Resistive Soil Moisture Sensor
The soil moisture sensor consists of two probes that are used to measure the volumetric content of water. The two probes allow the current to pass through the soil and then it gets the resistance value to measure the moisture value.
When there is more water, the soil will conduct more electricity which means that there will be less resistance. Therefore, the moisture level will be higher. Dry soil conducts electricity poorly, so when there will be less water, then the soil will conduct less electricity which means that there will be more resistance. Therefore, the moisture level will be lower.
Interfacing Resistive Soil Moisture Sensor with Nodemcu & OLED Display
Here is a circuit diagram for interfacing Resistive Soil Moisture Sensor with Nodemcu ESP8266 Board. The connection is fairly simple.
We are using the soil moisture sensor in analog mode. So, connect the analog output pin to A0 of Nodemcu. Similarly, OLED Display is an I2C Module. So, connect its SDA SCL pin to D2 & D1 of Nodemcu. Both the OLED & Soil Moisture Sensor work at 3.3V. So connect their VCC pin to 3.3V of Nodemcu.
Monitoring Soil Moisture Sensor Data with Nodemcu on Thingspeak
In order to Monitor the Sensor Data on Thingspeak Server, you first need to Setup the Thingspeak. To setup the Thingspeak Server, visit
https://thingspeak.com/
. Create an account or simply sign in if you created the account earlier. Then create a new channel.
Copy the API key and use it in the code below.
Source Code/Program
Find the source code/program below for the Resistive Soil Moisture Sensor with OLED Display. You need to add two libraries for the code compilation.
1. Adafruit_SSD1306 :
https://github.com/adafruit/Adafruit_SSD1306
2. Adafruit_GFX :
https://github.com/adafruit/Adafruit-GFX-Library
Make sure to change the Wifi SSID & Password. Also, change the API key here.
#include <ESP8266WiFi.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306
display
(
SCREEN_WIDTH
SCREEN_HEIGHT
&
Wire
OLED_RESET
)
;
String
apiKey
=
"14K8UL2QEK8BTHN6"
;
// Enter your Write API key from ThingSpeak
const
char
*
ssid
=
"Alexahome"
;
// replace with your wifi ssid and wpa2 key
const
char
*
pass
=
"12345678"
;
const
char
*
server
=
"api.thingspeak.com"
;
const
int
sensor_pin
=
A0
;
// Connect Soil moisture analog sensor pin to A0 of NodeMCU
WiFiClient
client
;
void
setup
(
)
{
Serial
begin
(
115200
)
;
display
begin
(
SSD1306_SWITCHCAPVCC
0x3C
)
;
//initialize with the I2C addr 0x3C (128x64)
display
clearDisplay
(
)
;
delay
(
)
;
Serial
println
(
"Connecting to "
)
;
Serial
println
(
ssid
)
;
display
clearDisplay
(
)
;
display
setCursor
(
)
;
display
setTextSize
(
)
;
display
setTextColor
(
WHITE
)
;
display
println
(
"Connecting to "
)
;
display
setTextSize
(
)
;
display
(
ssid
)
;
display
display
(
)
;
WiFi
begin
(
ssid
pass
)
;
while
(
WiFi
status
(
)
!=
WL_CONNECTED
)
{
delay
(
)
;
Serial
(
"."
)
;
}
Serial
println
(
""
)
;
Serial
println
(
"WiFi connected"
)
;
display
clearDisplay
(
)
;
display
setCursor
(
)
;
display
setTextSize
(
)
;
display
setTextColor
(
WHITE
)
;
display
(
"WiFi connected"
)
;
display
display
(
)
;
delay
(
4000
)
;
}
void
loop
(
)
{
int
moisture_percentage
;
moisture_percentage
=
(
100.00
(
(
analogRead
(
sensor_pin
)
/
1023.00
)
*
100.00
)
)
;
Serial
(
"Soil Moisture(in Percentage) = "
)
;
Serial
(
moisture_percentage
)
;
Serial
println
(
"%"
)
;
display
clearDisplay
(
)
;
display
setCursor
(
)
;
//oled display
display
setTextSize
(
)
;
display
setTextColor
(
WHITE
)
;
display
println
(
"Soil Moisture Monitor"
)
;
display
setCursor
(
)
;
//oled display
display
setTextSize
(
)
;
display
setTextColor
(
WHITE
)
;
display
(
moisture_percentage
)
;
display
setTextSize
(
)
;
display
setTextColor
(
WHITE
)
;
display
println
(
" %"
)
;
display
display
(
)
;
if
(
client
connect
(
server
)
)
// "184.106.153.149" or api.thingspeak.com
{
String
postStr
=
apiKey
;
postStr
+=
"&field1="
;
postStr
+=
String
(
moisture_percentage
)
;
postStr
+=
"r\n"
;
client
(
"POST /update HTTP/1.1\n"
)
;
client
(
"Host: api.thingspeak.com\n"
)
;
client
(
"Connection: close\n"
)
;
client
(
"X-THINGSPEAKAPIKEY: "
+
apiKey
+
"\n"
)
;
client
(
"Content-Type: application/x-www-form-urlencoded\n"
)
;
client
(
"Content-Length: "
)
;
client
(
postStr
length
(
)
)
;
client
(
"\n\n"
)
;
client
(
postStr
)
;
Serial
println
(
"Data Send to Thingspeak"
)
;
}
client
stop
(
)
;
Serial
println
(
"Waiting..."
)
;
delay
(
2000
)
;
// thingspeak needs minimum 15 sec delay between updates.
}
Results & Observations
Once the code is uploaded you can open the serial monitor and see the following.
Now you can dip the soil moisture probe in mud and see the value on OLED Screen or Serial Monitor. The more wet the soil the more the soil moisture percentage. Drier the soil, less the soil moisture percentage.
Now you
Overview
In this post, we are going to interface a Resistive Soil moisture sensor FC-28 with Nodemcu ESP8266 Board & 0.96″ OLED Display. This sensor measures the volumetric content of water inside the soil and gives us the moisture level as output. The sensor is equipped with both analog and digital output, so it can be used in both analog and digital modes. Here we will use the sensor in Analog mode and measure the soil moisture in percentage.
The measured soil moisture can be sent to any IoT cloud platform. In this case, we will use Thingspeak Server.
Thinspeak
server is an open data platform and API for the Internet of Things that enables you to collect, store, analyze, visualize, and act on data from sensors. The soil moisture data from Soil Moisture Sensor can be monitored online from any part of the world.
If you want to learn about another type of soil moisture sensor, i.e Capacitive Soil Moisture Sensor v1.2, you can check here:
Capacitive Soil Moisture Sensor
Bill of Materials
Following are the components required for making this project. All the components can be purchased from Amazon. The components purchased link is given below.
S.N.
Components Name
Quantity
Purchase Links
NodeMCU ESP8266
Amazon
AliExpress
0.96" I2C OLED Display
Amazon
AliExpress
Connecting Wires
Amazon
AliExpress
Breadboard
Amazon
AliExpress
Soil Moisture Sensor
Amazon
AliExpress
Resistive Soil Moisture Sensor
The soil Moisture sensor FC-28 consists of two probes that are used to measure the volumetric content of water. The sensor works between the input voltage range of 3.3V to 5V. The output voltage given by it is 0 – 4.2V. The output signal appears both in analog form and in digital form.
The soil Moisture sensor FC-28 has four pins
VCC
: For power
A0
: Analog output
D0
: Digital output
GND
: Ground
The Module also contains a potentiometer that will set the threshold value and then this threshold value will be compared by the LM393 comparator. The output LED will light up and down according to this threshold value.
Working of Resistive Soil Moisture Sensor
The soil moisture sensor consists of two probes that are used to measure the volumetric content of water. The two probes allow the current to pass through the soil and then it gets the resistance value to measure the moisture value.
When there is more water, the soil will conduct more electricity which means that there will be less resistance. Therefore, the moisture level will be higher. Dry soil conducts electricity poorly, so when there will be less water, then the soil will conduct less electricity which means that there will be more resistance. Therefore, the moisture level will be lower.
Interfacing Resistive Soil Moisture Sensor with Nodemcu & OLED Display
Here is a circuit diagram for interfacing Resistive Soil Moisture Sensor with Nodemcu ESP8266 Board. The connection is fairly simple.
We are using the soil moisture sensor in analog mode. So, connect the analog output pin to A0 of Nodemcu. Similarly, OLED Display is an I2C Module. So, connect its SDA SCL pin to D2 & D1 of Nodemcu. Both the OLED & Soil Moisture Sensor work at 3.3V. So connect their VCC pin to 3.3V of Nodemcu.
Monitoring Soil Moisture Sensor Data with Nodemcu on Thingspeak
In order to Monitor the Sensor Data on Thingspeak Server, you first need to Setup the Thingspeak. To setup the Thingspeak Server, visit
https://thingspeak.com/
. Create an account or simply sign in if you created the account earlier. Then create a new channel.
Copy the API key and use it in the code below.
Source Code/Program
Find the source code/program below for the Resistive Soil Moisture Sensor with OLED Display. You need to add two libraries for the code compilation.
1. Adafruit_SSD1306 :
https://github.com/adafruit/Adafruit_SSD1306
2. Adafruit_GFX :
https://github.com/adafruit/Adafruit-GFX-Library
Make sure to change the Wifi SSID & Password. Also, change the API key here.
#include <ESP8266WiFi.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306
display
(
SCREEN_WIDTH
SCREEN_HEIGHT
&
Wire
OLED_RESET
)
;
String
apiKey
=
"14K8UL2QEK8BTHN6"
;
// Enter your Write API key from ThingSpeak
const
char
*
ssid
=
"Alexahome"
;
// replace with your wifi ssid and wpa2 key
const
char
*
pass
=
"12345678"
;
const
char
*
server
=
"api.thingspeak.com"
;
const
int
sensor_pin
=
A0
;
// Connect Soil moisture analog sensor pin to A0 of NodeMCU
WiFiClient
client
;
void
setup
(
)
{
Serial
begin
(
115200
)
;
display
begin
(
SSD1306_SWITCHCAPVCC
0x3C
)
;
//initialize with the I2C addr 0x3C (128x64)
display
clearDisplay
(
)
;
delay
(
)
;
Serial
println
(
"Connecting to "
)
;
Serial
println
(
ssid
)
;
display
clearDisplay
(
)
;
display
setCursor
(
)
;
display
setTextSize
(
)
;
display
setTextColor
(
WHITE
)
;
display
println
(
"Connecting to "
)
;
display
setTextSize
(
)
;
display
(
ssid
)
;
display
display
(
)
;
WiFi
begin
(
ssid
pass
)
;
while
(
WiFi
status
(
)
!=
WL_CONNECTED
)
{
delay
(
)
;
Serial
(
"."
)
;
}
Serial
println
(
""
)
;
Serial
println
(
"WiFi connected"
)
;
display
clearDisplay
(
)
;
display
setCursor
(
)
;
display
setTextSize
(
)
;
display
setTextColor
(
WHITE
)
;
display
(
"WiFi connected"
)
;
display
display
(
)
;
delay
(
4000
)
;
}
void
loop
(
)
{
int
moisture_percentage
;
moisture_percentage
=
(
100.00
(
(
analogRead
(
sensor_pin
)
/
1023.00
)
*
100.00
)
)
;
Serial
(
"Soil Moisture(in Percentage) = "
)
;
Serial
(
moisture_percentage
)
;
Serial
println
(
"%"
)
;
display
clearDisplay
(
)
;
display
setCursor
(
)
;
//oled display
display
setTextSize
(
)
;
display
setTextColor
(
WHITE
)
;
display
println
(
"Soil Moisture Monitor"
)
;
display
setCursor
(
)
;
//oled display
display
setTextSize
(
)
;
display
setTextColor
(
WHITE
)
;
display
(
moisture_percentage
)
;
display
setTextSize
(
)
;
display
setTextColor
(
WHITE
)
;
display
println
(
" %"
)
;
display
display
(
)
;
if
(
client
connect
(
server
)
)
// "184.106.153.149" or api.thingspeak.com
{
String
postStr
=
apiKey
;
postStr
+=
"&field1="
;
postStr
+=
String
(
moisture_percentage
)
;
postStr
+=
"r\n"
;
client
(
"POST /update HTTP/1.1\n"
)
;
client
(
"Host: api.thingspeak.com\n"
)
;
client
(
"Connection: close\n"
)
;
client
(
"X-THINGSPEAKAPIKEY: "
+
apiKey
+
"\n"
)
;
client
(
"Content-Type: application/x-www-form-urlencoded\n"
)
;
client
(
"Content-Length: "
)
;
client
(
postStr
length
(
)
)
;
client
(
"\n\n"
)
;
client
(
postStr
)
;
Serial
println
(
"Data Send to Thingspeak"
)
;
}
client
stop
(
)
;
Serial
println
(
"Waiting..."
)
;
delay
(
2000
)
;
// thingspeak needs minimum 15 sec delay between updates.
}
Results & Observations
Once the code is uploaded you can open the serial monitor and see the following.
Now you can dip the soil moisture probe in mud and see the value on OLED Screen or Serial Monitor. The more wet the soil the more the soil moisture percentage. Drier the soil, less the soil moisture percentage.
Now you
Technologies used
Hardware components
- ESP8266
- Arduino
- SSD1306
- OLED
- Soil Moisture
Software & tools
- ThingSpeak
What you get
- Working project / hardware kit, tested before delivery
- Complete source code with explanation
- Project demo and guidance for your viva
- Project report, PPT and IEEE paper support (on request)
Delivery & Payment
Delivery takes a minimum of two weeks from the date your inquiry is confirmed.
Payment is in two parts:
• 50% advance to start the project
• Remaining 50% before delivery
Note:
• Documentation and PPT are not included by default
• If you need documentation/PPT, it can be arranged for extra time and cost
We'll confirm the exact timeline and cost with you after reviewing your requirements.