How to programatically determine if my Arduino is running from USB power or VIN?

Thanks for the replies, Majenko and Nick! They are enlightening.

That would require hardware changes - the OP wants software only.

Actually, I'm fine with hardware changes, if there isn't a software-only method, or if the software-only method isn't 100 percent reliable.

The on-board regulator will give the same reading whatever the input voltage. Compare it to the 1.1v Vref, and if it is the voltage that the voltage regulator gives you then you are running on wall wart. If it's anything else, then you're on USB.

This is the technique you linked to higher up on the thread, correct? That's software-only, right? Is that technique reliable? For example, it will work no matter what the voltage of the adapter I have plugged in?

Change that to "while (test if power not connected)" so they can plug in the wall-wart and have it recover without having to reboot.

Ah yes, of course. :slight_smile:

I'm going to experiment with Majenko's software-only method first, since it requires the least amount of work. However, the voltage divider diagram you provided, Nick, is extremely useful and looks like it would be very likely to be of high reliability! So if I run into trouble with the software method, I'll try that instead. Thanks so much!