Arduino testing its own power source ?

Hello,

I wave a 5V Arduino Pro Mini powered from 3 AA NiMH batteries. Is there a way to sense the power with the Arduino and switch a LED on when the voltage drops below a specific value ?

Thank you in advance.

Yes.
What you do is to switch the input of the A/D to the referance voltage and measure this with a referance voltage of the supply voltage ( the normal state).
Then you can work out the exact value of the 5V from what you measure the known 1.1V to be.

I don't get the idea. Do you mean I should simply connect the power source to an analog input of the Arduino ?

You can measure the internal 1.1V reference voltage relative the AVcc (which is normally connect to Vcc). If the supply voltage is 5V you would get a reading of about 225 ((1.1/5.0)*1024) if the supply voltage drops to 4V you will get a reading of about 281 ((1.1/4.0)*1024).

Unfortunately you can't use "analogRead()" to read the internal voltage standard. You will have to set the ADMUX register to 14 by direct port manipulation. Here is a tutorial that covers the ADC: http://fivefive.wordpress.com/2008/01/23/avr-tutorials-adc/

http://code.google.com/p/tinkerit/wiki/SecretVoltmeter
no external connections necessary, it even works with the attiny series with a little modification

this page also talk about it
http://www.ikalogic.com/avr-monitor-power-supply-voltage-for-free/

Couldn't you also use this?

you could with external components and change the reference but, the link I had has code for arduino to do it without any external components

Thanks a lot everyone ! This is very interesting.