# Least expensive way to plug in a microcontroller into 120V (without wall wart or batteries)

I need to be able to power a Atmega168 by plugging it into a wall. The circuit is a little bit more complex but not too much. The Atmega168 needs between 1.8V and 5V at 200mA. The ideal solution needs to be contained all on the PCB board. No wall warts or batteries.

What is a good strategy or set of components that will allow this to be done safely and inexpensively? I'm new to the area but I have heard things about switched-mode power supply. Also, efficiency is not very important as long as it is not hot to the touch.

• Does it need to interface with anything? Because there are ways to make an off-line power supply, but they cause the whole microprocessor to be at line-potential, so effectively you can not, and should not touch it when it's connected. Jun 1 '12 at 4:42
• They're you're stuck with a transformer or a wall wart. Period. Jun 1 '12 at 5:00
• @Fake - yes, I came to the same conclusion when I read the word "safe". Jun 1 '12 at 5:03
• @AlexisK - No transformer? You can make a mains power supply without transformer, but then it's not touch-safe. Touching any part may be lethal. Jun 1 '12 at 5:08
• @Jeanne - If you have a link to it that could be an answer. Jun 1 '12 at 14:42

I don't know if these are inexpensive enough, but the simplest - and safest - way would be to use a commercial pcb mount power supply module like these:

Or else build a wall wart into your device. I've purchased commercial equipment that had a wall wart mounted internally by means of cable ties, with wires soldered to the wall wart's prongs.

• @Jeanne: can you say what type of equipment it was? A client suggested that I do this (put a wall wart in the enclosure and route AC cable outside), but I felt it looked unprofessional so I used an OEM PC board switching supply instead. However, because of cost and space issues causing assembly headaches, I'm reconsidering their idea. Jun 1 '12 at 17:06
• It was a reflow oven which appeared to have been converted from a commercial cooking oven. The wall wart was to power the added temperature sensing and control circuitry, which were mounted in a separate enclosure (not near the hot oven). Jun 1 '12 at 17:14
• @JeannePindar firstly, thank you for the answer. I very much appreciate it! Can I hook up a clipped extension cord to the input of one of these can get out a clean 5V? Also, they are slightly pricey, but might be cheaper once all is said and done with getting a bunch of smaller component. Do they make any less expensive type of these devices? Jun 1 '12 at 23:23
• Those are meant for pcb mounting, so the pins are really too small to have the cord soldered directly to them. The output of those should be clean enough as long as you're not powering any sensitive analog circuits, but you should have bypass caps on your board anyway. Those are two of the less expensive ones carried by two of the major parts distributors. I make relatively expensive semi-custom equipment, so frankly, I don't pay much attention to price. Jun 2 '12 at 2:20
• @AlexisK - What do you mean "clipped extension cord"? If it means what I think: don't! Never solder your power cord. Put the module nicely on your PCB, that's what it's meant for, and use a screw PCB terminal to connect the power cord. Always do so! Jun 2 '12 at 10:06

If it needs to be safe you can't get around a transformer for isolation from the mains, and you'll probably end up with the classical linear power supply:

You probably can change a few things here. You say the AVR can work on 1.8V. How about the rest of the circuit? If 1.8V is enough there too you could use a lower voltage transformer. (Make sure the whole circuit can work at 1.8V. You can' use LEDs, for instance.) Digikey lists a 3.15V/600mA, but this isn't a PCB mount, otherwise it would be ideal. 3.15V AC combined with Schottky diodes for rectification give you more than 3.5V input to your regulator, which could be almost any LDO that can supply 200mA. (If you use a higher transformer voltage you'll have to use a different LDO, since this one is rated at 6V in maximum.)

This is the standard setup for a linear power supply. It may look a bit complicated, but you can't go more simple than this. The wall-wart is a nice alternative, why are you against that?

• thanks for the answer. Is a switched-mode power supply something that is worth exploring for this? How trickey/available are the components to rebuild a wall-wart on the pcb? I'm having a little trouble finding the area to look for the pcb mountable transformers on digikey. Do you have a link to the right area to look? Jun 1 '12 at 5:12
• @AlexisK - I couldn't find the right transformer right away. I'll have another look later today. For the low-voltage solution I proposed a switcher wouldn't give you a real advantage. Even at 5V you only need 1W, so it's probably not worth it. Jun 1 '12 at 5:15
• thanks. Once I get a little more information about the transformer I'll check it out. Jun 1 '12 at 5:25
• I thought this 3V trafo would be nice, until I saw the current: 50A :( Jun 1 '12 at 14:32
• @FedericoRusso and the price at $57.00. Do you know of another less expensive option? Jun 1 '12 at 22:50 An elegant solution may be to use an USB wall wart like these: and supply your circuit via the USB (like the Teensy). Then encase everything in the same box, letting the plug out. DISCLAIMER: I know that this is an off-the-shelf solution, but I like it for two reasons: 1. Safety: it will (hopefully) be certified, so you need only to deal with 5 V, leaving the problem to the manufacturer; 2. Price: these plugs are found in places like dealextreme for down to 1$, and mine is working well until now. If you make your own, only the components will be more expensive, and your time also.

• How's is this more elegant than a regular wall wart? At least people won't think the USB device doesn't work or do anything. Jun 1 '12 at 13:10
• @kenny well, you don't have to worry about safety, and it's going to be a small box anyway Jun 1 '12 at 13:12
• Economies of scale are an incredible thing. It's simply astonishing that a manufactured, enclosed, shipped product with the overhead of a USB jack is less expensive than implementing a power supply. Jun 1 '12 at 14:16
• Apple charges you an arm and a leg for these. Jun 1 '12 at 15:25
• The Apple ones are far better than the $2 ones. Look at the various teardowns on Youtube. The cheap ones are scary. Jun 1 '12 at 15:58 A safe mains rated switchmode power power supply is quite a complex design. Have a look at this teardown of an iphone charger as an example. In that article the author mentions a switchmode Samsung cube charger for about$6 this charger may be a good option (possibly removed from its case and mounted on your PCB).