I'm looking for building a power supply circuit that will convert 230VAC to 5VDC in order to power up an Atmega328P. I also want this to be as small as possible.

I know a transformer is one option but since I want to shrink it I was concerned about using a 5.1V zener diode.

Here is a schematic I found: 5V trasformerless power supply

But how much heat will the the capacitor/diode produce? Is it more efficient to use a transformer instead?

  • 12
    \$\begingroup\$ Power electronics isn't really my field, but galvanic isolation (i.e. a transformer) is usually a really good idea from a safety point of view. \$\endgroup\$ – jramsay42 Mar 1 '18 at 11:45
  • 21
    \$\begingroup\$ That thing (and everything it powers) needs to be enclosed in an insulated box with no user accessible connections to the the outside (except of coursevthe power lead.) All points in that circuit must be assumed to be at mains voltage. Touching any part of it could kill you. \$\endgroup\$ – JRE Mar 1 '18 at 11:49
  • 10
    \$\begingroup\$ The two pins marked "ouput" will have 5V between them. One or the other WILL have the full line voltage on it. \$\endgroup\$ – JRE Mar 1 '18 at 11:51
  • 36
    \$\begingroup\$ I smell burning electronics, corpses and crying mothers. \$\endgroup\$ – winny Mar 1 '18 at 12:20
  • 12
    \$\begingroup\$ Do not build this circuit. It could kill you. You may want to simulate it with LTspice or similar but as Olin says buy something. Learn on low power low voltage circuits. I have built circuits like this but only where there is no possibility of an end user coming into contact with the output. \$\endgroup\$ – Warren Hill Mar 1 '18 at 18:34

If you're here asking about the basics of a line-connected power supply for running some hobby project, then you shouldn't be trying to do this at all. This is NOT where you want to learn by experimenting. The cost of mistakes are too high. The results can burn down your house or electrocute you, or someone else.

If you need a little current at 5 V to run a microcontroller from, just buy the power supply, or use a USB power adapter. These things are cheap, small, and easily available. Someone else who actually knows what they are doing has done the engineering to provide the 5 V safely.

The Meanwell IRM-01-5 is just one of many examples. This one mounts on your PCB like any other part, only has a footprint of 1.3 x .9 inches (34 x 22 mm), puts out 200 mA at 5 V, works with line power anywhere in the world, and costs under $5 in singles. Doing this yourself just doesn't make sense.

| improve this answer | |
  • 22
    \$\begingroup\$ Yup - this - part of engineering is knowing when to engineer and when to just shop. \$\endgroup\$ – brhans Mar 1 '18 at 13:02
  • \$\begingroup\$ I agree it's non sens... except for learning. But yes, Oiln's solution uses only one component and it's easy. \$\endgroup\$ – Fredled Mar 1 '18 at 17:50
  • \$\begingroup\$ I agree, it's cheap and only consumes 75mW on standby! Nice product. \$\endgroup\$ – bobflux Mar 1 '18 at 18:39
  • 2
    \$\begingroup\$ @Fred: This isn't a project where it's OK to learn on the job. That's because a screwup can mean the house burns down or someone gets killed. \$\endgroup\$ – Olin Lathrop Mar 1 '18 at 18:57
  • 1
    \$\begingroup\$ @Fredled I would say it's okay to build such a circuit for education but you need to understand how it works and you really need to have appropriate safety precautions in place in case you got it wrong. (And this person certainly doesn't seem to understand how the circuit works). \$\endgroup\$ – user253751 Mar 2 '18 at 0:20

There are many problems with that circuit, of which the most important is it is not isolated from mains. A transformer will provide you with isolation. If you mount the Atmega in a plastic box, then it might be safe to use, but you will not be able to work on it safely, unless you use isolated equipment and are a careful engineer. You wouldn't be able to interface it to anything safely or easily either, at least not without using opto-couplers or something similar.

These days, it's far better to buy a small 5v plug-top power supply, isolated, ready made, high current output (1A/2A), waste of time to do anything else.

But if you want some critique of that circuit ...

C1 must be an X2 type capacitor. Mains will have large transients on it, often to 1500V. An X2 capacitor is rated to handle these safely.

R1 is far too big, and will get hotter than it needs to. Its only function is reduce the inrush current when first switched on, to below the withstanding of the D1 bridge. If they are 1N4004 class devices, able to take a 30A surge, then R1 could be as small as 10 ohms, though 100 ohms might be kinder. Check the single cycle surge rating of the bridge you are using, and adjust R1 accordingly.

R1 needs to be a high voltage type, most 'ordinary grade' resistors are 200v max. Alternatively, you can use several equal value ones in series to increase the voltage rating.

The efficiency, in output power per metered input power, is not too bad, as most of the input voltage is dropped across the non-dissipating C1, as long as R1 is not excessive, as it is here.

