Determining which power supply is connected to our circuit?
You can use the ADC of a microcontroller. Leave the external AREF pin out of the picture and use the internal reference voltage (such as 1.1V for AVR chips), and feed the source voltage into the ADC channel by way of a voltage divider.

As noted by Brian Drummond, it would be a good idea to drive the voltage divider from an I/O pin (if you have any available). It will still be the full source voltage (or at least +95% of it). Then you can drive the pin HI, measure the voltage, and shut the pin off. This will prevent constant current flow, reducing power consumption.

The circuit shown will produce the following voltage levels:


5V -> 1V    
3V -> 0.6V
1V -> 0.2V








simulate this circuit &ndash; Schematic created using CircuitLab

Vout = Vin * R2 / (R1 + R2)