# ### Site Tools

한국어

cubloc:temperature_sensor:index

# Temperature Sensor

There are many uses for devices that sense temperature. Refrigerators, heaters, air conditioners, automobiles, etc.. all make use of devices that sense temperature.

There are several different kinds of temperatures sensors. There are PT100, NTC, and PTC thermistors, and other chip-type sensors such as the DS1620.

We will take a look at the NTC thermistor and interface it with the Cubloc. The NTC thermistor is a temperature-sensitive resistor. Depending on the temperature, the value of resistance will change. By reading the value of this resistance, we can determine the temperature.

A common NTC thermistor resembles a diode. With this thermistor, we can sense temperatures between -30 and 250 degrees Celsius. You can acquire an R-T (Resistance – Temperature) conversion table from the maker of the thermistor. The following is a diode-type 10Kohm NTC thermistor R-T conversion chart and table. For connecting the sensor to the Cubloc, please refer to the following circuit diagram. To protect against voltage surges, a zener diode is recommended, especially if the thermistor is attached to a long probe wire. As you can see in the circuit diagram, we will be using an ADC (Analog-toDigital) converter to read the voltage across the sensor. The A/D converter will convert the voltage into a value between 0 and 1024.

The most important part of this application note is the following table which converts the temperature and voltage to an A/D value between 0 and 1024. (Only some of the temperatures are shown.) ```'
' 10K DIODE TYPE
'
Const Device = cb280

Const Integer TH_TABLE = (992,990,989,987,985,983,981,979,977,975,
973,970,968,965,963,960,957,954,951,948,
945,942,938,935,931,927,923,919,915,911,
907,902,898,893,888,883,878,873,868,862,
857,851,845,839,833,827,821,815,808,802,
795,788,781,774,767,760,753,746,738,731,
723,716,708,700,692,684,677,669,661,652,
644,636,628,620,612,604,596,587,579,571,
563,555,547,538,530,522,514,506,498,491,
483,475,467,460,452,445,437,430,422,415)
Dim a As Integer,b As Integer

Do
If b > 990 Or b < 400 Then
Debug "Out of Range" 'Check short or open th.
End If

For a=0 To 100
If b > TH_TABLE(a) Then Exit For
Next

Debug Dec a,cr

Delay 500
Loop```

By using the TADIn command for AD conversion, the Cubloc will automatically calculate the average of 10 A/D conversion reads for more precise results. The sample program shown here will be able to sense between 0 and 100 degrees. A minor modification to the code would allow a larger temperature range.

The formula for acquiring the A/D conversion value from the R-T table is as follows: THR is the resistance value. 1000 is for a 1K Ohm resistor and 5 is for 5 volts. The 10 bit A/D converter of the Cubloc will return a value between 0 and 1024. Therefore, to get the A/D value, you must multiply the result, V, by 204.8. A chart can be made by plotting this formula in a spreadsheet. 