Interfacing LM35 temperature sensor with PIC microcontroller
An LM35 temperature sensor senses the temperature
and produces Analog signals which is fed to a microcontroller which interprets
the result. The microcontroller used here contains an Analog to Digital
Converter (ADC) which receives the signals from the LM35 and produces a
corresponding digital signal and the value of the temperature displayed on an
LCD.
Application:
Room temperature control
Egg incubator
Dryers e.g. cocoa dryers,
Green agriculture, etc.
Materials:
- An LM35
- A PIC 16F877A
- Two relays
- 2 transistors BC549
- 2 protective diodes (fly-back diodes)
- A Fan
- A heater
- A 16x2 LCD
- Supply DC 5/12V, AC 230V
Circuit diagram of LM35 temperature sensor interface with microcontroller
The circuitry is shown below
Operation
Interfacing temperature sensor code
char keypadport at PORTC;
sbit lcd_RS at RB0_bit;
sbit lcd_EN at RB1_bit;
sbit lcd_D4 at RB2_bit;
sbit lcd_D5 at RB3_bit;
sbit lcd_D6 at RB4_bit;
sbit lcd_D7 at RB5_bit;
sbit lcd_RS_direction at TRISB0_bit;
sbit lcd_EN_direction at TRISB1_bit;
sbit lcd_D4_direction at TRISB2_bit;
sbit lcd_D5_direction at TRISB3_bit;
sbit lcd_D6_direction at TRISB4_bit;
sbit lcd_D7_direction at TRISB5_bit;
void main()
{
char display[16];
unsigned int result ;
float volt, temp ;
ADCON1 = 0x60;
TRISA = 0Xb111111;
TRISB = 0X00;
lcd_init();
lcd_cmd(_lcd_clear);
lcd_cmd(_lcd_cursor_off);
lcd_out(1,3,"temperature");
delay_ms(500);
lcd_out(2,5,"display" );
delay_ms(1000);
lcd_init();
lcd_cmd(_lcd_clear) ;
lcd_cmd(_lcd_cursor_off);
lcd_out(1,1,"temp =");
delay_ms(500);
while(1)
{
result= ADC_read(0) ;
volt = result*4.88;
temp = volt/10;
floattoStr(temp,display);
lcd_out(1,7,display);
lcd_chr(1,15,223);
lcd_out_cp("C");
if(temp<25)
{PORTB.RB6 = 0;
PORTB.RB7 = 1;}
else
{PORTB.RB7 = 0;
PORTB.RB6 = 1; }
}
}
schematic of operation:
Temperature is less than 25 degree Celsius. So, the heater is ON and the fan OFF. we can see the heater is heating and is at 75%.
Temperature is greater than 25 degree Celsius (29 degree Celsius). So, the heater is OFF and the fan ON to bring down the temperature. we can see as the fan is supplied from the relay and the heater is cooling down ( at 50%). The heater gradually cools down
Related:
Interfacing 16X2 LCD
Interfacing infrared distance sensor
Interfacing PH sensor
Scrolling text on LCD
Interfacing infrared distance sensor
Interfacing PH sensor
Scrolling text on LCD