Computing stuff tied to the physical world

Voltage levels

In AVR, Hardware on Oct 17, 2011 at 00:01

In yesterday’s post, I described the idea of powering the AC current detector via a transformer-less power supply, using a very large capacitor or a supercap.

That means the whole circuit ends up being connected to 220V AC mains. You might think that nothing changed, since the circuit was already connected to mains via the 0.1 Ω shunt, but there’s more to it – as always!

If the power supply is tied to AC mains, then that means the circuit’s GND and VCC are also tied to these wires. The problem is that these two things interfere with each other:

JC s Doodles page 19

Because now we have a signal coming from the voltage drop generated by the shunt which is referenced to the same voltage level as the GND of the circuit. In other words, that signal we’re trying to measure now swings around zero! And while the ATtiny has a differential input, which in principle only cares about the voltage differential between two pins, it’s not designed to deal with negative voltages.

Uh, oh – we’re in trouble!

I could use a capacitor to “AC-couple” the 50 Hz frequency into a voltage divider, but that effectively creates a high-pass filter which attenuates the 50 Hz and lets more of the noise through. Not a very nice outlook, and it’s also going to require a few additional passive components. I’m still aiming for a truly minimal component count.

But we’re in luck this time. The differential ADC appears to be perfectly happy with tying one side to ground. It might not be able to measure the negative swings, but it does the positive ones just fine. When I tried it on my existing setup, I still got more or less the same readings.

Still, we do have to be careful. A negative voltage on any input pin is going to seek its way through the ESD protection diodes present on each ATtiny I/O pin. Keep in mind that we’re dealing with a very low-impedance shunt, and large currents. So it’s important to limit the effect of negative swings to avoid damage to the chip. The easiest way to do so is to include a 1 kΩ resistor in series, i.e. between signal and ADC input pin. That way, even a 1 V negative voltage excursion will drive less than 1 mA current through the ESR diode, a value which is still well within specs. Even better, that 1 kΩ resistor can be combined with a 0.1 µF cap to ground, as low-pass for the ADC.

Good, so if that weak-supply-feeding-a-big-cap idea works, then the rest of the circuit ought to continue working as intended, even though we’re operating at the limit of the ATtiny’s ADC voltage range.

All that’s left to do then, is get that power supply right. Oh, wait: and figure out a way to get a wireless setup going. Oh, and also figure out a good enclosure to keep this dangerous hookup safely tucked away and isolated.

Oh well. Not there yet, but progress nonetheless!

  1. Nice to see that this simple setup still delivers the results you’re after!

    Now all there is left is to attach a standard JeeNode to the ATtiny (and thus to the 220V ;-)), and off you go!

  2. This would work well as a enclosure:

    You could also disassemble one of those cheap radio controlled switching outlets ( and make a PCB which fits inside. A hole for a status LED is already made and PCB mounting holes are propably existent, too. And you could take a look at its stock transformer-less powersupply. For ~ 12€ you can get three of those cheap ones. Another advantage is, that at least the enclosure and the Euro-Connectors itself should comply with safety rules.

    • Thanks, good tip – I was indeed planning on doing this. Maybe even the switching functionality can be re-used, i.e. driving the built-in relay.

      Only concern I have is that these units might draw quite a bit of idle power. I hardly ever see the power consumption mentioned on the specs, and I’m really trying to reduce my baseline power consumption. I’m currently at 100 W (excluding a small boiler), but I’d like to get it down to 50 W one year from now…

    • Good find indeed. Its very weird that you can by 3 of those for about €12, and if you ‘just’ want an empty enclosure that you pay about the same price or even more(Conrad has them for €10 – €17!!).

      Hmm, and reuse the switch, transformerless powersupply and 433Mhz receiver too for that price…

      A KaKu unit would also be a viable option, if you’re headed that way!

    • I got this mumbi Funksteckdosen Set from a local reseller in Switzerland and paid almost twice as much :-(. According to the package it uses less than 1W on standby. I can’t open them without breaking them as there are some security screws used there. They are labeled as 433.92MHz but the OOK443 Plug doesn’t see the the communication. I have absolutely no idea how (if) it’s possible to switch them from a JeeNode.

  3. The reason for ridiculus 12€ may be the cheap build quality, the propably not very well designed electronics and the giant production volume. Even all the electronic bits inside and the enclousre are much cheaper than a quality enclousure made in small quantities. Idle current could be quite high if you use the integrated power supply, but if you replace the whole PCB with a custom one including the attiny, RF, shunt and a driver for the relay you’re ready to go. And aside of the 220V risks, you could even sell these in kit form or as a drop in replacement for these switching outlets. If you take steps further, you could ‘upgrade’ them with a triac for dimming functionality. And if there are still unused resources available in addition to the wireless stuff, you could make it into a wireless-programmable timer clock. One last step even further: Add a Jenode plus Graphic LCD plus thermocouple to the mix and you have a standalone solution for your reflow timer. Definetly not the cheapest one, but a very versatile one.

    • It has been done – see

      But he’s not selling them. My hunch is that it will be either nearly impossible or nearly unaffordable to get this through the entire approval process for mains-connected devices. This is probably going to be a problem with everything I do on the topic of 220V-connected stuff as well, btw.

  4. Well, that’s exactly what i mean.

    You’re right, getting this kit through TÜV, VDE, etc. approvals won’t be easy, maybe impossible. I do not know the legal situation for selling a DIY kit which deals with hazardous voltages, but i think if it is in kit-form, it’s up to the user to take care of a safe operation (e.g. Anyway it would be cool to have such an intelligent power outlet.

Comments are closed.