SlideShare a Scribd company logo
1 of 3
Download to read offline
PIC16F877A and LM35 Based Temperature Monitor 
This is a simple project showing you how to read LM35 analog temperature sensor using a PIC microcontroller and to switch a certain load at a certain temperature. Software in use: CCS PIC-C Compiler Labcenter Proteus VSM Some concepts you need to Know: ADC is an internal module used to read analog voltages in the form of a digital representation, in this project I've used 16F877a which includes a 10Bit resolution ADC module having 8 channels A0-A5 and E0-E2. One important parameter of the ADC module is it's reference voltage (Vref), which is the maximum voltage an ADC can read, in our case Vref = 5V which is the supply voltage. Another important parameter is the ADC resolution, which determines the minimum value of analog voltage can read (ADC Step size). For example, our ADC is 10Bit resolution with a 5V reference, the range of voltages starting at 0V and ended by 5V is to be divided into equal steps starting at 000 and ended by 1023 (2^10 -1). i.e. if the input voltage is 5V which is the max value, the ADC will read it as 1023, if the input was 2.5V, the reading would be 512 and so on. The ADC step is simply calculated using the equation : Step = Vref/1024 , in our case its 4.883 mV, that's the minimum voltage our ADC can read, so: an input of 4.883mV would give us a reading of 001 an input of 9.766mV would give us a reading of 002, and so on. LM35 Temperature Sensor: LM35 is a Three-Pins (Vcc,Output,GND) high precision temperature sensor having a resolution of 10mV/C starting at 0V (i.e. an output of 0V represents a temperature of 0C). So, 10mV ---> 1C 20mV ---> 2C 370mV ---> 37.0C and so on. Converting ADC Reading to Celsius degrees: Knowing that our ADC has a step size of 4.883mV, converting our digital reading back to voltage is simply done by multiplying the digital reading by the step size: Vin (in Volts) = DigitalReading * 0.004883 Now, knowing our sensor's sensitivity is 10mV/C, converting this voltage to Celsius is simply done by dividing the input voltage by 0.01, So: Temperature (C) = Vin/0.01 = DigitalReading * 0.4883 
www.facebook.com/ELECTRONICS.LOVERZ www.electronicxlovers.blogspot.com
The Schematic Design
The C-Code: /* PIC16F877A and LM35 Based Temperature Monitor Badr Ghatasheh 079@live.it */ #include <16f877a.h> #device adc=10 // Set ADC resolution to 10Bit #fuses XT,NOLVP,NOWDT,NOPROTECT #use delay(clock=4000000) #use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,ERRORS) #include "lcd_flex.c" #define LOAD PIN_B7 #define THRES 30.0 // load switching threshold in Celsius int16 digital_reading; // ADC resolution is 10Bit, an 8Bit integer is not enough to hold the reading float temp; void main() { /* ADC Initialization */ setup_adc(ADC_CLOCK_INTERNAL); // initialize ADC with a sampling rate of Crystal/4 MHz setup_adc_ports(RA0_ANALOG); // set PIN_A0 as analog input channel set_adc_channel(0); // point ADC to channel 0 for ADC reading delay_ms(1); // ADC module is slow, needs some time to adjust. /* Peripherals Configurations */ lcd_init(); // Turn LCD ON, along with other initialization commands output_low(LOAD); // the load is initially OFF lcd_gotoxy(1,1); // point LCD cursor to col1 row1 lcd_putc("Temperature is:"); // print on LCD while(1) // infinite loop { digital_reading = read_adc(); // capture current temperature reading delay_us(100); // 0.1ms delay for ADC stabilization temp = digital_reading * 0.4883; // convert reading to Celsius lcd_gotoxy(1,2); // point LCD cursor to col1 row2 printf(lcd_putc,"%2.1f C",temp); // print value on LCD if(temp>=THRES) output_high(LOAD); // Control Load else output_low(LOAD); delay_ms(1000); // 1 second delay between readings } } 
For any questions, do not hesitate to ask :) www.facebook.com/ELECTRONICS.LOVERZ

More Related Content

Recently uploaded

Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Dr.Costas Sachpazis
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ankushspencer015
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
Tonystark477637
 

