วันจันทร์ที่ 4 กุมภาพันธ์ พ.ศ. 2562

งานที่ 3 rain detector circuit using pic microcontroller

                                  rain detector circuit using pic microcontroller – raindrop sensor





code

// 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;

////// rain detection circuit sensor variable///////

float rain_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,"Rain sensor" ); // Write text in first
delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR); // Clear display

while(1) 
{ // Endless loop

moisture_value = ADC_Read(0); // It will read the moisture value of sensor
if( moisture_value < 300 )
Lcd_Out(1,1, "Heavy rain" );
else if( moisture_value < 500 )
Lcd_Out(1,1, "Moderate rain" );
else
Lcd_Out(1,1, "No rain" );
//***** it will display the rain intensity in percentage format/////////
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("%");

}
}



ไม่มีความคิดเห็น:

แสดงความคิดเห็น