Temperature sensor

The temperature sensor module is based on the DS18B20 sensor IC. It requires a special software routine to download the measured temperature. If you want a simpler device for sensing temperature, you could use the thermistor module [23]. The advantage of the DS18B20 is that it is calibrated and supplies the temperature in degrees Celsius. Whereas as the thermistor module only provides an uncalibrated analogue signal.

Temperature sensor PCB layout
Circuit details

Temperature sensor design symbol

Temperature sensor circuit details
Although this circuit outputs its data digitally, it is not possible to test it as you would test other digital sensors e.g. the push button. That is because the sensor outputs its measured temperature serially when it is interrogated by the PIC.
Programming
To download the temperature of the sensor, use the ReadTemp box . . .

Set the ReadTemp box properties according the number input used and the variable name you want to store the temperature in. For example, if you plug the sensor into D1 and want to store the temperature in variable A use these settings. . .


Of course, once the temperature has been downloaded you will want to do something with the reading. Here are a couple of possibilities:
Example 1
You could use the temperature sensor as part of a thermostat. Suppose a temperature sensor is connected to input D0 and a relay (connected to a heater) is connected to output Q0.

picXplorer thermostat
When the measured temperature is below a set value (determined by the number stored in C), a heater (controlled by Q0) is switched on. When the temperature rises above the set temperature, the relay (and hence heater) switches off.

Flowchart for a thermostat
In practice, real thermostats use two different temperatures to control the heater switch off and switch on temperatures. This is to avoid repeatedly switching the relay switch on and off when the temperature hovers on the set temperature boundary causing it to fail prematurely. The difference between the two temperatures as called the hysteresis of the system. The flowchart could b modified to include hysteresis.
The value of C could be set by a preset potentiometer connected to another input. This avoids having to re programme the PIC in order to change the set temperature. See preset potentiometer. Alternatively, the set temperature could be set digitally using switches. See octal switch.
Example 2
The measured temperature can be displayed on an 8 LED bargraph display. As only 8 outputs are available on a 20 pin PIC, only a limited range of temperatures can be shown. The following programme displays the temperature in the range 17ºC to 24ºC. Temperatures outside this range flash the end LEDs at a rate set by the Wait box.
