Temperature Meter
Temperature Meter
void main() {
OSCCON = 0X70; // Set internal oscillator to 8MHz
ANSEL = 1; // Configure RA0 pin as analog (AN0)
Lcd_Init(); // Initialize LCD module
Lcd_Cmd(_LCD_CURSOR_OFF); // cursor off
Lcd_Cmd(_LCD_CLEAR); // clear LCD
while(1) {
else
Temp_C[7] = ' '; // Put space ' '
Disclaimer:
Electricity poses inherent risks. Adequate skills are crucial for handling it safely. Undertake tasks
at your own risk; the author disclaims responsibility for misuse, harm, or errors. Website content
is unique and copyrighted; refrain from unauthorized copying. Most articles are open-source for
your benefit. Feel free to use the knowledge freely, and consider purchasing available resources.
For assistance or guidance, comment below; the author aims to help. Some articles may contain
affiliate links, having no impact on you but supporting the author with a commission. Thank you
for your understanding.
Advertisements
Table of Contents
About DHT11 sensor:
o Technical Specification of DHT11:
o Interfacing DHT11 with MCU:
Circuit diagram:
Coding:
o Code Explanation:
Test result:
Conclusion:
About DHT11 sensor:
The DHT11 measures relative humidity. The relative humidity is the amount of water vapor in
air vs the saturation point of water vapor in the air. At the saturation point, water vapor starts to
condense and accumulate on surfaces forming dew.
The saturation point changes with air temperature. Cold air can hold less water vapor before it
becomes saturated, and hot air can hold more water vapor before it becomes saturated.
The relative humidity is expressed as a percentage. At 100% RH, condensation occurs, and at 0%
RH, the air is completely dry.
Pin Configuration of DHT11
Signal pattern
So we have to draw our circuit according to the datasheet of DHT11.
You can read this article too: How to interface DHT22 with PIC microcontroller
Circuit diagram:
Here is the circuit diagram for interfacing DHT11 sensor and PIC micro-controller:
Circuit Diagram
Coding:
/*******************************************************************************
*******************************************************************************/
void StartSignal()
Data = 0;
Delay_ms(25);
Data = 1;
Delay_us(30);
TOUT = 0;
TMR2 = 0;
if (TOUT) return 0;
else
TMR2 = 0;
if (TOUT) return 0;
else
T2CON.TMR2ON = 0;
return 1;
DataDir = 1;
for (i=0; i<8; i++)
while(!Data);
Delay_us(40);
while(Data);
return num;
if(PIR1.TMR2IF)
TOUT = 1;
void main()
// port initialization
TRISB = 0b00000010;
PORTB = 0;
TMR2 = 0;
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,1,"DHT11 WITH");
Lcd_Out(2,1,"PIC16F877A");
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR);
while(1)
StartSignal();
check = CheckResponse();
if (!check)
Lcd_Cmd(_LCD_CLEAR);
else
{
RH_Byte1 = ReadByte();
RH_Byte2 = ReadByte();
T_Byte1 = ReadByte();
T_Byte2 = ReadByte();
CheckSum = ReadByte();
Lcd_Out(1,1,"HUMIDITY:");
Lcd_Out(2,1,"TEMP:");
Lcd_Out(1,11, message);
Lcd_Out(1,16,"%");
Lcd_Out(2,11, message);
Lcd_Chr_CP(223);
Lcd_Out(2,16,"C");
Delay_ms(2000);
else
Lcd_Cmd(_LCD_CLEAR);
}// while(1)
}// void