Overview of NTC Thermistor
A thermistor is a type of variable resistor whose resistance changes with temperature.
For PTC (Positive Temperature Coefficient) thermistors, the resistance increases as the temperature rises. In contrast, for NTC (Negative Temperature Coefficient) thermistors, the resistance decreases as the temperature increases.
Thermistors are commonly used in applications such as current limiting, temperature sensing, and overcurrent protection. The change in resistance due to temperature variations can be measured to determine the temperature.
By connecting the thermistor in series with a fixed resistor to form a voltage divider, the temperature can be determined. As the temperature changes, the resistance of the thermistor changes, which in turn affects the voltage across the voltage divider, providing a measurable change in voltage corresponding to the temperature.
For more information on thermistors and their use, refer to the “NTC Thermistor” section in the sensors and modules topic.
To learn more about using the ADC (Analog-to-Digital Converter) in the PIC18F4550 microcontroller, refer to the “ADC in PIC18F4550” section in the PIC Inside series.
Connection Diagram of NTC Thermistor with PIC18F4550
Here, we used a 10k NTC thermistor
NTC Thermistor Interfacing with PIC18F4550
NTC Thermistor Code for PIC18F4550
/*
Thermistor Interfacing with PIC18F4550
http://www.electronicwings.com
*/
#include <pic18f4550.h>
#include <string.h>
#include <stdio.h>
#include "LCD_16x2_8-bit_Header_File.h"
#include "PIC18F4550_ADC_Header_File.h"
#include <math.h>
#define ohm 0xf4
#define B_coefficient 3950.00 /* B coefficient of NTC Thermistor*/
#define Room_temperature 25.00
#define Series_Resistance 10000.00
float Get_Temperature(int);
long NTC_Resistance;
void main(void)
{
float Temperature;
OSCCON =0x72;
LCD_Init(); /* initialize LCD16x2 */
LCD_Clear(); /* clear LCD */
ADC_Init(); /* initialize ADC */
char Temperature_buffer[20],Resistance[20];
int Analog_Input;
while(1)
{
Analog_Input = ADC_Read(0); /* store the analog data on a variable */
Temperature = Get_Temperature(Analog_Input);
sprintf(Temperature_buffer,"Temp: %.2f%cC ",Temperature,0xdf); /* convert integer to ASCII string */
LCD_String_xy(0, 0, Temperature_buffer);
sprintf(Resistance,"Res: %ld %c ",NTC_Resistance,ohm);
LCD_String_xy(1,0,Resistance);
MSdelay(1000); /* wait for 1 second */
}
}
float Get_Temperature(int analog_value)
{
float Thermistor_temperature;
analog_value = ADC_Read(0); /* store adc value on val register */
/* calculate the NTC resistance */
NTC_Resistance = ((1023*Series_Resistance/analog_value) - Series_Resistance);
Thermistor_temperature = log(NTC_Resistance); /* calculate natural log of resistance */
/* Calculate Temperature using B parameter Equation */
/* 1/T = 1/T0 + ((1/B_coefficient)*log(NTC_Resistance/Series_Resistance)) */
Thermistor_temperature = (1.0/(Room_temperature + 273.15))+
(1.0/B_coefficient)*log(NTC_Resistance/Series_Resistance));
Thermistor_temperature = (1/Thermistor_temperature) - 273.15; /* convert kelvin to °C */
return Thermistor_temperature;
}