Digitize Your Soil With A Sensor
Overview
In this section you will learn how to use the soil moisture sensor. With a practical example to help you grab the concept.
What You Will Learn
- How the soil moisture sensor operates
- Hardware Overview
- Interfacing the sensor with Arduino
How The Soil Moisture Sensor Operates
The sensor has two probes which serves as conductors. The conductivity of the sensor is dependent on the moisture level of the soil. More water in the soil means more conduction and less resistance where as less moisture content means less conduction and more resistance. The sensor produces an output voltage according to the resistance, which means by measuring we can determine the soil moisture level.
Hardware Overview
A typical sensor has two components
- Probe
- Electronic Module
Probe
This is a fork shaped component that goes into the soil.It conducts electricity according to the moisture level of the soil
Electronic Module
This is what links the Arduino to the probe.The sensor has four pin-out
- VCC(Power Pin)
- GND(Ground Pin)
- AO(Analog Pin)-gives an analog signal and will be connected to analog input on the Arduino
- DO(Digital Pin)-gives digital output of the internal comparator output and will be connected to a digital input of the Arduino or 5v relay.
This set up is useful and can help make your soil smatter ,for example when a threshold is reached a signal can be sent to trigger a relay to start pumping water on the farm into the soil
ii) Status LED-Lights up when the digital output goes low
Interfacing sensor with Arduino
There are two ways of connecting the soil moisture level sensor to the Arduino
- Analog mode
- Digital mode
Components for both set ups are:
- Arduino UNO
- connecting wires
- Soil moisture level sensor
- Breadboard
- LED
Analog mode
circuit diagram of sensor in analog mode
//code after connecting components
int sensor =A1;//sensor is connected to the anolog pin A1 of the Arduino
int value =0;//takes reading of the sensor
int led =13;//Arduino's on board LED
boolean notice =false;//stop unnecessary repetition of code
void setup() {
Serial.begin(9600);//activates serial monitor
pinMode(sensor ,INPUT);
pinMode(led,OUTPUT);
}
void loop() {
value =analogRead(sensor);//reads the moisture level and stores the value in 'value'
Serial.println(value);//prints the value read by the sensor
if((value>=500)&&(notice==false)){//if value is greater than 500 and notice is true
digitalWrite(led, HIGH);//turn on the LED
//This means soil is dry hence needs water
notice=true;//change the notice status back to true
delay(1000);//delays for 1 sec and continues with next line of code
}
if((value <=300)&&(notice==true)){//if value is less than 300 and notice is true
digitalWrite(led, LOW);//turn off LED
//water level is okay hence quit adding water
notice=false;//changes the nnotice status back to false
delay(1000);
}
delay(1000);
}
Digital mode
The circuit diagram for the digital mode is similar to that of the analog mode just that the digital pin of the module is connected to the digital pin of the arduino
circuit diagram on sensor in digital mode
int sensor =4;//sensor is connected to pin 4 of Arduino
int led =13;//Arduino's on-board LED
boolean notice =false;//stop unnecessary repetition of code
void setup() {
Serial.begin(9600);//activates serial monitor
pinMode(sensor ,INPUT);
pinMode(led,OUTPUT);
}
void loop() {
if((digitalRead(sensor)==HIGH&&(notice == false))){//if sensor is HIGH and notice is false
digitalWrite(led, HIGH);//turn on LED
//soil is dry hence needs water
notice=true;//change notice status to true
delay(1000);//delays for one second
}
if((digitalRead(sensor)==LOW&&(notice == true))){//if sensor is LOW amd notice is true
digitalWrite(led, LOW);//turn LED off
notice=false;//change notice status back to false
delay(1000);
}
delay(1000);
}
wooow! my very own Hon. Garbah, nice job bro. Keep it up. I suggest you implement it on an actual day to day life practicality, for instance, a garden.
its will happen practically,the project is in the dormancy stage it will germinate and skate the soil soon.
thanks very much bro
You are welcome bro
Great Job….. interesting piece
3b3 tumi ay3 true😅
i would like to recommend this if its possible on your side
i think it make reading very easy 🙂
the output should be rated over 10% and print something like this
1 — dry soil
2 — dry soil
3 — Wet
4 –Average
5 — Average
6 — Average
7 — Moist
8 — Moist
9 — Very moist
10 — Wattery
That’s an eye opener, I love this idea I wil work on it. Thanks very much
will be looking up to you boss 🙂
That will be great yh. @charles show us😍
wooooow
This is great
Wow I love your work sir, keep sharing with us😊