how detect ac signal in avr?
Assuming I get the requirement correctly you can use the following:  

An optocoupler that outputs pulses to a digital pin for each zero cross of the mains voltage, you'll get 100 pulses for a 50Hz input frequency.



If you want to get the pulses only when the mains is above a specified level (for under-voltage detection) then you can use a zener in the opto diode side to introduce a voltage drop.
In the following example the zener used is 1N5281 which is a 200v diode, so in order turn on the optodiode the mains voltage need to raise above Vzener + Vfdiode + Vfoptodiode which results to about 203v.



Both these circuit offer the benefit of mains isolation.



The schematics have been update,  the resistor values should be calculated per case.
In both graphs the green trace is the mains input (left axis) and the red trace the output (right axis).

As jippie noted, care must be taken regarding the power dissipated on R1 and possibly replace it with two resistors in needed in order to operate them within voltage specs.

As Anindo Ghosh noted, the resistor value R1 needs to be selected based on the current transfer ratio of the used optocoupler and the output current requirement.

As JoeHass noted, in one of my previous circuits the diode was connected anti-parallel to the opto-diode which resulted in increased dissipation on R1. The diode has been moved in series with the opto-diode so that the current through R1 flows only for half cycle (in one polarity).