This is a tutorial on plant monitoring system with alarm using Arduino to monitor soils moisture using YL-69(HL-69) for plant watering. Here we will build Arduino plant monitor that monitors soils using moisture(humidity) sensor YL-69(or HL-69 can be used) to detect whether the plant needs watering or not. This can be helpful at monitoring your plants automatically at home or can be used in agricultural farms to automate watering of crops and vegetables.
Parts Required:
• Arduino board• Jumper wires
• LED
• HL-69 hygrometer soil moisture sensor
• Piezo buzzer
YL-69 moisture sensor for Plants
The YL-69 moisture sensor also called hygrometer used
in this project is readily available in the market and just cost few
dollars. The picture below shows the YL-69 plant moisture sensor.
As shown in the figure above, the sensor consists of two parts: the prong sensor and the electronic controller board. The sensors detects level of water content in the soil by sending current from its prongs through the soil. A damp soil conducts more electricity(less resistance) than a dry soil(higher resistance). By detecting the conductivity of the soil, the sensor detects whether the soil is damp or dry. The controller contains logic and IC, some resistors, LED, potentiometer(to adjust sensitivity) that detects conductivity from the prong and sends the sensed values to microcontrollers or Arduino. In effect, we have the following conditions:
- Wet: the output voltage decreases
- Dry: the output voltage increases
It
has four pins: AO (analog out), DO (digital out), GND, and VCC Arduino
reads the value from the controller AO and DO pins. A lower value
readings indicate more moisture content in the soil and higher value
readings indicate dryness of the soil. Either of the analog or digital
output can be used to monitor the soil conductivity. If we use digital
output(DO), then when certain predefined threshold is exceeded, the DO
outputs high otherwise low. If we use analog output(AO) then the
controller sends value from 0 to 1023 and we can use pre-defined
threshold to take action if it is exceeded. In this tutorial we will use
the analog output(AO) to monitor the plant soil.
So
by monitoring the output from the controller using Arduino, if the
reading exceeds the threshold then we can know that the plant is thirsty
and needs watering. And by using LED and piezo buzzer we can create
visual and audio alarm if watering is needed.
Video demonstration of plant watering
The following video shows how the soil moisture sensor works.
Interfacing & Circuit Schematic of Plant Moisture Sensor & Arduino
The following circuit schematic drawing shows the connection of plant moisture sensor YL-69 with Arduino, LED with resistor and the buzzer.
The circuit wiring is as follows:
Arduino & YL-69:
- Analog pin A2 of Arduino is connected to the analog output AO of the plant sensor
- GND of Arduino and sensor are connected together
- VCC of sensor is connected to Arduino +5V
Arduino & Buzzer
- The buzzer is connected to Arduino pin 4 and grounded on the other side
Arduino & LED
- The LED with 220Ohm resistor is connected to Arduino pin 2
Arduino code for Moisture detection for Plant Monitoring
The following is code for Arduino for moisture detection in soil for plant monitoring.
const int sensorPin = A2; //Pin connected to A2 on the controller
const int ledPin = 2; // Pin connected to the LED
const int buzzerPin = 4; // Pin connected to the piezo buzzer
void setup () {
Serial.begin(9600); //set baud rate for serial monitor for reading
pinMode(ledPin, OUTPUT); //set pin as output
pinMode(buzzerPin, OUTPUT); //set pin as output
//Output format:
Serial.println("\nSoil Moisture/Humidity sensor");
Serial.println("------------------------------");
}
void loop () {
int anaValue = analogRead(sensorPin); //read sensor value
if (anaValue > 200){
digitalWrite(ledPin, HIGH); //LED indicator alarm
digitalWrite(buzzerPin, HIGH); //buzzer sounds alarm
delay(1000); //wait for 1 sec for buzzer to sound and then repeat
digitalWrite(buzzerPin, LOW);
Serial.println("\nSensor Value: "+String(anaValue));
Serial.println("Soil is Dry, Plesae water your Plant!");
delay(1000); // Wait for 1 second
}
else{
digitalWrite(ledPin, LOW); //turn off LED if reading is below 900
digitalWrite(buzzerPin, LOW); //turn off buzzer if reading is below 900
Serial.println("Sensor Value: "+String(anaValue));
Serial.println("Soil is Wet, Good!");
delay(1000); // Wait for 1 second
}
}
In the above code, we have setup the pins for the moisture plant sensor, buzzer and the led as described in the above schematic wiring part. Then we read in the voltage sensed by the Arduino on the analog pin A2. This read value is from 0 to 1023. This is then calibrated according to need to decide what value is judged as wet soil or dry soil. In the example code above, we have used value of 900 as being the threshold value for wet. If the value read by the ADC is greater than 900 then we decide that the soil is dry. If the soil is dry which means the read value is greater than 900, then we turn on the buzzer alarm and also the LED is turned on to give visual indicator. We also output reading from the plant sensor to the serial monitor and give text warning and alert to the user. The output on serial monitor is shown below.
So in this way we can monitor the soill moisture content with Arduino.