Simple 60 Hz AC Mains Cycle Detector
How can you detect AC cycles with a microcontroller?
I usually use low voltage AC/AC "wall-wart" transformers for isolation.
Opto-isolators work well too.
The web is full of different methods and schematics.
But there's an interesting application note
(google for AVR182, doc2508.pdf)
that shows detecting cycles directly from the AC line: live, direct, hot.
The trick is to wire the microcontroller input and ground pins
directly to a wall plug through a 1 meg series resistor on each side.
What they should also tell you is that it's a really good idea
to put the resistors at the plug end
rather than at the microcontroller or circuit board end.
So here's how I made mine.
A local hardware store will have these cheap small plastic non-polarized lamp cord plugs.
They bend apart into two pieces as shown below.
Screw one resistor (brown-black-green is 1 MΩ)
to each side of the wall plug.
I used flameproof resistors,
applied one layer of white heat shrink tubing over the bare wire leads,
and then two layers of clear tubing around each resistor.
When completed the wires act like a 2-pin 0.1" header.
Before you use it,
short the two pins and
verify that the plug itself has about 2MΩ resistance.
There are no safety worries about voltage, current or power,
about frequency, shock or shorting.
Worst-case current is only 60 µA
so you can use thin digital wire to connect the plug to the microcontroller.
One wire goes to Vss (signal ground)
and the other to the microcontroller digital or analog input pin.
If it doesn't work the first time,
swap plug polarity.
Or use capacitive coupling on both wires.
Of course, the whole idea of this AC plug is unnerving at first
but when you think about it, it makes sense.
Better yet, just make one and test it for yourself.
You should observe it tickles far less than a 9V battery
(which I measured to be about 200 µA on a wet tongue).
Return to LeapSecond.com home page.
Comments/questions to tvb.