What is an RTD sensor


An SMD 0805 platinum temperature sensor is a precision Resistance Temperature Detector (RTD) that measures temperature by exploiting the predictable change in platinum’s electrical resistance with temperature. Compliant with DIN EN 60751, it offers excellent stability and near-linear response over a wide range (−50 °C to +170 °C), making it ideal for accurate temperature monitoring in compact electronic designs. Its technology ensures high repeatability and reliability, commonly used in industrial, automotive, and consumer electronics applications.


Interfacing the Sensor with Roboteq


Calculating the Sensor's Resistance


The SMD 0805 platinum RTD is nearly linear over its operating range, but not perfectly—its resistance follows the Callendar–Van Dusen equation. For practical purposes between −50 °C and +170 °C, the curve is close enough to linear that simple conversion works well. To read it with a device, you typically use a voltage divider: connect the RTD in series with a known pull-up resistor to a stable supply voltage. The RTD voltage is then measured by the ADC. As the RTD’s resistance increases with temperature, the voltage across it changes proportionally, exploiting this effect for temperature calculation.




Figure 1: Calculating the sensor resistance through analog Input measurement



Calculating the Temperature


The RTD sensor provides a temperature coefficient of resistance (TCR), which indicates how much the sensor’s resistance changes per degree of temperature. This value is expressed in parts per million per Kelvin (ppm/K). For example, a TCR of 3850 ppm/K means the resistance changes by 0.00385 per Kelvin relative to its reference resistance.


By knowing the TCR parameter, the sensors nominal resistance (at 0 °C) and the sensors actual resistance, we can calculate the actual temperature. 






Figure 2: Calculating temperature from sensor specs and measured resistance



Calculation Example


Below we will calculate the temperature by knowing the sensor's resistance, so we can validate the analog input readings and calculations.




Figure 3: Calculation Example


MicroBasic Implementation


A MicroBasic script can be used to read the analog input and calculate the motor temperature. 


The script can be parametrized as follows:


ParameterDescription
PULLUPPull-up resistor resistance in Ohms
R0
Sensor Resistance at 0°C
TCR
The sensor PPM/K (points per million per Kelvin)
V_SUPPLY
The voltage supplied to the divider, in mV
INPUT_1
The analog input that sensor 1 is connected. MUST be set to 0 if a sensor is not used on that channel otherwise an error will be triggered. 
INPUT_2

The analog input that sensor 2 is connected. MUST be set to 0 if a sensor is not used on that channel otherwise an error will be triggered. 
VAR_1 
The user VAR to store temperature 1
VAR_2
The user VAR to store temperature2
LOOP_TIME
The script period in ms. MUST NOT be zero. 


The script example follows:


'________________Pt1000 RTD Temperature Sensor via Analog input________________

 

'DISCLAIMER

 

'Script is provided only as an example. It has not been extensively tested and user must validate and use it at their own risk. 

 

' DESCRIPTION: 

 

' Script reads an analog input voltage, calculates the RTD sensor resistance and then temperature, using the RTD sensor Specs.

' The calculated temperature is stored to a user VAR. Sensor specs are configurable by the user. RTD sensor requires a pullup

' for its operation. Preferably, choose a pullup with a value equal to the sensor's resistance in the midpoint of the temperature range.

 

option explicit

 

' ------------ PARAMETRIZE THE SCRIPT BELOW: 

 

'Sensor Specs

 

#define PULLUP 1000 'Set here the pullup resistor value in Ohm.

#define R0 1000 ' Pt1000 nominal resistance at 0°C

 

' -> Below is defined the sensor TCR value, measured in PPM/K (points per million per Kelvin). 

' (!) This value indicates the resistance increase per million of its nominal value per degree of Kelvin. 

 

#define TCR 3850 'The sensor PPM/K (points per million per Kelvin). 

#define V_SUPPLY 5000 'The voltage supplied to the voltage divider in mV. Use 5000 for 5 V.

 

#define INPUT_1 'The analog input to use for the temperature measurement of motor 1. Use 0 to disable

#define INPUT_2 'The analog input to use for the temperature measurement of motor 2. Use 0 to disable

#define VAR_1 'The user Var to store temperature 1

#define VAR_2 'The user Var to store temperature 2

 

#define LOOP_TIME 1' The temperature update rate - as well as the script refresh period - in milli seconds.

 

' ----------- FUNCTION STARTS HERE. DO NOT MODIFY

 

' Variable declarations

 

dim V_RTD_1 as integer 'The voltage accross the sensor 1, measured by first analog input

dim V_RTD_2 as integer 'The voltage accross the sensor 2, measured by second analog input

 

dim R_RTD_1 as integer 'The calculated resistance of sensor 1

dim R_RTD_2 as integer 'The calculated resistance of sensor 2

 

dim temp1 as integer ' Calculated temperature of motor 1

dim temp2 as integer ' Calculated temperature of motor 1

 

'Variables initialization

 

V_RTD_1 0

V_RTD_2 0

R_RTD_1 0

R_RTD_2 0

temp1 0

temp2 0

 

if (PULLUP 0or (R0 0or (TCR 0or (V_SUPPLY 0or (VAR_1 0or (VAR_2 0or (LOOP_TIME 0'Check invalid values that can result also in script crash.

 

    print("Improper configuration. Program will terminate \n")

    terminate

 

end if

 

top:

 

if (INPUT_1 <> 0'If Analog input 1 is used

 

    V_RTD_1 GetValue(_AI,INPUT_1)     ' Read Analog input 1 voltage in mV

 

    if (V_SUPPLY V_RTD_1'Check correct values and also avoid dividing by zero. 

    

        print("Posible connection error. Analog input voltage equals the supply voltage. Ensure correct connections. Program will terminate\n")

        terminate

        

    elseif (V_RTD_1 50)

    

        print("Posible connection error. Analog input voltage equals zero. Ensure correct connections. Program will terminate\n")

        terminate        

        

    else

    

         R_RTD_1 = ((PULLUP V_RTD_1) / (V_SUPPLY V_RTD_1)) ' Compute RTD resistance. 

        ' Compute temperature (linear approx) in °C.      

        temp1 = ((R_RTD_1 R0) * 10000) / (R0*TCR/100)   'Divide by 1 million to convert PPM/K to P/K.     1000000 broke to 10000/(a)/100 to avoid integer overflow.   

        SetCommand(_VARVAR_1temp1)  ' Output temperature i expressed in degrees x 10 (meaning that 11.1 degrees of Celsius is reported as 111. 

        print ("Resistance 1: "R_RTD_1,"\tTemperature 1: ",temp1)

    

    end if

 

end if

 

 

if (INPUT_2 <> 0'If Analog input 2 is used

 

    V_RTD_2 GetValue(_AI,INPUT_2)     ' Read Analog input 2 voltage in mV

    

    

    if (V_SUPPLY V_RTD_2'Check correct values and also avoid dividing by zero. 

    

        print("Posible connection error. Analog input voltage equals the supply voltage. Ensure correct connections. Program will terminate\n")

        terminate

        

    elseif V_RTD_2 50)

    

        print("Posible connection error. Analog input voltage equals zero. Ensure correct connections. Program will terminate\n")

        terminate        

        

    else

    

         R_RTD_2 = ((PULLUP V_RTD_2) / (V_SUPPLY V_RTD_2)) ' Compute RTD resistance. 

        ' Compute temperature (linear approx) in °C.      

        temp2 = ((R_RTD_2 R0) * 10000) / (R0*TCR/100)       'Divide by 1 million to convert PPM/K to P/K.     1000000 broke to 10000/(a)/100 to avoid integer overflow.   

        SetCommand(_VARVAR_2temp2)  ' Output temperature i expressed in degrees x 10 (meaning that 11.1 degrees of Celsius is reported as 111. 

        print ("Resistance 2: "R_RTD_2,"\tTemperature 2: ",temp2)

    

    end if

    

end if

 

    Wait(LOOP_TIME'The Loop 

    print("\n")

    

goto top