There are some excellent suggestions on how to create a wide-voltage range digital logic input on this question.
The question is very similar to my needs. I'd like to be able to detect the presence of a voltage (either AC or DC of either polarity, from, say, 5V-300V or thereabouts) and have the input go to a digital input pin of a microcontroller. I particularly like the second solution that suggests current-limiting resistor -> zener diode clamping... but...
In my understanding, an input that can take such high voltages should really be isolated (by a transformer / optoisolator) from a normal low-voltage circuit. How could I create an isolated input like this? Is the limited current and voltage of an input circuit like this enough to drive the input of an optoisolator?
And furthermore, how can I cope with DC voltages of either polarity and AC voltages on that input? I assume that I can put a bridge rectifier straight after the input, but that will cause a decent voltage drop before anything else has happened. Then I know there will be a capacitor in there somewhere to smooth out the input for AC, but I don't understand where it should go, how big it should be and how it will affect switch-on and switch-off times when it's just a plain DC voltage input?
Bonus points if the solution can go down to 3V (or even lower) instead of just 5V. Further bonus points for use of only cheap, standard 'jellybean' parts.