Recently uploaded (20)

Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spain
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 

Featured

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

PIC16F877A and LM35 Based Temperature Monitor

  • 1. PIC16F877A and LM35 Based Temperature Monitor This is a simple project showing you how to read LM35 analog temperature sensor using a PIC microcontroller and to switch a certain load at a certain temperature. Software in use: CCS PIC-C Compiler Labcenter Proteus VSM Some concepts you need to Know: ADC is an internal module used to read analog voltages in the form of a digital representation, in this project I've used 16F877a which includes a 10Bit resolution ADC module having 8 channels A0-A5 and E0-E2. One important parameter of the ADC module is it's reference voltage (Vref), which is the maximum voltage an ADC can read, in our case Vref = 5V which is the supply voltage. Another important parameter is the ADC resolution, which determines the minimum value of analog voltage can read (ADC Step size). For example, our ADC is 10Bit resolution with a 5V reference, the range of voltages starting at 0V and ended by 5V is to be divided into equal steps starting at 000 and ended by 1023 (2^10 -1). i.e. if the input voltage is 5V which is the max value, the ADC will read it as 1023, if the input was 2.5V, the reading would be 512 and so on. The ADC step is simply calculated using the equation : Step = Vref/1024 , in our case its 4.883 mV, that's the minimum voltage our ADC can read, so: an input of 4.883mV would give us a reading of 001 an input of 9.766mV would give us a reading of 002, and so on. LM35 Temperature Sensor: LM35 is a Three-Pins (Vcc,Output,GND) high precision temperature sensor having a resolution of 10mV/C starting at 0V (i.e. an output of 0V represents a temperature of 0C). So, 10mV ---> 1C 20mV ---> 2C 370mV ---> 37.0C and so on. Converting ADC Reading to Celsius degrees: Knowing that our ADC has a step size of 4.883mV, converting our digital reading back to voltage is simply done by multiplying the digital reading by the step size: Vin (in Volts) = DigitalReading * 0.004883 Now, knowing our sensor's sensitivity is 10mV/C, converting this voltage to Celsius is simply done by dividing the input voltage by 0.01, So: Temperature (C) = Vin/0.01 = DigitalReading * 0.4883 www.facebook.com/ELECTRONICS.LOVERZ www.electronicxlovers.blogspot.com
  • 3. The C-Code: /* PIC16F877A and LM35 Based Temperature Monitor Badr Ghatasheh 079@live.it */ #include <16f877a.h> #device adc=10 // Set ADC resolution to 10Bit #fuses XT,NOLVP,NOWDT,NOPROTECT #use delay(clock=4000000) #use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,ERRORS) #include "lcd_flex.c" #define LOAD PIN_B7 #define THRES 30.0 // load switching threshold in Celsius int16 digital_reading; // ADC resolution is 10Bit, an 8Bit integer is not enough to hold the reading float temp; void main() { /* ADC Initialization */ setup_adc(ADC_CLOCK_INTERNAL); // initialize ADC with a sampling rate of Crystal/4 MHz setup_adc_ports(RA0_ANALOG); // set PIN_A0 as analog input channel set_adc_channel(0); // point ADC to channel 0 for ADC reading delay_ms(1); // ADC module is slow, needs some time to adjust. /* Peripherals Configurations */ lcd_init(); // Turn LCD ON, along with other initialization commands output_low(LOAD); // the load is initially OFF lcd_gotoxy(1,1); // point LCD cursor to col1 row1 lcd_putc("Temperature is:"); // print on LCD while(1) // infinite loop { digital_reading = read_adc(); // capture current temperature reading delay_us(100); // 0.1ms delay for ADC stabilization temp = digital_reading * 0.4883; // convert reading to Celsius lcd_gotoxy(1,2); // point LCD cursor to col1 row2 printf(lcd_putc,"%2.1f C",temp); // print value on LCD if(temp>=THRES) output_high(LOAD); // Control Load else output_low(LOAD); delay_ms(1000); // 1 second delay between readings } } For any questions, do not hesitate to ask :) www.facebook.com/ELECTRONICS.LOVERZ