Temperature Sensor - Thermistor - PSoC

It's a simple temperature sensor based on a thermistor and PSoC.

IntermediateProtip4 hours5,172
 Temperature Sensor - Thermistor - PSoC

Things used in this project

Story

Read more

Schematics

PSoC Creator Schematic

Code

PSoC Creator Code

C/C++
The Project
#include <project.h>
#include <stdio.h> // Library for sprintf to work

int main()
{
    int32 vTherm,vRef; // Corresponding variables to the reference voltages and thermistor
    int32 Termresis,Termtemp; // Corresponding variables to resistance and temperature of thermistor
    float TermistorResis,TermistorTemp;// variables for correcting format for temperature and resistance
    char str[12];// Variable for print
    
    // Initialization of components
    CyGlobalIntEnable; 
    ADC_Start();
    LCD_Start();
    AMux_Start();
    Opamp_1_Start();
    
    // Print permanent message
    LCD_Position(0,0);
    LCD_PrintString("Ejemplo de termistor");
    LCD_Position(1,0);
    LCD_PrintString("NTC KY-013");
    

    for(;;)
    {
        //Channel 0 (Thermistor)
        AMux_FastSelect(0);//Selecting channel 0 of the AMuX  
        ADC_StartConvert();//Beginning ADC conversions
        ADC_IsEndConversion(ADC_WAIT_FOR_RESULT);//Waiting for result
        vTherm = ADC_GetResult32();// Saving result in the variable Vtherm
        ADC_StopConvert();// Stop ADC conversions
        
        //Channel 1 (Resistor Reference)
        AMux_FastSelect(1);//Selecting channel 1 of the AMux
        ADC_StartConvert();//Begin ADC conversions
        ADC_IsEndConversion(ADC_WAIT_FOR_RESULT);//Waiting for result
        vRef = ADC_GetResult32();// saving result in the variable Vref
        ADC_StopConvert();// Stop ADC conversions
        
        /**********************************************************************
        Once obtained the two values of voltage proceed with obtaining the 	        
		values of resistance and temperature for thermistor
        ***********************************************************************/
        
        Termresis = Thermistor_GetResistance(vRef,vTherm);  // Getting resistance value from the thermistor
        Termtemp = Thermistor_GetTemperature(Termresis); // Getting temperature value thermistor
        
        TermistorResis=Termresis/1000.000;// Correction of the format for resitencia
        TermistorTemp = Termtemp/100.00;// Correction of the format for thermistor
        
        LCD_Position(2,0);
        LCD_PrintString("Resistance: ");
        // Using Sprintf to pass from float to char to be printed on LCD
        sprintf(str,"%.3fK ",TermistorResis);
        LCD_PrintString(str);// The value of resistance is printed 
        
        
        LCD_Position(3,0);
        LCD_PrintString("Temp: ");
        // Sprintf to pass from float to char to be printed on LCD
        sprintf(str,"%.2f.C  ",TermistorTemp);
        LCD_PrintString(str);// The value of resistance is printed
        
        
        
        CyDelay(300);// // A little delay so that the measurements of the sensor are done every 300mS
    }
}

Project Archives

Credits

Brayan Andrés Bermúdez

Brayan Andrés Bermúdez

9 projects • 19 followers
Edgard Daniel Ucha

Edgard Daniel Ucha

3 projects • 4 followers
An electronic engineer, hardware designs,

Comments