Table of Contents
Overview
In this quick tutorial you are going to learn how to connect the capacitive soil moisture sensor v1.2 with Arduino and get soil moisture percentage displayed on the 16X2 LCD display with I2C module. and also learn how to calibrate the capacitive moisture sensor to get the correct soil moisture percentage.
You can build an Automatic plant watering system with this project. If you are interested refer the below article link.
Before getting started lets learn in detail about the sensor, its advantages and how it works.
Capacitive Soil Moisture sensor v1.2 and its advantages:
As the name indicates capacitive moisture sensor is a sensor which senses the moisture in the soil, the moisture in the soil can be measured using two methods resistive and capacitive, This v1.2 sensor uses capacitive method instead the resistive method which was used in the previous versions of the sensor.
The above image shows an analog capacitive soil moisture sensor which measures the volumetric amount of moisture levels present in soil. unlike other moisture sensors which uses DC current with two metallic electrodes printed on the silicon board which cause the electroplating activity on one electrode and the metals corrode by damaging the sensor permanently with in one month. This capacitive one is the best moisture sensor which has the best build quality made of non-corrosive materials. With capacitive sensor it outputs analog signals and the metallic parts are not exposed to water which tends to long time run of the sensor.
This sensor module has an onboard voltage regulator which made it to work under voltages between 3.3 to 5.5V which makes it compatible with all the major microcontrollers available.
Pinout diagram:
The sensor has 3 pins GND, VCC and Aout.
Features & specifications of Capacitive moisture sensor v1.2
- Works from 3.3v to 5.5v
- Output analog Voltage: 0 ~ 3.0 VDC
- Supports 3-Pin Sensor interface
- Interface: PH2.0-3P
Working principle of Capacitive moisture sensor:
First let’s learn in a simple way, as we all know a capacitor consists of 3 pieces. A positive plate, a negative plate and the gap between the plates known as di-electric. there are different physical forms of capacitors but all have two metal plates and di-electric between them.
A capacitive moisture sensor works by measuring capacitance changes caused by the changes in the dielectric. It does not measure soil moisture directly (as pure water does not conduct electricity well), instead it measures the ions that are dissolved in the moisture. Capacitive measuring basically measures the dielectric that is formed by the soil and the water is the most important factor that affects the dielectric.
The capacitance of the sensor is measured with the help of a 555 timer based circuit that creates a voltage which is directly proportional to the capacitor inserted in the soil. We then measure this voltage by use of an Analog to Digital Converter which produces a value that we represent as percentage of soil moisture.
Capacitive Soil Moisture Sensor v1.2 Hardware Schematic
The above schematic image represents the onboard hardware schematic diagram of capacitive soil moisture sensor. where you can see a fixed frequency oscillator which is built using a 8 pin DIL8 555 timer IC (NE555) a square wave pulse generator. The square wave signal made out of 555 timer circuit is connected to the sensor which is capacitor in our case. As we know capacitors has a reactance (storing the extra unwanted energy on the plates and releases it when discharged with out dissipating as heat in the case of resistor) so a voltage divider is created by connecting a 10k ohm resistor from pin 3 to a capacitor.
The concept behind this is “higher the soil moisture in the sensor, the capacitance is higher on the sensor”. So when higher capacitance is observed on the sensor, the smaller the reactance to the square wave. which produces low voltage on signal line. This voltage is measured through the analog inputs on the microcontrollers and moisture levels in the soil are calculated.
Interfacing capacitive soil moisture sensor v1.2 with Arduino and display on serial monitor and LCD display module
After learning the working and principles of sensor above, now lets build the soil moisture meter by connecting the Arduino with Capacitive soil moisture sensor and LCD module with I2C or without I2C to display the soil moisture percentage.
Required components:
- Arduino UNO R3
- Capacitive moisture sensor v1.2
- 16X2 LCD module with I2C
- Few connecting wires
Circuit Diagram:
Connect all the required components with connecting wires according to the above schematic diagram. here we connected the signal pin AOUT from sensor to A0 of Arduino, VCC and GND of sensor is connected to 3.3v and GND of Arduino respectively. We connected the 16X2 LCD display module with Arduino through I2C communication as it uses only 4 wires. If you need to connect it with out I2c refer the below link.
Source code:
After connecting all the components upload the below code, also install the required libraries from this libraries link.
Required Libraries:
- Liquidcrystal_I2C
//#include <LiquidCrystal.h> unquote this for LCD display without I2c //LiquidCrystal lcd(12, 11, 5, 4, 3, 2); #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd (0x3F, 16,2); // if error get address from i2c scanner const int AirValue = 616; //replace the value with value when placed in air using calibration code const int WaterValue = 335; //replace the value with value when placed in water using calibration code int soilMoistureValue = 0; int soilmoisturepercent=0; void setup() { Serial.begin(9600); // open serial port, set the baud rate to 9600 bps lcd.begin(16, 2); } void loop() { soilMoistureValue = analogRead(A0); //put Sensor insert into soil Serial.println(soilMoistureValue); soilmoisturepercent = map(soilMoistureValue, AirValue, WaterValue, 0, 100); if(soilmoisturepercent >= 100) { Serial.println("100 %"); lcd.setCursor(0, 0); lcd.print("Soil Moisture"); lcd.setCursor(0, 1); lcd.print("100 %"); delay(250); lcd.clear(); } else if(soilmoisturepercent <=0) { Serial.println("0 %"); lcd.setCursor(0, 0); lcd.print("Soil Moisture"); lcd.setCursor(0, 1); lcd.print("0 %"); delay(250); lcd.clear(); } else if(soilmoisturepercent >0 && soilmoisturepercent < 100) { Serial.print(soilmoisturepercent); Serial.println("%"); lcd.setCursor(0, 0); lcd.print("Soil Moisture"); lcd.setCursor(0, 1); lcd.print(soilmoisturepercent); lcd.print(" %"); delay(250); lcd.clear(); } }
Calibration values:
to get the airvalue and watervalue use the calibration code at the end of the article.
After uploading the code LCD display outputs as the below image.
Interfacing capacitive soil moisture sensor v1.2 with Arduino and display on OLED display module
In this method we are going to output the moisture percentage value on OLED display. follow the below instructions step by step.
Required components:
- Arduino UNO R3
- Capacitive moisture sensor v1.2
- 0.96″ I2C OLED display module
- Few connecting wires
Circuit diagram:
Connect all the required components with connecting wires according to the above schematic diagram. here we connected the signal pin AOUT from sensor to A0 of Arduino, VCC and GND of sensor is connected to 3.3v and GND of Arduino respectively. We connected the OLED display module with Arduino. For more details on connecting OLED display with Arduino refer the below article link.
Source code:
After connecting all the components upload the below code, also install the required libraries from this libraries link.
Required Libraries:
- Adafruit_GFX.h
- Adafruit_SSD1306.h
#include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #define OLED_RESET 4 Adafruit_SSD1306 display(OLED_RESET); const int AirValue = 616; //replace the value with value when placed in air using calibration code const int WaterValue = 334; //replace the value with value when placed in water using calibration code int soilMoistureValue = 0; int soilmoisturepercent=0; void setup() { Serial.begin(9600); // open serial port, set the baud rate to 9600 bps display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //initialize with the I2C addr 0x3C (128x64) if any error use i2c scanner display.clearDisplay(); } void loop() { soilMoistureValue = analogRead(A0); //Insert Sensor into soil Serial.println(soilMoistureValue); soilmoisturepercent = map(soilMoistureValue, AirValue, WaterValue, 0, 100); if(soilmoisturepercent >= 100) { Serial.println("100 %"); display.setCursor(45,0); //set cursor on OLED display display.setTextSize(2); display.setTextColor(WHITE); display.println("Soil"); display.setCursor(20,15); display.setTextSize(2); display.setTextColor(WHITE); display.println("Moisture"); display.setCursor(30,40); //set cursor on OLED display display.setTextSize(3); display.setTextColor(WHITE); display.println("100 %"); display.display(); delay(250); display.clearDisplay(); } else if(soilmoisturepercent <=0) { Serial.println("0 %"); display.setCursor(45,0); //set cursor on OLED display display.setTextSize(2); display.setTextColor(WHITE); display.println("Soil"); display.setCursor(20,15); display.setTextSize(2); display.setTextColor(WHITE); display.println("Moisture"); display.setCursor(30,40); //set cursor on OLED display display.setTextSize(3); display.setTextColor(WHITE); display.println("0 %"); display.display(); delay(250); display.clearDisplay(); } else if(soilmoisturepercent >0 && soilmoisturepercent < 100) { Serial.print(soilmoisturepercent); Serial.println("%"); display.setCursor(45,0); //set cursor on OLED display display.setTextSize(2); display.setTextColor(WHITE); display.println("Soil"); display.setCursor(20,15); display.setTextSize(2); display.setTextColor(WHITE); display.println("Moisture"); display.setCursor(30,40); //set cursor on OLED display display.setTextSize(3); display.setTextColor(WHITE); display.println(soilmoisturepercent); display.setCursor(70,40); display.setTextSize(3); display.println(" %"); display.display(); delay(250); display.clearDisplay(); } }
Calibration values:
To get the airvalue and watervalue use the calibration code which is at the end of the article.
After uploading the code OLED display outputs as the below image.
Capacitive soil moisture sensor calibration code:
void setup() { Serial.begin(9600); // open serial port, set the baud rate as 9600 bps } void loop() { int value; value = analogRead(0); //connect sensor to Analog 0 Serial.println(value); //print the value to serial port delay(100); }
while calibrating follow the rules as shown in the below picture
Useful ideas:
- To make the sensor last long apply nail polish enamel on the sides of the open silicon chip to protect from water.
- Use a silicon glue or some tubing to protect the circuits above the warning line as they are not water proof.
If you find this project helpful please share it with your friends, and if you have any doubts or got any issues regarding this project please feel free to comment below or ask us on facebook community page “Circuit Schools“. Your interest makes us happy and help to add more projects. Thanks and happy creations.
WRONG! This sensor don’t work at 3,3V, because of the NE555. It needs more than 4 V
You need the sensors with the TL555C. this Chip is working with 2 V to 15 V, Please modify your artikel.
Hi, This is a good design in theory. However there are issues with a large number of available capacative soil moisture sensors of this type in the market. See the video at this link. https://www.youtube.com/watch?v=IGP38bz-K48 Indeed the versions of the sensor photographed in this article does not have the voltage regulator at U2 in place (Instead the supply is shorted to Vcc with Zero ohm resistor). Also in this design the sensor is supplied at 3.3V from the Arduino so the sensor should have a 555 timer able to run at 3.3V. Some NE555 (asperthe pics here) have a min Vcc spec of 4.5v So Its a good design but users should look out for the pitfalls of the variations in this sensor as layed out in the video above.