Saturday, March 14, 2020

0000 0000 0010 0110

Detecting AC Mains with a CD4017 circuit

A couple of years ago I swore that I would not open the pandora's box of logic gate chips. Again and again I would load up the AliExpress cart with assorted logic chips only to back out and go back to the familiar ground of Arduino, AVR and in particular the Attiny13 microcontroller.

After some shift registers arrived one day (and proved useful) I thought it wouldn't hurt to dip a toe in the ocean and so I followed up that purchase with a small batch of CD4077 chips, also useful, and suddenly the floodgates were open.

The YouTube algorithm kicked in and soon I was absorbing all manner of material specifically related to the use of logic gate chips. At some stage I must have pushed the button on a bunch of CD4093 chips, billed as four Schmitt-trigger circuits. Now I love Schmitt-trigger circuits, so how could this IC not be useful to me at some stage?

After singing the praises of internet circuit repositories on this very blog, I came across this potentially useful AC Mains detector.
Seems legit...
So confident was I that I grabbed one of my superbly functional 1206 SMD to DIP adapters and, without even bread-boarding a prototype, soldered the circuit together and tried to add the logic chip...and then came a MAJOR snag!

All linked and ready to go
In the circuit found online, the CD4093 is shown with 16 pins. Even a cursory glance (and there was some cursing eventually) reveals that this device has only 14 pins (e.g. in the circuit VCC is shown connected to a non-existent pin 16). Uh-oh. Diving deeper, I could see that some of the connections made no sense - why have an output diode linked to pin 10 when the datasheet shows this pin as an input?

Many hours of happy (??) searching later and I abandoned the CD4093 for a CD4017 (not again - how much Deja Vu can one blog stand?). After much testing I was even able to use the prematurely soldered circuit on the 1206 SMD adapter.

So now the circuit does indeed detect AC mains, but there was some redesigning necessary. For instance, the "Antenna" must come into the "clock" pin, which is pin 14 on the CD4017 (not pin 1 as shown in the online version). This is because the AC signal is detected as a clock signal and that is what triggers the counter IC to light the LED. Once triggered, the LED stays lit even when you move the antenna away from the AC source.

The LED can be extinguished by pulling the reset pin high which resets the counter, so I added a button on the end of the board.
Fritzing with through hole equivalents

The actual circuit after re-design

So it works! But how weird is it that the online version was so far off the mark?! Also, now I have to keep looking for a circuit to use the CD4093, which in the meantime has returned to the bucket of bits.





No comments:

Post a Comment