Digital Thermostat with LED Temperature Display
(Project added 30th August 2006. Last updated September 2007)
I needed to replace two old, unreliable thermostats for controlling the heating and cooling for a large garden shed.
Commercial basic digital thermostats are available quite cheaply, but some lack the ability to control heavy loads or have the extra features that I require for saving energy when the door is often left open or to indicate temperature being out of range etc.
I like the PIC18F1320 microcontroller used in my previous project – so decided to use it again in a very similar design to drive three multiplexed LED displays and read the temperature from a Dallas/Maxim DS18x20 “1-Wire” digital sensor.
- Simple,cheap,compact design, few components, no surface-mount types.
- Uses an accurate digital sensor to avoid the need for calibration.
- Low power consumption
- Uses a modern Microchip PIC 18F1320 microcontroller
- Temperature sensor is accurate to +/- 0.5 degree Centigrade with 0.1 degree C or F display resolution over most of the range.
- Thermostat is easily adjusted in +/- 1 degree Centigrade or Fahrenheit intervals (all settings saved in memory)
- Adjustable thermostat cycle delay to help reduce wear on heater/cooler
- Adjustable thermostat temperature hysteresis to reduce heater/cooler wear.
- Facility to automatically turn-off the heater/cooler while a door is left open (For Energy saving)
- Under/Over temperature alarm LED indication
- Selectable Celsius or Fahrenheit temperature display
- Minimum and Maximum temperatures are logged for display.
Display of temperature between -55 and +124 deg C (-67 to 255 deg F)with 0.1 degree resolution between -10 and 100 degrees.
Thermostat settings between 1 and 100 deg C (34 to 212 deg F.)
The microcontroller communicates with a Dallas/Maxim “1-wire” digital temperature sensor (in fully powered mode).
It has been successfully tested with DS18B20 and DS18S20 types.
The choice of sensor makes no difference to the temperature display resolution here. If a DS18S20 device is used,the software uses the “Count_remain” variable to increase it’s resolution to 0.1 deg centigrade.
The controller drives the three (high efficiency) LED single digit common cathode type display segments through series 510ohm resistors to help limit the current to remain within the 25mA per pin drive limit, together with the multiplexing action which effectively reduces the average current.
The multiplex is the same “Charliplexed” circuit as used in my previous project – this saves two pic port pins for other uses. Using the on-chip oscillator again frees-up the two pins normally used for connecting a crystal to be used as ports instead.
There are two tactile (or panel mounted) pushbuttons for configuration – a “SET/DOWN” button to enter config mode and reduce thermostat temperature and an “UP” button to increment the config values or temperature.
The circuit is powered from a 12V dc supply and the low power 78L05 5V regulator supplies the microcontroller and display. The heating/cooling output is via a 2N7000 Mosfet transistor (rated for up-to 200mA) to control a relay connected to the unregulated 12V supply.
The relay is not mounted on the circuit board because I intend to use one with heavy-duty mains contacts and also to keep the mains wiring well away from the microcontroller etc.
The red LED to indicate out of range temperatures in this application will probably be upgraded to a high brightness type and eventually fitted outside of the case (fixed to the inside of the shed window viewable from the house).
The door switch feature is used with a magnet operated switch that is made when the door is closed.
When power is first applied, the display shows all 8s for a few seconds,then shows the firmware version.
It then displays the current temperature and updates it about once a second. A short press of the “SET/DOWN” button shows the thermostat setting in degrees centigrade. Now, each press of the DOWN or UP button decreases or increases the thermostat temperature setting a degree at a time. (the new setting is saved in eeprom).
If there are no further button presses for six seconds, the display reverts back to showing the current temperature again.
If the SET/DOWN button is initially held pressed for more than three seconds,the settings options are available.
Each option (shown in red) is accessed by pressing the set button.
- C-H—-This option is to select Cooling or Heating mode (very important!)
- dLy—- Cycle delay time (0-15 minutes), Determines how long the thermostat must wait after each on/off trigger. (Useful to prevent wear on heater/cooler)
- Hys—- Thermostat temperature hysteresis (0-5 deg Centigrade) (Higher hysteresis reduces wear on heater/cooler switching but reduces temperature stability)
- odo—- Open Door Override (0=off, 1-10mins) Number of minutes with a door open before turning-off the heater/cooler. (for energy saving)
- HiA—- High temperature alarm threshold (10-100 deg C or 50-212 deg F) (Alarm LED lights if exceeded)
- LoA—- Low temperature alarm threshold (0-100 deg C or 32-212 deg F) (Alarm LED lights if exceeded)
- C-F—- Select Centigrade or Fahrenheit mode.
The minimum and maximum temperatures logged since power-on can be displayed by a short press of the UP button.
If the UP button is held pressed for over 4 seconds or the power cycled, the logged temperatures will be cleared.
The firmware for this project is written in assembler language.
The microcontroller currently determines if a DS18S20 or DS18B20 sensor is being used.
(It should also work with the old original DS1820 sensors (but with only 0.5 deg display resolution), although I do not have one to test it with.
Each temperature reading is CRC validated. I have experienced no errors with the readings, but decided the CRC checking was worth implementing as a safeguard.
You will require a PIC programmer compatible with the PIC18F1320 microcontroller.
If you don’t have one – there are various articles on the web for constructing a simple serial port “JDM” type programmer. Good Freeware programmer software is easily available – such as “IC-Prog” or “WinPic800”.
I shall update the file version here as features are added/bugs fixed etc.
The ASM source code for projects or kits is not available.
The circuit is simple enough to construct on stripboard, Or you may wish to try the double sided pcb layout design provided.
The microcontroller and displays should be mounted in sockets. A socket for all three displays can be made by carefully cutting-off the ends off a 40 pin ic socket.
If you decide to make the double sided pcb,the “toner transfer” method can be used (search for instructions on the web) – you will need to position both sheets on the pcb very accurately to achieve good results.
The four corner holes also act as alignment marks in the pcb artwork and the topside sheet is already mirrored ready for printing.
I used a bright light to help align the two sheets together accurately, then tape the sheets together and carefully slide in a pcb that is a few centimeters larger than required. (it can be cut-down to the exact size later and makes the toner transfer easier).
PCB vias can be made with short lengths of wire carefully soldered between pcb sides.
Many component leads will require soldering on both sides of the pcb – you need to leave a small gap between sockets and the board to allow access to the topside pads for soldering.
I have now installed it into a case and it is ready to be put into service. The case and power supply components have been re-used from a previous project.
I decided to attach the temperature sensor externally via a short lead because even though I drilled ventilation holes in the case, the readings inside it were slightly higher.
The photo above shows a 12v supply transformer and a small stripboard for the DC bridge rectifier, 200mA fuse and 1000uF smoothing capacitor.
The black object at the rear is a 12V relay with heavy duty mains contacts.
All high voltage connections must be properly insulated and the metal case and transformer must be earthed.
The transformer is also protected by a separate mains panel mounted 125mA fuse (the yellow insulated object on the left). The output from the relay is cabled out through grommets to an external mains 1-way trailing socket.
The front panel was made by drilling and making cutouts in the case then using a graphics design program to print a black paper template to fix over it. Finally, a piece of clear plastic sheet was cut and drilled to fit over that and the area that fits over the display was coloured red using a medium indelible marker pen to act as a display filter.
Hopefully it should work ok when you have assembled it and you will not need to read this section!
On power-on, it should show .8.8.8 on the display.
And both of the indicator leds and the relay should also operate for 2.5 seconds.
If not all digits, leds or segments light, check all the connections carefully, looking for dry joints or missing connections.
If no digits or leds light and the relay does not operate, check that the chip is actually getting 5 volts power (pin 14).
If the indicator leds and relay operate but the display is blank – check the display connections.
If either indicator led does not light – check their polarity.
If the green relay led lights but the relay does not operate – check the relay connection.
If still no success, use a logic probe or a multimeter with logic indication to look for hi/lo pulsing on pin 18.
If no pulsing is found, check the connection to the reset pin (pin4) and check R4 connection.
If still no activity, check that the chip has been programmed ok (use the verify option on your programmer software).
If there is a problem with the temperature sensor chip, the display may show a fault indication Flt – NoT
This means that either the sensor is “Not” connected or there is a wiring fault or faulty sensor.
Check that the sensor is connected correctly, has a 5 volt supply and also check the connections to the 4.7K resistor R1 and pin 8 of the microcontroller.
If the fault message is Flt – Lo this means that the sensor data wire is either shorted to ground or the pullup resistor (R1) is not connected.
If the fault message is Flt – rES this means that the sensor was detected, although it took to long to respond to a reset command,
This could be caused by a very long cable length to the sensor, too much capacitance in the cable (wrong type of cable) or some sort of interference affecting the readings.
If you are extending the cable length to the sensor, use a twisted-pair type such as CAT5
Id – Err means that it cannot read a valid sensor ID – may be due to use wiring that is too long, causing data error or by not using a DS18x20 type of chip.
After the startup diags have completed ok, it displays the firmware number for 2 seconds and then begins normal temperature display.
During normal operation if either a CrC – Err or Rd – Err is displayed – check that there is a good connection to the sensor, cable length is not excessive and that there is no nearby interference to cause CRC errors.
Changes to sensor problem detection so that it does not require a manual reset after detecting a sensor error. Small timing improvements for more reliable operation when using a very long cable to the sensor (tested with a 15 Meter cable).
Added more temperature sensor fault indications in case of any problems with the sensor connection etc. and improved the sensor communications timing.
Decided to add a few software features now as the cooling thermostat has not been required much recently due to a very cool summer so far this year
19th October 2006.
I installed it in the shed about a month ago with the heating temperature set to 18 degrees, 1 degree hysteresis and 1 minute cycle delay.
So far it is working very well and the “open door” sensor is saving energy wastage.
To Do List
I may add a few more features later –