TempMaid is a simple temperature controlled power switch to control a mains-voltage appliance, with capacitive power supply (it powers itself from the mains without using a transformer). The purpose of this particular implementation is to trigger an appliance when temperature reaches freezing point. This device is a derivative of the MinuteMaid design. It’s all documented after the usual:
The information and methods described herein are provided “AS-IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED. Use the concepts, examples and information at your own risk. There may be errors and inaccuracies, that could be damaging to your devices. Proceed with caution, and although it is highly unlikely that accidents will happen because of following advice or procedures described in this document, the author does not take any responsibility for any damage claimed to be caused by doing so.
I’ll add an extra one since this particular design runs from and drives mains voltages:
BE VERY CAREFUL: POTENTIALLY LETHAL VOLTAGES ARE PRESENT IN THIS DEVICE WHEN IN USE.
This device is a proof of concept that presents several safety risks. PLEASE READ THE SAFETY NOTES CAREFULLY.
My design goals were relatively simple:
- KISS design
- Small footprint
- Can be built “by hand”
- Must run from mains, no separate PSU, with very low standby power drain
- Must be programmable
- Must be very easy to use (plug and forget)
- Must handle up to 10A loads
- Must be reasonably safe (again, who would have thought?)
Here’s the schematic of this design:
This design requires some explanation, but since the power-supply section is identical to the one found in MinuteMaid I will focus on the surrounding circuitry.
This designs uses a MCU which is interfaces with a digital thermometer, one LED for visual feedback, a power-relay to control the main load and the AC mains voltage to perform Zero Crossing Detection (ZCD). This combination allows for a variety of use cases, since the whole control logic is under the MCU’s supervision. An example program is provided below.
The brains of this design is a PIC10F320, which was chosen because it fits the bill in terms of features, costs, ability to run from a wide range of voltages, sufficient number of I/O, power usage and availability. Given the simplicity of the program I intend to run on it, I didn’t feel necessary to upgrade to the 322 version, but if your control logic requires it, it’s a drop-in replacement with double the memory size. This MCU offers 4 Input-Output pins, suitable for the design.
The low-voltage parts of the circuit operate on two distinct voltages: 24V for the “output logic” (relay and LED operation), and 5V for the “input logic” (MCU operation). Practical considerations require to keep the current drain of the control system as low as possible, within a few milliamps, especially on the +5V rail, for reasons that will become obvious later.
Due to the above power considerations, typical NPN transistors (BC547) are used in a switching configuration to control the LED and relay coil. The LED switch must drive a typical maximum of 20mA Ic, likewise for the coil (assuming 500mW coil in the worst case scenario, though this design uses a 250mW coil). Assuming a worst case transistor gain (hFE) of 100, this means that the base current required for the transistor to drive enough collector current is 0.2mA (assuming non-saturation). The suggested 10kΩ bias resistors R4 and R5 deliver 0.5mA from the 5V rail, which is plenty enough to ensure adequate switching.
Ballast resistors R8 and R9 provide two current levels for driving the LED, allowing for two levels of brightness, which is useful to convey information: under “low” level (through R9 only), the circuit is powered and in standby mode. When the PIC drives RA2 (pin 3) high, T1 switches on and the equivalent resistor driving the LED drops to about 2kΩ: the LED becomes much brighter. If preferred, R9 can be entirely ommited to have a classic “on/off” effect.
Note: the suggested resistor values provide a LED current of about 1mA in the low state and 12mA in the high state, which worked nicely with the yellow LED I used, while keeping current drain at very low values. You may want to experiment for your particular LED type. I’ve generally noticed that a 1:10 ratio from high to low gives good results, and that most LEDs will run at half their rated current with no significant loss in light output. If you don’t have a 24VDC supply to test from, you can experiment from 5VDC and then multiply the resistor values by 5, choosing the closest match in the standard series.
The digital thermometer is from the ubiquitous DS1820 family, which offer +/- 0.5°C precision. The design supports both the DS18S20 and the DS18B20, connected via 1-Wire bus to the PIC’s RA0 (pin 5). The thermometer is powered normally and draws about 1mA when active. The bus pull-up resistor R3 also limits the sink current to about 1mA.
A digital thermometer is used instead of e.g. a thermistor for simplicity and accuracy (no ADC conversion to manage, no calibration). The DS1820 was specifically selected because it offers a precision (+/- 0.5°C) which is suitable for the intended purposes.
In order to perform mains ZCD, and since the circuit is not isolated, RA3 (which is not an analog input pin) is directly connected via a current-limiting resistor R1 to the low-side of the capacitor. RA3 is also the PIC’s /MCLR pin and as such does not have a VCC clamp diode like the other inputs. Overvoltage is thus provided via an external clamp diode (D5, a standard 1N4148 which can be used since there isn’t a MOS passgate on this pin and this input can withstand up to 9V), while undervoltage protection relies on the PIC’s internal input clamp diode present on the /MCLR port. R1 is sized to satisfy several conditions:
- Ensure that the maximum clamp current of the internal diode (20 mA) is not exceeded,
- Ensure that the current flowing will not affect regulation of the +5V rail (when D5 conducts, the excess current will be sunken by D6),
- Ensure that the time-constant of the resulting RC circuit (taking into account the c.5pF PIC input capacitance and 1N4148 similar Cd) remains sufficiently low to not induce too much of an angle error on the actual detection.
Control power requirements
The above allows us to compute the maximum power usage of the control logic, which will be necessary for the next step:
- For the 5V rail, about 3mA:
- < 1mA for the PIC itself
- 1mA for the DS18 (active or bus exchanges)
- 0.5mA for each of the BC547 triggers
- For the 24V rail, about 22mA:
- 12mA (LED “high” current)
- 10mA (250mW relay coil)
We can thus see that the design requires about 25mA to run, which we’ll round up to 30mA to have some leeway. This is where we can start explaining the leftmost part of the schematic.
The power supply is a fairly typical capacitive power supply (see AN954 for a primer), the only oddity being its capacity to offer two regulated DC power rails.
I reused the one I designed for MinuteMaid, the same caveats apply. I only made minute changes, specifically:
- The bleeder resistor R6 is now 2.2MΩ to further reduce leakage, it will still bring the capacitor’s voltage down to safe levels in a couple seconds.
- The soft-starter resistor R2 is now 100Ω, again to reduce losses
For all its shortcomings and deficiencies, this type of power supply is cheap and easy to implement. As for why not use a basic wall wart, two reasons: first it would complicate ZCD (requiring opto isolation to boot, increasing costs and PCB real estate usage) and second it would clutter the use of this device, which is aimed at being inserted between the mains power plug and the appliance being controlled, without further fiddling.
Remaining bits of interest
This pretty much sums it up. D8 is a typical flyback diode, to protect the circuit from coil kickback. VR1 is a varistor used to protect the relay from kickback from inductive loads (the same phenomenon that the flyback diode protects against, except since this part of the relay drives alternating current under mains voltage, a single diode is not suitable and a TVS is overkill). F1 is a polyfuse, which will trigger if anything goes wrong in the circuit. K1 is a 250mW, 24VDC power relay rated for 10A under 240VAC. This enables driving 2kW loads, which covers a useful range of applications.
By design, the “power supply” of this design will not provide a very stable voltage, especially at the onset. It will take time to converge towards the expected +24V and +5V, but it nonetheless reaches operational levels in about 0.5s.
Here’s a very simple two-sided, hand-routed layout that fits on credit-card-sized PCB.
- The Part list.
This PCB will nicely fit in a 90x90mm junction box. I highly recommend that the mains be connected via a fuse holder between mains “Live” source (coming from the wall socket) and the PCB’s “L” pin. This fuse holder will hold a 10A fuse, to protect the relay and the user should anything go wrong. Once again, C3 must be Class X2, rated for 275VAC or more. These capacitors are designed to ensure safety in the event of a catastrophic failure. R6 is meant to be mounted under the capacitor (these large caps can normally accomodate a small resistor between their base and the PCB: there is enough clearance). The polyfuse F1 should ideally be mounted “raised” above the PCB surface for optimal cooling (this really is more about nitpicking than anything, though :).
Due to the potentially significant current flowing in the L and Lout pins and circuit tracks, I recommend that a generous amount of solder tin be layered over both those tracks from the plug to the lugs of the relay.
There is no mention of GND on the schematic, but instead there is a V0 reference. This is because this device DOES NOT use an isolated power supply, and this has several consequences:
- NEVER TOUCH ANY PART OF THE CIRCUIT WHEN CONNECTED TO MAINS POWER,
- ONLY use this device INSIDE an electrically isolated container, such as a plastic junction box,
- ALWAYS use an electrically isolated switch rated to match MAINS voltage for the push-button.
DANGER: if the Neutral/Live 230V input connections are inverted (e.g. due to the misorientation of the input plug in the socket), the following will happen:
- The low voltage section of the circuit WILL FLOAT ABOUT 200VAC above actual 0V ground reference level,
- The controlled appliance will be PERMANENTLY CONNECTED TO THE LIVE POLE, EVEN WHEN TURNED OFF.
The device and appliance will still operate correctly, but the risk of electrical shock is increased.
In any case, this bears repeating: NEVER TOUCH ANY PART OF THE CIRCUIT WHEN IT IS CONNECTED TO MAINS. This device is only proposed as a proof of concept and should not be used by inexperienced personel.
This design works well, and is quite versatile, provided that one writes an adequate program for the PIC. Here’s a sample program that implements a 1°K-hysteresis anti-frost thermostat: the relay will be latched when the temperature measured by the DS18 drops below 1°C and it will be released when temperature rises above °C. The LED will reflect the state of the device as follows:
- Permanent low output: ZCD detection failure (no operation, relay is released)
- 4 pulses: DS18 failure (no operation, relay is released)
- 2 pulses: normal operation, relay latched
- Slowly alternating high/low: normal operation, relay released
Sample timer program
Pictures of a working prototype
I used an illuminated switch (and a slightly different PCB layout).