Recognizing the power source of the Arduino

Hello!
Is there a way to know what source an Arduino is being powered from in software? For example, I want to know if the Arduino is being powered by a computer via USB, or a battery or any other power source that does not provide Serial communication. That is so I can do something in software if there is Serial communication, and something else when there is not. Is that possible?
Thanks!

This comes up very often. The ATmega328 has no way of knowing what source is providing its Vcc.

You would need to modify the Arduino board to be able to tell which source is being used.

Is there a way to test for Serial communication?

Only on the Leonardo.

Otherwise, an applicaion on the pc must send something.

Any other alternative method besides the application on the computer?

10: "is there a way to recognize power source of arduino?"
20: Modify the board
30: "Another way?"
40: PC Application
50: Goto 10

This came up about a week ago. I think a number of us got insulted to within an inch of our life when we tried to respond. Try searching for that thread.

Nick Gammon:
Try searching for that thread.

I was about to do that. But I don't know what keywords to enter.

http://arduino.cc/forum/index.php/topic,113169.0.html