# How to use a transformer to power a 5V chip (an Atmega328)?

I am designing an Atmega328 based device which needs to be powered directly from 230V AC. I have found a transformer in my local electronics store which seems perfect, but I have never worked with transformers before.

Does this unit output 6/9/12 V DC or does it output AC which needs to be converted?

If it still needs to be converted to DC, what size/type diodes and capacitors should be used and how to get it to 5V?

Lastly, should this transformer, with its blue and black primary wires, be connected in serie or parallel to a mains supply running through my device? It is a device that connects to the mains, and then you connect another device (e.g. TV) to it, so should it connect in serie or parallel to the wires running to power the TV?

Thank you for helping out!

• My internet is not working correctly rite now so it won't let me view the linked transformer, but just FYI, transformers almost always output AC. So you will most likely need to convert this to DC. – Garrett Fogerlie Jan 6 '13 at 12:35
• What is the estimated current consumption of your entire circuit (Atmega + supporting circuits) that needs to be powered at 5V? If your requirement falls below 1.5A, you can use an LM7805 linear regulator to drop the 9V output of the transformer to 5V. Of course, you need to convert/rectify the AC output of the transformer first into DC using a bridge rectifier. – shimofuri Jan 6 '13 at 13:34
• @shimofuri , it is far below 1.5A. – LouwHopley Jan 6 '13 at 13:54
• @LouwHopley Thorn's answer below will give you the basic approach in making a simple linear regulator supply using LM7805 (since your current requirement is below 1.5A). You still need to estimate the current required though as the choice of filter capacitors, output capacitors, and heatsink capacity will vary on the design current. LM7805 datasheet can be found here: ti.com/lit/ds/symlink/lm340-n.pdf Further reading on power supply design: sound.westhost.com/power-supplies.htm – shimofuri Jan 6 '13 at 14:04

(Note that ready-made power supplies that will fit your requirements are available just about everywhere. These remove safety hazards associated with mains voltage, so they're very much recommended for a beginner.)

Here is a random linear power supply circuit:

Your transformer outputs AC, so you need to 1) rectify it using a diode bridge and 2) bring it down to regulated 5V using a linear regulator. The transformer should be rated for the current you need with some margin.

Output voltage of your transformer should be somewhat larger than desired voltage to take into account linear regulator dropout and diode drop, but not too large because any excess power will have to be dissipated by the regulator as heat.

Diodes should be able to withstand both forward current and reverse voltage (this is essentially guaranteed automatically for power diodes). A 1N4007 (rated for 1A) will likely fit. If not, cheap 5A diodes are available. A diode bridge is more convenient than 4 individual diodes.

The regulator (7805, LM1117-5.0 or any number of other ICs) should also be rated for the current you need. Note that a heatsink might be required.

Choice of capacitors is normally dictated by the linear regulator datasheet. There's normally some minimum value required for stability. The capacitors should be rated for voltages they're under. Note that the voltage is >5V for C1, and it's also pulsing, so make sure you provide a large margin for safety.

Note that you really want a mains switch and a fuse before the transformer (not shown in the circuit). Also note that mains can kill you, so read up on electrical safety before doing anything if you have not done so already.

Everything that is connected to mains is connected in parallel so that full mains voltage and lowest possible source impedance is available for every device.

• Most linear regulators should be operated with its input higher by at least 2V than the output. The LM7805 IC linear voltage regulator will provide a 5V output but you must supply at least 7V to its input. Diode rectifiers will also drop 0.7V when converting AC to DC. So, the transformer must supply at least 7.7V (make that 8) AC nominal for the power supply circuit to work. Using the 0-9V AC taps of the transformer is thus appropriate. – shimofuri Jan 6 '13 at 13:53
• Thanks for the great answer! Do you have any links to "ready-made power supplies" ? I have always been using mobile-chargers etc, but would like to have a transformer internally, so would love to get my hands on rather the insides of a mobile-charger – LouwHopley Jan 6 '13 at 13:59
• Use any old wall wart that matches your specs. They have the transformer built in, and will save you a great deal of time and most importantly, risk (if you're a beginner). – capcom Jan 6 '13 at 14:07
• @LouwHopley: if it's going to be produced in quantity, using an off-the-self supply is even more important. I really doubt you're willing to accept responsibility for burning a customer's house down, especially since your devices are unlikely to be certified. Take a look at Digikey or Farnell inventories, there're going to be hundreds of choices. – Thorn Jan 6 '13 at 14:42
• @Thorn Thanks for the response. I have taken your opinion into account and decided to rather source a power supply. Thanks – LouwHopley Jan 6 '13 at 20:03

Firstly, my advice is if you are relatively new to electronics/transformers/working with mains voltages, then don't do it - just buy a ready made 5VDC plug pack or a module that will achieve what you are wanting to do.

Anyway, warning out the way, here's the basic idea for a linear supply:
All normal transformers output AC, which then needs to be converted to DC for use in a typical circuit. There is no direct connection, a transformer works with changing magnetic fields, so DC is not an option.

If you want to end up with 5VDC then select the 6-0-6 (250mA) option. The 6-0-6 means the secondary will have a centre tap with 2 6VAC taps relative to this of opposite phase. This is better explained with a diagram:

Note the resistor marked "Rspice" is only for simulation purposes to keep SPICE from complaining, you don't want it in your circuit (you need to keep the secondary isolated from the primary) L1, L2 and L3 represent your 230VAC in, 6VAC-0-6VAC out transformer.

Simulation:

Notice the input voltage is ~325V pk-pk, this is because AC voltage is generally given as an RMS (Root Mean Square) Value, which is the equivalent of a DC voltage of the same level. This is 0.707 times the peak to peak value, so 325V * 0.707 = 230V

This will work out the same for the 6VAC taps, they will be 6V * 1.414 = ~8.5V relative to the center tap, as you can see. The taps are 180 degrees out of phase with each other.

Turning this into 5VDC

First you need to rectify the 6VAC output. There are various ways to do this, but generally a full bridge rectifier is used. You can buy a ready made bridge rectifier as a single component designed to do this job (i.e. rolls D1-D4 into one package).

Using this and a large filter cap, we get something like this:

Again, note the resistor marked "Rspice" is only for simulation purposes, you don't want it in your circuit.

Simulation:

The top two red and green traces are the inputs to the regulators - you can see the rectifier + capacitor has converted the AC into DC with a slight ripple. The bottom plot is of the +5V and -5V outputs from the regulators.

The above has +5V and -5V rails, but you can just leave the negative side out if desired. The components are not suggestions, just picked from LTSpices library to suit. A decent LDO and some standard 1N400x diodes, plus a good quality filter cap or two (ideally rated for double the expected voltage across it) should work fine.

Just to mention again, I don;t recommend you try to build your own supply yet until you have done some more low voltage work and are extremely confident you have the required knowledge. Mains can kill instantly, so for the sake of waiting a little while longer and lessening the risk of mistake, I'd say that's the way to go at present.

Remember the above circuits are basic concepts, not fully designed supplies (e.g. there is no fuse or other protection present, notes on construction, recommended trace/wire thickness, clearance/creepage distances, etc. there is a lot to consider in order to make even a simply mains supply safe)