Mains Power Supply For ATtiny Project Is Probably A Bad Idea

When designing a mains power supply for a small load DC circuit, there are plenty of considerations. Small size, efficiency, and cost of materials all spring to mind. Potential lethality seems like it would be a bad thing to design in, but that didn’t stop [Great Scott!] from exploring capacitive drop power supplies. You know, for science.

The backstory here is that [Great Scott!] is working on a super-secret ATtiny project that needs to be powered off mains. Switching power supplies are practically de rigueur for such applications, but compared to the intended microcontroller circuit they are actually quite large, and they’ve just been so done before. So in order to learn a thing or two, [Scott!] designed a capacitive dropper supply, where the reactance of the cap acts like a dropping resistor to limit the current. His first try was just a capacitor in series with an LED; this didn’t end well for the LED.

To understand why, he reverse-engineered a few low-current mains devices and found that practical capacitive droppers need a few more components, chiefly a series resistance to prevent inrush current from getting out of hand, but also a bridge rectifier and a zener to clamp things down. Wiring up all that resulted in a working capacitive dropper supply, but a the cost of as much real estate as a small switcher, and with the extra bonus of being potentially lethal if the power supply is plugged in the wrong way. Side note: we thought German line cords were polarized to prevent this, but apparently not? (Ed Note: Nope!)

As always, even when [Great Scott!]’s projects don’t exactly work out, like a suboptimal 3D-printed BLDC or why not to bother building your own DC-AC inverter, we enjoy the learning that results.

