Introduction
In my previous article I explained about working with a fire sensor and in this article I'll show you working with a soil moisture sensor to get the accurate moisture value in the soil.
Things you will need
- Arduino Uno
- Bread Board
- Soil Moisture Sensor
- Led
Connection
- Pin1 to the Analog
- Pin2 to the Gnd
- Pin3 to the 5v
Programming
- int pin=A0;
- int soilmoisture=0;
- int led=13;
- void setup()
- {
- pinMode(led,OUTPUT);
- Serial.begin(9600);
- }
- void loop()
- {
- int soilmoisture=analogRead(pin);
-
- if(soilmoisture>=100){
- digitalWrite(led,HIGH);
- }
- else{
- digitalWrite(led,LOW);
- }
- Serial.println(soilmoisture);
- Serial.print("%");
- delay(20);
- }
Explanation
Declare the variable pin to the Analog and set the minimum value to the soil moisture sensor as 0 and connect the led to the digital pin 13
Functions
Void setup()
- Set the pinMode to led as OUTPUT
- Set the baud Rate( 9600)
Void loop()
AnalogRead- Reads the analog value from the specific pin i.e soil moisture pin with the delay time
Condition
- if (soilmoisture >= 100)
- {
-
- }
- else
- {
-
- }
And then print the soil moisture sensor value in the serial monitor.
Advantages
- It reduces the human effort.
- Based upon the irrigation the water will flow through the plant.
- We can save our water.
Read more articles on Arduino: