วันอังคารที่ 5 กุมภาพันธ์ พ.ศ. 2562

งานที่ 4 MQ-2 gas sensor interfacing with pic microcontroller

                                       MQ-2 gas sensor interfacing with pic microcontroller



code

// LCD module connections
sbit LCD_RS at RD2_bit;
sbit LCD_EN at RD3_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;

sbit LCD_RS_Direction at TRISD2_bit;
sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;

////// MQ-2 gas sensor interfacing with pic microcontroller ///////

int gas_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,"MQ-2 sensor" ); // Write text in first
delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR); // Clear display

while(1)
{ // Endless loop

gas_value = ADC_Read(0); // It will read the gas value of sensor
if( gas_value > 400 )
Lcd_Out(1,1, "Gas detected" );
else
Lcd_Out(1,4, "No Gas " );
intToStr(gas_value, Ltrim(text));
Lcd_Out(2,1, text );
delay_ms(1000);

}
}


อ้างอิง

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

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