
Here is a reference design from Microchip describing how to built a Light dimmer with a PIC12C508 and a few discrete components. The circuit uses a simple zener voltage doper, to drop the voltage from mains to 5V required by the PIC. Watch out, there is live mains voltage involved.
This reference note describes an application where the use of a microcontroller was not reviously economically feasible for any but the highest end products: lamp dimming.

For those of you that want to experiment with circuits like this may I suggest that you get a nice AC-AC power adapter. A lot of halogen desk lamps will come with one that goes from mains to 12V (Ikea for the win!) with 1 – 2 amp. You can easily play with that and it won’t be nearly as unsafe as using mains voltage.
Speaking from experience, getting shocked with 240V is not a pleasure …
This to me is an extremely poor application note, I’m surprised Microchip would produce such a thing which I would deem as unsafe. I haven’t read all the details, but I’ve seen enough to show me that the engineer who wrote this doesn’t know a thing about mains applications. Even for a 110V (RMS) supply the 1N4001 is a very poor choice, as the maximum reverse voltage is 50V. They are using C3 as a dropping element, but any spikes (which can be very frequent on mains lines) will have a fast risetime and will be coupled directly to the two diodes (via the 47 Ohm resistor) and the one which is reverse biased will likely eventually fail, going short circuit and then perhaps overloading the 47 Ohm resistor (I haven’t done the maths, but in any case spikes are random). C3 is specified as a 200V device and anybody who works on mains stuff professionally will tell you that anything direct off line needs to be suitably rated for main voltages, where the devices have been tested under severe spike and surge conditions, such as X2 and Y rated mains caps. These are more commonly paper caps due to their excellent self healing abilities. Good quality (and suitably mains rated) polyester caps are also sometimes used. You may think a cap rated at 630V might be suitable, but in mains application that’s not the case, in fact I’ve seen examples where 630V ‘greencaps’ (Metalised Polyester) have gone up in smoke and caught fire when used on 240V mains applications in very similar circuits.
Even on 110V, you need to be using mains rated caps and mains rated resistors, in fact *ALL* of the components really should to be mains rated, even those running in the ‘low voltage’ area (you can get away with some leeway on some components, but you need to be very careful), because the whole circuit needs to be considered as being ‘live’ – Understand there is absolutely no isolation from the mains with this circuit and so needs to be considered as all being connected directly to the mains. It is not uncommon to find the Active and Neutral connections swapped, especially in older installations and in those cases your whole circuits ‘ground’ (should not be called ground) will not be at Neutral at all, but rather at whatever your mains voltage is!
The app note actually states ‘Generic’ resistors, even for the 47 Ohm connected directly the line, which is just downright disgraceful. You should ensure resistors that are specifically rated for the mains voltage *and* any likely spikes and in practical terms this means high voltage rated caps.
The diodes should be at least 1N4004 and more likely 1N4007
Also consider the switches, these potentially could be connected *directly* to the Active (live) if the Neutral and Active are transposed and in that case they have to be suitably rated also, otherwise you could end up killing somebody. I haven’t looked at their specks, but judging by the rest of the circuit, I doubt any consideration of this has been taken into account.
If you are planning on building this, please play it safe. What Bert said above sounds good, play with a low voltage circuit on the output of a suitable *isolated* transformer (a variac does not isolate by the way) and just adjust the component values as required.
I totally agree with Sleepwalker!
We have test built a similar RC-power supply to power a PIC and a 48 V relay. Instead of the X2-rated plast film capacitors we usually use, the space was really constrained so we had to use high voltage ceramic caps instead. The series resistor was a wirewound one with 3 Watts rating and 500% short time overload capacity with sufficient voltage rating. Guess what, it burned with an open flame during the final burst tests.
One key solution to filter out voltage transients was to lower the voltage in several step, all with separate filtering. The relay was powered at 48 V, then a 12 V zener mid stage followed by a 3.3 V regulator and another zener. Filter chokes and TVS diodes were also used.
During EMC testing, the rapid trainsient bursts are troublesome. As Sleepwalker said about C3, it will be seen as a short and all the power will heat up the series resistor. Things are going to burn and it will burn with an open flame!
I am not so sure that the pictured schematics is in accordance with the CE regulations in Europe. The varistor is not a very safe device to connect directly to Live and Neutral without a fuse. Common varistors can explode when they “had enough”, speading out glowing material. A fuse, in series with Live, and perhaps also a shrink tube as a covering hat will help you out.
I’m not surprised that a 630V greencap blew on 240VAC, because the peak-to-peak voltage there is actually 679V. Most hardware is rated to 250VAC, so you’d probably want your cap to be rated for over 700V to be safe, assuming those ratings are VDC, not RMS.
When looking at 110VAC, the peak-to-peak is actually 311 V because you have to count the negative swing as well as the positive swing. The thing about RMS is that it takes the absolute value, which immediately ignores half the peak-to-peak voltage, then divides by the square root of 2. But 110VAC is often 120VAC (especially where the service starts at 240V) and can easily reach 125VAC. In other words, you’d better be prepared to get 354V peak-to-peak.
Whilst you are basically correct in your description, the voltage across C3 will not be the Peak to Peak voltage, but rather close to the peak in one half cycle and about the peak less the regulated voltage in the other half cycle. The peak-to-peak doesn’t occur all at the same time (as I’m sure you realise), and so the cap in this situation would never actually see the peak to peak voltage across it, though a larger cap may.
Good point, Sleepwalker. Although the Hot line spans as much as 350 Vpp, the diode stage is always referenced to the Neutral return, and thus should never exceed your +158 V. I must have been thinking of the sometimes-seen noise filter cap that can be found across the input leads ahead of the rectifier stage. Actually, it’s pretty rare to see a rectifier stage directly on the power lines without a step-down transformer in between.
This circuit doesn’t need and probably shouldn’t have a mains isolated low voltage supply. It is firing a triac — even if you isolate it, it won’t be isolated, and in any case must share at least common with the line supply. This types of direct-off-mains circuit is pretty standard for things like lamp dimmers and timers that directly control mains connected loads and don’t have any external interface. They should be safe by complete encapsulation and limited current draw to prevent fire.
This isn’t a great hobby project — this app note is for mass produced consumer goods that are extremely cost sensitive. If you want to build one yourself use a low voltage isolated power supply *and* an opto-isolator on the mains switch. It will cost a lot more in components than the version given here but will be more tolerant of user error and safer to debug. For a 1-off the parts cost is not a big factor anyway. If you must build a circuit like this, the circuit and the load should both be on an isolation transformer.
Evan – I think you mistunderstood what Bert and I were meaning, we were proposing using a low voltage lamp, as well as a low voltage side of the transformer, not just powering the circuit from the low voltage, but the lamp as well.
Certainly the direct-off-mains circuit is very common, I’m not disputing that, but what I am saying is that the ratings of the components as specified in the application note are downright dangerous! When you buy a commercial light dimmer is would (or at least should) have mains rated components in it with specs suitably calculated, the specs for this app note don’t even consider that. The cap will fail eventually, there’s just not sufficient overhead for common mains transients and as I said, I’ve seen cases of this happening (and they mostly caught fire). And the 1N4001 Diodes? that’s just crazy.
What happens if at the instant of turn-on you just happen to be near the peak of the waveform? The cap C3 will initially be discharged, the peak will be around 110*1.44=158.4V put directly across a reverse biased diode with a maximum rating of 50V via 47 Ohm resistor. It’s only a matter of time before there is a failure and quite possibly things getting grossly overloaded. This app note could not be used for mass produced goods, at least not as specified, the failure rate would be huge, not to mention the insurance claims probably!
This is the part I like:
“This reference note describes an application where the use of a microcontroller was not reviously economically feasible for any but the highest end products: lamp dimming”
Obviously this guy hasn’t seen any X10 product designs. I’m not certain that I’ve ever seen an X10 dimmer that DIDN’T use a super low cost microcontroller to do dimming. Nobody in their right mind would characterize an X10 anything like a “highest end product”.
The publication year of this app note is 1997. It is an “ancient” device, and as I recall from that era, this type of circuit was fairly common. There are many things “we” used to do that are no longer considered good ideas. Builder beware?
I made a typo which multiplied – the voltage should have been RMS* Root2 i.e. 1.414 and I typo’d it as 1.44 then blindly went and calculated it as such (it’s late, that’s my excuse!). So it should have been about 155.5V, not that it would make any great diff in this instance. In any case, around here the mains is officially +/- 10%.
I worked extensively with this sort of power-supply during the 80’s, even designed a ‘variant on it , that was extensively copied in Asia.
Even if this note was produced in 1997, it is still significantly wrong in a number of areas, not least of which is the selection of components.
You can blow this design out of the water, by working out the current across the ‘inrush’ resistor (R1 ) charging the capacitor the first time it is plugged in, vrs the resistor size.
As for C3… don’t even get me started about it not being an X2 400v
I have seen so many PCB’s with this circuit burned right through the FR4 boards, that it is just not funny.
What about this app note from 2005 ?
http://ww1.microchip.com/downloads/en/AppNotes/91094A.pdf
@Manual Garbe – That’s just as bad for other (but similar) reasons, though this could be made to work. In this case the engineer involved mucks up the calculations pretty badly (at least as I see it). I don’t have time at the moment, but if there is enough interest, then I might sit down at do a write up of why it’s bad and where he went wrong.
Same situation,
Problem with many engineers is that they only design for ‘good’ in-spec operation, (how many engineers are really going to remember to disconnect the programmer)
The first data-sheet uses a single 10M resistor to power the IC if this were to meet german standards then there should be two or even three resistors in series.
It is one reason why I will not have a ‘touch dimmer’ light in my house, because all that is keeping you from being a BBQ is a couple of capacitors in the touch lead (German requirement), the rest of the circuit is at mains potential no isolation. Other markets only require one capacitor, and I have seen some instructions clearly state: “some users may experience a slight ‘tingle'”.
Do you have some country specific additional rule in Germany, more than the EN60335 (Household products) and EN60664 (Electric Insulation)? I’m just curious to know.
I think there was a paragraph about bridging reinforced insulation and what to demand from the components doing so. One X1 cap could be replace by 2 X2 caps in series (or was it Y1 and Y2s?). There was similar demands on resistors.