54

I am a new Arduino user. I am not sure whether I can connect both USB and external supply through power adaptor to Arduino simultaneously. Would this burn the controller?

Basically, I want to automatically shut down the computer after saving all open documents before my UPS battery goes out whenever I am not there to manually shut it down. I am trying to notify the computer about the power failures of main supply - AC 220V 50 Hz (notification/signal sent when power goes out) via USB using Arduino. I am thinking that this can be done by using the external voltage power supply pin. Whenever power goes out in the mains, the external voltage power supply pin will drop to 0 V from 7 V. The value of the voltage can be read using software ( I am unclear about this: Can it be done? If yes, how?). The Arduino will still be powered up as it is connected to USB of computer and thereby communicates to the computer about the power failure.

2 Answers 2

12

From arduinoBoardUno:

Power

The Arduino Uno can be powered via the USB connection or with an external power supply. The power source is selected automatically.

Put the external power through a voltage divider or transistor-based inverter and into an analog (divider) or digital (inverter) pin and check the appropriate value from the pin. Note that this does not require powering the Uno from external power, only connecting the grounds.

5
  • Ok. Thank you for the answer. What will happen when I power them through both USB connection and external power supply. If it selects automatically, what source will it select?
    – Jagat
    Commented Mar 24, 2014 at 10:56
  • 2
    According to the schematic external power will be chosen if it's above 7.4V or so, otherwise USB power. Commented Mar 24, 2014 at 11:01
  • Only connect the grounds. Won't that be done automatically by the Uno? (Or are you referring to the voltage divider setup?) Commented Mar 24, 2014 at 21:49
  • @AnnonomusPerson: Neither of the voltage divider nor inverter configuration require the Uno to be powered by the external supply; it is only used for sensing. Commented Mar 24, 2014 at 22:17
  • 2
    The answer may be factually correct, but it seems confusing to me (as a novice user). Is misses some summary (can I have both at the same time or no?). What is this voltage divider talk about? Do I have to use a voltage divider to have both powers at the same time, or is this an experiment to prove someting?
    – Suma
    Commented Aug 6, 2014 at 7:16
69

I am a novice user of Arduino. I am not sure whether I can connect both USB and external supply through power adaptor to Arduino simultaneously. Would this burn the controller?

Lets study the schematic of Arduino UNO R3

The input from the power supply plug (PWRIN, the power jack) goes through a diode D1 (to prevent reverse polarity), and feeds a NCP1117 regulator that down converts it to the 5v supply that feeds the 5v parts.

Power input

The alternative supply comes from the USB plug (USBVCC). The relevant circuit is shown below

enter image description here

The USB power lines goes through a P-mosfet (T1) that operates as a switch and then goes to the +5V node (that is the +5v regulator output as shown in the first schematic).

The mosfet is controlled by an LMV358 operational amplifier (OPAMP) that operates as a comparator.
The negative input of the opamp is tied to 3.3V and the positive one fed through a voltage divider with half the Vin supply level.

  • When Vin >6.6V then the + input of the opamp become higher than the - input and the opamp turns the mosfet off.

  • When Vin <6.6V then the + input of the opamp become lower than the - input and the opamp turns the mosfet on.

Note that Vin is after the input diode so it's about 0.6V lower than the external connected power supply level. So when there is power supply connected to the power input that is higher than 6.6V+0.6V (where 0.6V is the diode D1 voltage drop), then the USB supply line is cutoff (because the mosfet turns off) and the power is provided from the power plug. Connecting or disconnecting the USB supply in this case will not make a difference, so you can have both power supplies connected simultaneously, only when the power input drops below the specified level (about 6.6V+0.6V=7.2V), the USB will start powering the board.

8
  • 4
    +1 Excellent answer: very detailed, precise and didactic.
    – Ricardo
    Commented Mar 24, 2014 at 18:28
  • 2
    Note that while D1 adds protection for the PWRIN pin it does not protect from eg reverse polarity on Vin. Commented Feb 25, 2015 at 15:13
  • 1
    I know this is a bit old but isn't there a danger of damaging something (your Arduino or a USB port)? For example, while plugged in to USB for serial output and using a battery pack for powering a motor shield, if your battery pack drops below 7.2V, the Arduino would try drawing all that current through USB, either destroying your board or your USB port. I know it's not the exact situation the OP was asking for but I arrived here via Google for a different situation so I think the clarification is useful. Awesome answer, by the way!
    – sraboy
    Commented May 10, 2016 at 21:42
  • 1
    @sraboy Motor Shield uses the 5V line only for the logic circuitry section, the motors are powered from a separate line. You describe a situation where the motors are powered by the raw supply line Vin (7.2v battery) and the rest of the circuit from the 5V line. If the battery is depleted then the 5V of the USB with just keep powering the logic circuitry of the motor shield and Arduino, the motors would not get any power because there is no path from the 5V line (which is after the 5V regulator) to Vin (which is before the regulator).
    – alexan_e
    Commented May 14, 2016 at 7:38
  • 1
    @alexan_e I appreciate the clarification!
    – sraboy
    Commented May 14, 2016 at 20:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.