The circuit described here and its accompanying BASCOM software arose from the need to control the temperature in a laminator. The laminator does include its own temperature controller, but it was not suitable for the author‘s purposes (making printed circuit boards using a thermal transfer method ). The result (see circuit diagram) is based around an ATmega48 microcontroller with a 2-by-16 LCD panel and a rotary encoder. The base-emitter junction of an ordinary NPN power transistor in a TO220 package is used as the temperature sensor.
Although this technique is not often seen, it is far from new: decades ago Elektor published a digital thermometer design with an NPN transistor pressed into service as the sensor. The approach has the advantage of wide linear temperature range from –50 °C to +150 °C and the TO220 package is particularly convenient because it has a handy fixing hole and heatsink to allow good thermal contact. Note that the heatsink is electrically connected to the collector of the transistor, so it may be necessary to use an insulating washer.
The BD243C is wired as a diode by connecting its collector and base together and powered from the 5 V rail via a 4.7 kΩ resistor. A current of approximately 1 mA therefore flows through the diode. The voltage across the diode has a reasonably constant negative temperature coefficient of around –2 mV/K, and so the plot of voltage against temperature is reasonably straight. The voltage is measured using the ATmega48’s internal A/D converter using input ADC5 on pin 28. A point to note is that we can use the 1.1 V internal reference voltage to obtain good precision when converting the diode voltage drop, which is around 0.6 V. Not all AVR-series microcontrollers have the 1.1 V internal reference for the A/D converter, which should be borne in mind if modifying the design to use a different microcontroller. The set point for temperature control is entered using the rotary encoder in one degree steps.
Turn the encoder to the right to increase the set point, to the left to decrease it. It is possible to set upper and lower thresholds for switching. If the rotary encoder has a pushbutton function, this can be used to select between setting the upper and lower thresholds; if not, a separate button must be fitted. The display consists of the LCD panel and two LEDs. The upper line of the LCD shows the measured temperature and the lower line shows the current set point (upper and lower temperature switching thresholds). P1 adjusts the contrast of the LCD. The two LEDs show the state of the controller at a glance. If the blue LED (D2) is lit, the temperature is too low (below the lower switching threshold); if the red LED (D1) is lit, the temperature is too high (above the upper switching threshold); and if both LEDs are lit the temperature is just right (between the lower and upper switching thresholds).
Since at least one LED is always lit there is no need for a power indicator LED. The output of the controller is the logic level on pin 27 (PC4). The author used this to drive a solid state relay (SSR) in his application which in turn controlled the heating element in the laminator. The circuit diagram shows this as LED D3, which is intended to represent the LED in the optocoupler in the SSR. ISP connector K1 is optional and can be dispensed with if a ready-programmed microcontroller is used (see ‘Downloads and products’). It will then not be possible to calibrate the temperature reading, as this can only be done in the software using the ISP interface. However, for many one-off applications it will be sufficient to determine the upper and lower switching thresholds experimentally, including compensation for any error in the temperature measurement.
Details of the control process can be found by inspecting the BASCOM source code. Calibration of the temperature measurement, as mentioned above, is done by directly modifying the software. Remove the comment characters (‘) from lines 105 to 107 of the program, and comment out lines 108 to 110 by adding a single inverted comma at the start of each. The display will now show the conversion results from the A/D converter in the ATmega48. Immerse the sensor in a mixture of ice and water and wait until the reading stabilizes. Note down the conversion result (or take a number of results and average them for better accuracy). Now immerse the sensor in boiling water and repeat the procedure. Replace the number 546 in line 86 of the source code with the conversion result for the ice-water mixture.
Now subtract the conversion result for boiling water from the ice-water result and divide by 100: substitute the answer for the value 2.460 in line 87 of the source code. As indicated at the start, we assume in this calibration that the conversion result versus temperature relationship is linear. We can write this in the form y = mx + c, where c is the A/D conversion result at 0 °C (the intercept of the A/D conversion result axis) and m is the (negative) slope of the base-emitter junction voltage-temperature characteristic, calculated by dividing the difference between the conversion results at 0 °C and 100 °C by 100. These two numbers allow you map any conversion result into a corresponding temperature.