Soil Moisture Sensor YL-69 or HL-69 interfacing with pic microcontroller

Soil Moisture Sensor YL-69 or HL-69 interfacing with pic microcontroller, In this tutorial you will learn how to interface Soil Moisture Sensor YL-69 or HL-69 with pic microcontroller? How to measure soil moisture using these low price sensors and how to display these measured values on liquid crystal display. Soil moisture sensor is also know as hygrometer. It is used to measure the humidity level of moisture or it is used to measure the moisture content in soil. You can also use it to measure water level by using multiple moisture sensors.  you may also like to check our previous tutorials on various sensors interfacing with pic microcontroller.

Introduction to Soil Moisture Sensor YL-69 or HL-69

So now let’s see what is soil moisture sensor? How soil moisture sensor works? Pin out of Soil moisture sensor we are using in this tutorial. As I have discussed earlier Soil Moisture Sensors are used to measure level of moisture in soil.  I am using Soil Moisture Sensor YL-69 or HL-69  in this tutorial. So now lets see how to use this senor. Picture of soil moisture sensor is shown below. It consists of two parts one is electronic circuit on the right side of the picture which is used to adjust the sensitivity and other on the left hand side consists of two probes which we place in soil. soil moisture sensor pin out

// LCD module connections
sbit LCD_RS at RC0_bit;
sbit LCD_EN at RC1_bit;
sbit LCD_D4 at RC2_bit;
sbit LCD_D5 at RC3_bit;
sbit LCD_D6 at RC4_bit;
sbit LCD_D7 at RC5_bit;

sbit LCD_RS_Direction at TRISC0_bit;
sbit LCD_EN_Direction at TRISC1_bit;
sbit LCD_D4_Direction at TRISC2_bit;
sbit LCD_D5_Direction at TRISC3_bit;
sbit LCD_D6_Direction at TRISC4_bit;
sbit LCD_D7_Direction at TRISD5_bit;

////// Moisture sensor variable///////

float moisture_value;
char text[10];
void main(void)
{

ADC_Init(); // it will initialize the adc module of pic16f877a microcontroller
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,"Moistue sensor" ); // Write text in first row

while(1) 
{ // Endless loop

moisture_value = ADC_Read(0); // It will read the moisture value of sensor
moisture_value = ( moisture_value * 100) / (1023); // it converts the moisture value on percentage
FloatToStr(moisture_value, Ltrim(text));
Lcd_Out(2,1, text );
Lcd_Out_cp("%");

}
}

Simply upload this code to pic16f877a microcontroller and check working of your sensor.

7 thoughts on “Soil Moisture Sensor YL-69 or HL-69 interfacing with pic microcontroller”

  1. whre are these function definations in moisture level detection with piv code
    ADC_Init(); // it will initialize the adc module of pic16f877a microcontroller
    Lcd_Init(); // Initialize LCD
    Lcd_Cmd(_LCD_CLEAR); // Clear display
    Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
    Lcd_Out(1,1,”Moistue sensor” ); // Write text in first row

    Reply
  2. Where can we get the module for the moisture sensor? I am currently working on a project that requires the moisture sensor, and I cannot find a module for it on Proteus.

    Reply

Leave a Comment