How to stop Arduino from drawing power through USB

If you provide power to the Arduino through Vin this will disconnect USB power through the MOSFET switch.

There are a couple of alternative solutions to the question that I think are worth mentioning.

  1. Use a data only USB cable or manually cut the VCC and GND wires of the cable.

  2. Remove the USB poly fuse from the arduino board.

  3. Connect external power to one of the input pins to measure the voltage. This measurement can then be used to determine if the external power is connected and is providing sufficient voltage. If it does the USB power should not be use anyways, otherwise an if statement can be used to disable the code that turns devices that draw power. USB power will still be used to power the arduino board itself. It also has a limitation in that because the power supply could provide insufficient current it could draw the remaining required current from USB.