Skip to main content

social

pop

Programming temperature sensor with microcontroller

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
interfacing temperature sensor

Operation

Lets control the temperature such that if the temperature is less than 25 degree Celsius, the heater is put ON and the fan OFF. If the temperature is about 25 degree Celsius, the fan is put ON and the heater put OFF to reduce the temperature. The code is presented below and the conditions can be modified to suit your domain of application. this is just an example to illustrate on how to interface a temperature sensor. 

Interfacing temperature sensor code

you can copy the code below. ( mikro c 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:


interfacing LM35 temperature sensor
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%.

interfacing temperature sensor with PIC microcontroller

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:




















Popular posts from this blog

How to Install Proteus 8 Professional: A Step-by-Step Guide

 How to Install Proteus 8 Professional: A Step-by-Step Guide Proteus 8 Professional is a powerful tool for electronic circuit design and simulation. Whether you’re a student, hobbyist, or professional engineer, following a clear installation process ensures you get started without headaches. Are you ready to start designing and simulating electronic circuits with Proteus 8 Professional!   Here’s a comprehensive, guide to installing Proteus 8 Professional on your Windows PC. Step 1: Download the Installer ·        Visit the official Labcenter Electronics website or another trusted source to download the Proteus 8 Professional installer. Avoid unofficial sources to prevent malware or corrupted files . You can download from HERE DOWNLOAD PROTEUS AND ARDUINO ·        The installer typically comes as a ZIP file. Wait for the download to finish and locate it in your Downloads folder Step 2: Extract the Installer...

Intermediate switch connection and wiring diagram

Intermediate switch An intermediate switch is a switch which permits the control of a lighting point from three positions. In order to control this lighting point from the three positions, the intermediate switch is connected together with two other 2-way switches. Application: it can be used in lighting a room or hall having 3 entrances , it can also be used in long corridors and staircases. We shall be looking at these connections. Connection diagram of intermediate switching Below is an illustration of the connection. The brown lines indicated on the diagram are the switching contacts. The switch labelled 2 is an intermediate switch . The figure below is the configuration of an intermediate switch. The switch labelled 1 and 3 in the first diagram are two-way switches.  Click here to know more about two-way switches . ON and OFF positions of intermediate switching ON positions OFF positions Staircase wiring layout using an inte...

Download HND Past Questions and Solutions

Download Cameroon HND Past Questions & Solutions Boost your exam prep with past papers and answers across all fields! How to Access Past Questions Visit the Cameroon HND Platform or trusted sites like EKETECH . Browse by field : Select your program (e.g., Civil Engineering , Banking and Finance , Nursing ). Download PDFs for free or via subscription. Practice with solutions : Review answers to refine your understanding. Fields of Study Covered Past questions are available for all HND programs in Cameroon, including: Engineering Civil Engineering Design Software Engineering Electrical Power Systems Telecommunication Mechanical Engineering Computer Engineering Medical Sciences Nursing Medical Laboratory Studies Health Care Management Physiotherapy Nutrition and Dietetics Agriculture Agribusiness Management Agricultural Engineering Food Technology Integrated Agriculture Business Accounting Banking and...