INTRODUCTION
In this tutorial, we are going to learn how to interface a Soil Moisture sensor to an Arduino UNO. And we will learn how to measure the moisture level of the soil.
THEORY
The soil moisture sensor is basically used for measuring the moisture level of the soil.
It detects the availability of water inside the soil and gives us the data as moisture level.
We can get both digital and analog output from the sensor.
This sensor has two probes, which pass current through the soil. If there is more water in the soil then it conducts electricity easily and when dry soil it conducts electricity poorly.
It has 4 pins,
i) Aout
ii)Dout
iii)GND
iv)VCC
REQUIREMENTS
Parts | Quantity |
Arduino UNO | 1 |
A-B cable | 1 |
Soil Moisture Sensor | 1 |
Bread Board | 1 |
Connecting Wires | As per required |
CIRCUIT DIAGRAM
NOTE: Here I used the Analog pin for programming.
CODE
For programming this concept we need to understand some basic syntax of Arduino IDE. The first thing is we need to install Arduino. After that, we need to know how to interface led to Arduino and how to use serial monitor.
To control Moisture Sensors we need to define, at which pin it is connected to UNO. And also we will define the LED.
Here we used the in-built LED of UNO.
#define moist A0 //Analog pin of UNO
#define LED 13
After define we have to declare it. Whether the LED is an output/input device. There is no requirement of declaring the sensor because it is connected to the analog pin.
Also, I added here the serial monitor.
void setup()
{
Serial.begin(9600);
pinMode(LED, OUTPUT);
delay(2000);
}
Let's start the sensor by using some basic syntax in the void loop function.
void loop()
{
Serial.print("MOISTURE LEVEL : ");
value= analogRead(moist); // This will detect the moisture value.Here i used value as a variable.
value= value/10;
Serial.println(value);
if(value<50)
{
digitalWrite(LED,HIGH);
}
else if(value>60)
{
digitalWrite(LED,LOW);
}
}
FINAL CODE
#define moist A0
#define LED 13
int value= 0;
void setup()
{
Serial.begin(9600);
pinMode(LED, OUTPUT);
delay(2000);
}
void loop()
{
Serial.print("MOISTURE LEVEL : ");
value= analogRead(moist);
value= value/10;
Serial.println(value);
if(value<50)
{
digitalWrite(LED,HIGH);
}
else if(value>60)
{
digitalWrite(LED,LOW);
}
}
Comments
Leave a Reply