45 thoughts on “Mains Power Supply For ATtiny Project Is Probably A Bad Idea

    1. His solution is as big as the COTS version and worse can kill the user.

      This is what I tend to expect from low end Chinese products. A mix of lethality and bad design.

    2. I have found myself wanting a tiny 5V supply to run a 555 timer as a oneshot controlling an SSR to 1) add a variable pulse time to my spot welder rather than relying on the original big toggle switch which you needed to turn on and off manually while counting “little monkeys”. And 2) Not blow the breaker when turning on at the wrong part of the half-cycle. (by using a zero-switching ssr)
      it all needed to fit into the space vacated by the toggle switch. I ended up using a pp3 battery as it was a long time ago and I knew a lot less.


      >Loophole in BS 1363
      >There is a problem in BS 1363 which allows extension sockets to be manufactured with the earth hole placed too close to the edge. Most multi-way portable socket outlets exploit this loophole and permit the insertion of an inverted plug into the earth pin only, thus opening the shutters of the current carrying contacts. This is a clear danger as can be seen from these photos.

      1. I keep looking at the photo and I don’t understand the danger, perhaps I’m missing some key piece of information? If an appliance is plugged into only the earth pin why would there be any significant current on the exposed but unconnected pins? (post says April 2 in my timezone)

        1. The danger is that by doing this, the small tabs covering the live & neutral which prevent small metal items being inserted in those holes are moved out the way allowing small metal things to be inserted.

          The advantage with these is that you can do just this to open the tabs so you can put a 2 pin euro plug in the rectangular holes when you don’t have an adapter to hand. Alternatively a suitably sized key works well in the Earth hole to move the tabs.

          1. I often plug in 2 pin plugs in the british 3 pin socket. I put one pin in the earth hole to open the shutter, then rock the other over into the neutral, then rock the other into the live. The dimensions are close enough that it almost always works, although sometimes the pin gets sprained out a little. Once I almost died doing this as I had a foot on a pc case earthing me and a finger brushing against the live pin at the socket.

        2. Baby (or ehm retard) proofing. The live and neutral are protected by a small flap/shutter which slides away when you plug in the earth pin. So you cannot poke a screwdriver into the socket until you disengage the shutter with the earth pin.
          Since around the mid 2000’s every socket in EU has to have shutters (this is not UK specific).
          With the CEE 7/5 sockets where there is no earth/ground pin (there is grounding but not a “pin”), the shutter is a small plastic flap held by a really strong spring. It gives you a damn workout plugging in things…
          I always buy extension cords from which its removable. Its getting harder and harder to find those, but still manageable.

          1. Ah, the shutter is in the socket/extension. That’s pretty cool. It’s something we don’t think about in the US. Maybe our 110AC is less dangerous, or maybe we don’t care quite as much about safety.
            I do have a US power strip that has shutters, I assumed it was to keep dirt from falling into the holes.

    2. No thanks. Those UK plugs are huge and clunky with their weirdo integrated fuse holders and switches in all sockets. Things work just fine here with Schuko plugs. You can keep the plugs, separate water taps and the royals.

      1. Right–honestly faulty power plugs are just not a statistically significant cause of death anywhere. This is a solved problem. Only complete turkeys deliberately misusing things in spectacular ways end up rarely getting a jolt, and no amount of design will fix them.

      2. The plug is huge and not very pretty, but the fuse, that’s a thing of beauty. Fuses and trip switches are there to prevent the downstream wiring going up in smoke. This all seems rather pointless when your 15 A rated socket has a device plugged in with a 5 A rated cable. The wire will smoke before the trip goes. With integrated fuses, each cord can protect its cable, with its specific current rating. AFAIK only the UK plug addresses this issue.

        1. I had several fans with US style plugs (I’m in the US) which have fused plugs. I’ve been seeing these more often in low power appliances, and the plug is only slightly longer than normal.

        2. Fuse protect upstream not downstream. You can have a fancy 5A fuse and still smoke your cord or appliance as it’s still 1kW going trough, so a bad connection will smoke happily without tripping your fuse.
          But once melted it will trip at 5A (or front 16/20/32A) without bringing full kiloamps from power network.

      3. For devices like mains hoovers (or extension reels) where the cable getting pulled is almost a design feature, a plug with the cord exiting from the middle face would allow me to give it a yank and disconnect it without having to walk back to the socket.
        That ability for US and Euro plugs is something the UK plug misses out on.

        Its’ also rare but not unheard of to find a plug where the cord exits from the top. A lot of mains DC adapters are like that.
        I do have some sockets in my house fitted upside down because the wire needs to go up not down and it makes more sense.

    1. For running a flickery LED and wasting more energy as heat? Si!

      For supplying a microprocessor and trying to conserve energy? No!

      For any real application: still no. These are really dumb ways to power things–like this is aggressively lazy and amateurish. It’s that advanced laziness, where you end up expending much more effort avoiding different kinds of effort. Failure modes here are all horrible. Kind of fun just for the novelty of it but don’t actually use this for a project when there’s one amp/five volt wall warts piling up in your junk drawer that are barely any larger than the USB port and prongs which define their form factor.

      Like I have several that are about the size of a standard six-sided die, just waiting to be used for random tomfoolery. Pull out the board, prongs, female USB port, and wire it directly and it’s far smaller. Just double-insulate it when you’re done. That would be smaller, cheaper, safer, easier, less ripple–basically in every way superior to these shenanigans. But it’s good to understand the alternatives and theory I suppose.

    2. Actually, for cases where the applied peak reverse voltage exceeds the approximately 5V reverse breakdown of an LED, a series diode is in order. For one thing, it saves power, as the series resistor isn’t dissipating heat on the half-cycles that don’t light up the diode. In the second place, according to something I heard years ago, repeated reverse current in an LED can shorten its life even when it doesn’t cause excessive power dissipation.

  1. Back in the late 90s I had much success with Microchip data sheet DS00954A ap note.
    AN954 Transformerless Power Supplies: Resistive and Capacitive
    Even built a touch controlled AC lamp dimmer with an 8 pin PIC12F509

  2. This solution, with voltage dropper based on reactance is quite common in appliances in which user can not come in contact with inner electronics. For example WiFi enabled socket or PID enabled bulb is pretty fine with this solution as no HV part is exposed to user. However using it in stuff where some parts are fully or partly exposed is a deathtrap. I believe HaD had article about those lanterns/powerbanks that look like Dalek and use such voltage droppers for converting 230V mains into 5V for phone charging. Pretty dangerous stuff.

    1. Thank you for being the voice of reason here. I totally agree It is not that the topology itself is bad, in fact it is very good, however it is not good in all applications. A smart engineer knows when he can use what safely.

  3. I found one of those transformerless supplies inside a Philips Avent bottle heater. It powered a small ST micro, which in turn drove the heating element and determined heating profile and time depending on user setting. Of course it died due to supply failure. It was also made to be unserviceable…

  4. This is a very common type of power supply, and if correctly designed and used, is quite ok.
    Most speed controlled power tools use this for example.
    But these supplies are a bit NO NO if the output finds its way into the external world, like phone chargers (shudder!!).

  5. There’s one big advantage over a switching supply for certain applications that’s often overlooked: practically no EMI generation. That can be quite significant for wireless remote outlets and LED lighting in EMI sensitive areas!

  6. Many years ago in the data section of the Dick Smith Electronics catalog it had a section on resitor values for LEDs and included the capacitive stopper circuit for mains operation. One diode, one cap, one resistor and the LED.
    I never built it but it certainly looked simple enough.

  7. Why not just spend a buck and buy a mains to 5v or 12v power supply from ebay? They’re smaller than that assemblage you have there and they work pretty well. I’ve been using them for some time now. Not shilling, just pointing to a source. I think I have also bought similar from Banggood before, but I just looked and don’t see any there now.

  8. It was back in 1986.

    I had a soldering iron. It was not the only one. But this was the only one I really liked. 220 volt soldering iron 25 watts. I then worked not only at home and therefore I always carried it with me. I had a special outlet with a switch at home. But I was sometimes scattered. Turned on the switch …. and waited until it warms up. And it turned out … I forgot to turn it on.

    And I got a little challenge. Must be an indication! The soldering iron is on … and the switch is on. Can you solve this problem? Of course, you need a current transformer, Arduino necessarily!

    But at the time I didn’t have it all …

    I had to solve the problem with one rectifier diode and one LED.

    It worked for about one year without any problems! BUT ….. I was not at home and my wife did something stupid !!!! In this special outlet plug 1000 watts of iron. Then the magic smoke went ……….

  9. Yes, I forgot to mention. I then lived in the Soviet Union. . America detonated the first atomic bombs. The world has become a little uncomfortable. But when the USSR detonated a hydrogen bomb ….. the whole world started. Literally!
    And this soldering iron also made the military industry. He was like a little soldering station. Realistically! But there was no electronics. His name was ЭПСФ-25. More of these were not ….

  10. Want about 3d printed capacitors and circuit boards using light for better amps on a 12v plug or some other 12v to 240v converter for a psu using wireless transfers within a pc case using mirrors and glass case lighting using mirrorl li fi boncing like a cube bouncing light power everythung wirelessly??

Leave a Reply to Jii Cancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.