Sunday, 5 November 2017

SOIL MOISTURE SENSOR VALUE AND THRESHOLD VALUE

Soil moisture sensor have fixed value that is 0 - 1023

EXAMPLE:

if you set your threshold value=250, when

soil moisture sensor value<threshold value, the plant does not need watering, pump stop

soil moisture sensor value>threshold value, the plant need watering, pump start.

Sunday, 22 October 2017

EXAMPLE: SOIL MOISTURE SENSOR WITH THE ARDUINO.

This is a simple example for you to understand how you can use the soil moisture sensor in your projects with Arduino.
In this example, you’ll read the analog sensor output values using the Arduino and print those readings in the Arduino IDE serial monitor.

Parts required
For this example, you’ll need the following components:
  • 1x YL-69 moisture sensor
  • 1x Arduino
  • 1x Breadboard
  • 2x 220 Ohm Resistors
  • 1x Red LED
  • 1x Green LED
  • Jumper wires
CODE

Upload the following sketch to your Arduino board:

int rainPin = A0;
int greenLED = 6;
int redLED = 7;
// you can adjust the threshold value
int thresholdValue = 800;

void setup(){
  pinMode(rainPin, INPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(redLED, OUTPUT);
  digitalWrite(greenLED, LOW);
  digitalWrite(redLED, LOW);
  Serial.begin(9600);
}

void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(rainPin);
  Serial.print(sensorValue);
  if(sensorValue < thresholdValue){
    Serial.println(" - Doesn't need watering");
    digitalWrite(redLED, LOW);
    digitalWrite(greenLED, HIGH);
  }
  else {
    Serial.println(" - Time to water your plant");
    digitalWrite(redLED, HIGH);
    digitalWrite(greenLED, LOW);
  }
  delay(500);
}

Open the Arduino IDE serial monitor to see the values. Then, try your sensor in a wet and in a dry soil and see what happens.
When the analog value goes above a certain threshold, a red LED will turn on (indicates that the plant needs watering), and when the value goes below a certain threshold, a green LED will turn on (indicates that the plant is ok).

Tuesday, 10 October 2017

HOW DOES SOIL MOISTURE SENSOR WORK?

The voltage at the sensor outputs changes accordingly to the water content in the soil.

When the soil is:

  • Wet: the output voltage decreases
  •          Dry: the output voltage increases


The output can be a digital signal (D0) LOW or HIGH, depending on the water content. If the soil humidity exceeds a certain predefined threshold value, the modules outputs LOW, otherwise it outputs HIGH. The threshold value for the digital signal can be adjusted using the potentiometer.



Monday, 2 October 2017



GUIDE FOR SOIL MOISTURE SENSOR.

The sensor is set up by two pieces: the electronic board (at the right), and the probe with two pads, that detects the water content (at the left).


The sensor has a built-in potentiometer for sensitivity adjustment of the digital output (D0), a power LED and a digital output LED, as you can see in the following figure.




Monday, 25 September 2017

EXAMPLE OF CODING IN ARDUINO UNO.


#include<LiquidCrystal.h>

 #define moisture_sensorPin A0
 #define float_switchPin A1
 #define motorPin 4
 #define soil_statusPin 2
 #define tank_statusPin 3

 LiquidCrystal lcd(13,12,11,10,9,8);

 const int avg_moisture = 800;

void setup()
{
 Serial.begin(9600);
 lcd.begin(16,2);
 lcd.clear();
 lcd.setCursor(0,0);
 lcd.print(" AUTOMATIC ");
 lcd.setCursor(0,1);
 lcd.print(" IRRIGATION S/M ");
 delay(2000);

  pinMode(moisture_sensorPin,INPUT);
 pinMode(float_switchPin,INPUT);
 pinMode(motorPin,OUTPUT);
 pinMode(soil_statusPin,OUTPUT);
 pinMode(tank_statusPin,OUTPUT);

 digitalWrite(motorPin,LOW);
 digitalWrite(soil_statusPin,LOW);
 digitalWrite(tank_statusPin,LOW);
}
void loop()
{
lcd.begin(16,2);

 lcd.setCursor(0,0);
 lcd.print(" MOISTURE - ");

 if(analogRead(moisture_sensorPin) > avg_moisture){
 lcd.print("HIGH");
 digitalWrite(soil_statusPin,HIGH);}

 if(analogRead(moisture_sensorPin) < avg_moisture){
 lcd.print(" LOW");
 digitalWrite(soil_statusPin,LOW);}

 lcd.setCursor(0,1);
 lcd.print("TANK LEVEL- ");

 if( digitalRead(float_switchPin) == HIGH){
 lcd.print("HIGH");
 digitalWrite(tank_statusPin,LOW);}
 if( digitalRead(float_switchPin) == LOW){
 lcd.print(" LOW");
 digitalWrite(tank_statusPin,HIGH);}

 digitalWrite(motorPin,LOW);

  if(analogRead(moisture_sensorPin) < avg_moisture && digitalRead(float_switchPin) == HIGH)
 {

 while(analogRead(moisture_sensorPin) < avg_moisture && digitalRead(float_switchPin) == HIGH)
 {
 lcd.setCursor(0,0);
 lcd.print(" MOISTURE - LOW");
 lcd.setCursor(0,1);
 lcd.print(" MOTOR IS ON ");
 digitalWrite(soil_statusPin,LOW);
 digitalWrite(tank_statusPin,LOW);
 digitalWrite(motorPin,HIGH);
 }

 if(analogRead(moisture_sensorPin) > avg_moisture){
 lcd.setCursor(0,0);
 lcd.print(" MOISTURE - HIGH");
 lcd.setCursor(0,1);
 lcd.print(" MOTOR - OFF ");
 digitalWrite(soil_statusPin,HIGH);
 digitalWrite(motorPin,LOW);
 delay(3000);}

 if(digitalRead(float_switchPin) == LOW){
 lcd.setCursor(0,0);
 lcd.print(" TANK LEVEL- LOW");
 lcd.setCursor(0,1);
 lcd.print(" MOTOR - OFF ");
 digitalWrite(tank_statusPin,HIGH);
 digitalWrite(motorPin,LOW);
 delay(3000);}

}
 delay(500);

}

In this programming part, to facilitate communication between Arduino and LCD module, we make use of a built in library in Arduino <LiquidCrystal.h>. During interfacing  the library is first initialized and then define pins using the command LiquidCrystal lcd(RS, E, D4, D5, D6, D7), pins are assigned in this order.

The Arduino reads the sensor output through the analog input pins using analogRead function. For example “analogRead(moisture_sensorPin);” converts the voltage (in the range 0 to 5V) at the  A0 pin into a number (in the range 0 to 1023) This way the voltage at A0 is compared to a fixed number (avg_moisture) for identifying the current status of the soil.

Monday, 18 September 2017

EXAMPLE OF SOIL MOISTURE SENSOR CIRCUIT.

HOW MOISTURE SENSOR WORKS IN A CIRCUIT.

DRY CONDITION

when no moisture or water, the probe are dry. Circuit is open, no current flows into the base of the transistor, so the LED is off.


WET CONDITION

when there is moisture or water, the probe gets short circuit when in contact with moisture or water. Circuit is closed, current will flow into the base of the transistor, LED turns on.