To put some actual numbers on it, C1 = 220nF at 50Hz (I assume, as it's 230v) will have an impedance of about 14.5k. Together with R1, their total impedance will be about 17.5k (they are in quadrature remember), giving an rms current at 230v of about 13mA. That will dissipate 1.7W in R1, and deliver an average output DC current of around 11mA. That doesn't sound much juice to power your Atmega, if you want to light any LEDs. With no load on the output, that will dissipate about 56mW in D2.

| improve this answer | |
  • \$\begingroup\$ It could be worked on safely with an isolation transformer, in an earth-free area. I used this technique for one of our technicians working on non-isolated PSs when I worked for Rank-Xerox (UK). \$\endgroup\$ – Leon Heller Mar 1 '18 at 12:13
  • \$\begingroup\$ 230V rectified gives around 350V, which is one more hazard. 350V DC is much more dangerous than 230V AC. Therefore Another big problem is that D2 and C2 will have to be rated 350V and so goes with dissipation which must be calculated from that voltage. \$\endgroup\$ – Fredled Mar 1 '18 at 17:58
  • 3
    \$\begingroup\$ @Fredled 230V rectified gives around 350V True, but irrelevant, as most of that input voltage is dropped across C1 and R1, which act as a current source into the diode bridge. The diode bridge, D2 and C2 only need to be rated for low voltage. If D2 fails open circuit, then the bridge and C2 will see a higher voltage. I have used this circuit in the past, and have used two parallel diodes for D2 for just that reason. \$\endgroup\$ – Neil_UK Mar 1 '18 at 18:45
  • \$\begingroup\$ I agree C1 and R1 have enough high combined resistance. Still, absent of load there will be 350V at the cathode of the zener. Thought a simple indicator led would drop it significantly. \$\endgroup\$ – Fredled Mar 4 '18 at 23:05
  • 1
    \$\begingroup\$ @DannyS lightning, inductive loads switching off, see this \$\endgroup\$ – Neil_UK Jun 3 '18 at 5:13

My grain of salt as a professional power supply designer engineer.

The issue is not on power dissipation or losses, but on safety. This system will most likely not burn (you limit power trough capacitor, smaller = less power), but it is GUARANTEED to electrocute anyone touching our Atmega or any of its output.

If you really want to do it, you must make sure that

  1. Your system will be fully encapsulated in a non conductive project box
  2. above project box has nothing mechanical going out : a wifi module is fine
  3. you never communicate using wire with your controller while plugged (people tend to forget that part).

Basically, anything metallic or conductive (cable, resistance or even an other capacitor) will be a safety risk. Risk in the sense that touching = life threatening injury.

If you are not trained with safety I can only recommend to go with a USB adapter (like already proposed). Using a transformer is possible only if it is qualified as a reinforced or double insulated (sometime wrongly named galvanic insulated) transformer.

| improve this answer | |

The other answers are pretty good, but we can still add a few nails to the capacitive dropper's coffin...

  • The USB microcontroller programmer will strongly dislike being connected to mains voltage, so you need an isolation transformer or USB isolator for development... annoying...

  • It burns power even when the micro sleeps. Like 1-2W for doing nothing, and it's a shunt regulated supply, so it has to be sized for the max current, incl. relays, LEDs, etc. Not environmentally-friendly.

  • If you want it small to put it inside a wall outlet or switch, burning power in small places tends to make things hot

| improve this answer | |

Disregarding the safety issues, R1 should be 500 ohms at 1/2 watt. (It could be two 1,000 ohms at 1/4 watt in parallel.) This circuit is very common in LED replacements for incandescent lamps. I use "MB6S Bridge Diode Rectifiers" = 600 Volt 0.50 Ampere bridge rectifiers in this circuit. (They are smaller than 4 X 1N4004s.) (Average Rectified Output Current: 0.5A, Peak Repetitive Reverse Voltage: 600V, Maximum RMS Reverse Voltage: 420V; Maximum Working Temperature: +150 degrees C, Peak Reverse Current: 10uA; Forward Voltage Drop: 1V.

Remember anything (wires) connected to your micro-processor can have 120 volts on it/them.

| improve this answer | |

If you really want to build your own power supply, consider using a common doorbell transformer, available at most hardware stores in the US. It will step down wall voltage to 10-16 Vac, isolate the secondary side from the wall, and save you the heat and expense of high-wattage resistors and zeners.

| improve this answer | |
  • 3
    \$\begingroup\$ The OP is asking about using a capacitor to drop the voltage vs. using a transformer because they want to make a small power supply. Small transformers are available - a doorbell one would be somewhat on the large side in comparison and need dropping a lot of voltage. \$\endgroup\$ – Andrew Morton Mar 1 '18 at 19:00

In your current design, the impedance of your capacitor at 60Hz is...

Zc = 1/(2*pi*60Hz*j*0.22uF) = -12057*j Ohms.

The other power lead has a 10K resistor. The total magnitude of the combined impedance between the capacitor and resistor is...

|Z| = sqrt((-12057j)^2 + 10000^2) = 15.6k ohms

If we ignore the 1.7V drop in the rectifier and the 5.1V drop across the load then calculating the input current becomes much simpler and the answer will still be within a few percent of the real answer.

At 120Vrms the RMS current in the capacitor/resistor will be approximately...

230V / 15.6K ohms = 14.7mA RMS

The average current is...

7.7mA * sqrt(2) * 2 / pi = 13.3mA

This average current is also the max allowed load current to maintain regulation. If your device draws more than 13.3mA then your 5V will drop out.

The capacitor will not dissipate significant power as it charges and discharges. The power will be dissipated in the resistor and zener.

The power dissipation in the 10K resistor is approximately... Wres = (14.7mA) ^ 2 * 10K = 2.16W

Without any load the power dissipation in the Zener is approximately...

Wzen = 13.3mA * 5.1V = 68mW.

Note that if there was a load then the load current would subtract from the current in the zener and the power dissipation in the zener would be less.

You have 10K on one of the power leads and a capacitor with 12K impedance on the other power lead. If the user were to touch one of the leads then as much as 23mA RMS could flow into the user.

If someone touches a wire and 23mA RMS is flowing in it, it would be painful and they may be unable to let go of the wire.

An isolation transformer really is the way to go. The size of a transformer shrinks a lot as the frequency of the input voltage goes up. If you want the transformer to be small then chop the 60Hz into a few hundred Hz first.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.