This one’s not a flashy hack, it’s a great piece of work and a good trick to have up your sleeve. Sometimes you’ve got a voltage difference that you’d like to measure, but either the ground potential is at a different level, or the voltages are too high for your lowly microcontroller.
There are tons of tricks with resistive voltage dividers that you can play. But if you want serious electrical isolation from the target, there’s only one way to go — an optocoupler. But optocouplers only really transmit digital signals, and [Giovanni Carrera] needed to measure an analog voltage.
Enter the voltage-to-frequency IC that does just what it says: produces a square wave with a frequency that’s proportional to the voltage applied. Pass this square wave through an optocoupler, and you can hit one side with voltages approaching lightning strikes without damaging the microcontroller on the other side. And you’re still able to measure the voltage accurately by measuring the frequency on the digital I/O pins of the microcontroller.
[Giovanni] built up and documented a nice circuit. He even tested it for linearity. If you’re ever in the position of needing to measure a voltage in a non-traditional way, you’ll thank him later.