+5V on USBVCC when powering from external source?

Hello,

I was trying to understand p-mosfets, but failed on getting the information I need.

I'm preparing home automation project with the power outtage detector. I want to have a power setup like this: 1. Normal operation -> Power comes from external 5V USB-B charger connected to USB connector AND PWRIN 12V source disconnected by a relay. 2. Power outtage -> Relay kicks and and power comes from external UPS (http://www.01.ee/en/product/681556). The router is powered from this UPS, so I need 12V from it.

Problem is, that I don't know how to detect that external 5V charger is disconnected. I wanted to connect USBVCC to arduino pin (with pulldown resistor), but if I disconnect USBVCC and power the arduino only from PWRIN then I receive +5V on the USBVCC, thus I can't use this to detect that USB charger has no power. And I have no idea why is that and how to prevent it.

I could power the whole thing from 12V source, but I don't want to put too much unnecessary stress on the regulator. Also I could add additional regulator to drop down this 12V to something smaller, but I wanted to avoid adding new components.

Any suggestions why I get +5V at USBVCC when I power the arduino from PWRIN jack? Or maybe some other suggestions.

If you try to detect power loss by testing the supply you have lost power to the Arduino as well so how do you detect with the Arduino turned off?

You need to rethink how you do this.

Weedpharma

Depending on what else you are powering from the Arduino, you may not have any problem running from 12v.

Otherwise use a switchmode power supply to drop the 12v to around 7.5v into the external power or 5v into the 5v input.

Weedpharma

weedpharma: If you try to detect power loss by testing the supply you have lost power to the Arduino as well so how do you detect with the Arduino turned off?

You need to rethink how you do this.

Weedpharma

When the 5V from power socket drops I planned to use 12V DC from UPS. I don't mind if Arduino restarts at the point of switching or not.

Arduino is powering bunch of sensors, dht22, fire, movement, noise, atmospheric pressure and water + Ethernet shield + 2.8" tft screen. I didn't measure the current drawn, but when I power it all from PCs USB I have no problems in terms of stability. But as I was reading, the power regulator gets hot at 12V, even if there is little current flowing.

A switchmode is the way to go then.

Weedpharma

How about this approach?

(ground connections not shown)

If you wish you can monitor 12V mains power supply via a voltage divider.

No need for a relay and no delay while the relay kicks in.

Look at the UNO schematic. The USBVcc is switched OFF by a mosfet when Vin > 3.3V.

You can use zn opto- isolator to deyect 5V. It' very straightforward.

raschemmel: Look at the UNO schematic. The USBVcc is switched OFF by a mosfet when Vin > 3.3V.

You can use zn opto- isolator to deyect 5V. It' very straightforward.

It is switched off by the mosfet, but somehow there is 5V on USBVcc when powering from 12V external. I don't understand how this 5V goes backwards to USBVcc, but apparently it does.

Thank you for great ideas guys. Will it be ok if I use the equipment I have (It's christmas, I would have to wait til next week to get parts like opto-transistors or 12-7V voltage regulators) to make it like this:

|500x195

You basically have a voltage divider into your analog pin. There is another thread explaining this.

http://forum.arduino.cc/index.php?topic=367136.0

raschemmel:
Look at the UNO schematic. The USBVcc is switched OFF by a mosfet when Vin > 3.3V.

As there is a 2:1 voltage divider, the MOSFET will be switched off when Vin > 6.6V.

outofoptions: You basically have a voltage divider into your analog pin. There is another thread explaining this.

http://forum.arduino.cc/index.php?topic=367136.0

Yes, I've put on the "schema" the voltage divider, if I calculate correctly, for 12V I'd get something around 3.3V on the pin. In the mentioned thread guy connected the 5V without resistor to the pin, but I guess that using this voltage divider like in my diagram would be correct?

This is the question the link answered.

Garreth: I don't understand how this 5V goes backwards to USBVcc, but apparently it does.

You don't have the same ground for USB and your circuit so you do not have a common reference You can't be sure the voltage difference you caculated between your circuit and your computer is going to be accurate. This is why grounds are normally tied together It MIGHT BE be but you don't know. You have at least limited the current.

How did you conclude you had 5V going back to the USBVCC ? Was there a USB cable plugged in and if not where did you measure it ?

raschemmel: How did you conclude you had 5V going back to the USBVCC ? Was there a USB cable plugged in and if not where did you measure it ?

I took out everything from the board - no shields, no sensors, nothing. Then I connected ONLY 9V battery to 2.1mm jack power input and I started measuring. For the ground referrence I tried both battery "-" and casing of the USB socket, for positive I touched the pin 1 in usb-b port (as a matter of fact I tried all of the pins in usb connector, but voltage for fortunately only on pin 1). Is there something wrong with my board?

You're probably seeing leakage back through the mosfet channel, ground the USBVCC pin with a 20k resistor and test again. Your DMM has very high input impedance so don't put enough load on the pin to drain off the leakage.

The Mega has the same circuit (T1,T2) Mega SCHEMATIC

Pulling doesnt help. But I may have figured it out. At my Mega board, the P-mosfet is labeled as A1SHB and googling this out returns me to this note http://pdf.datasheetcatalog.com/datasheet/vishay/70627.pdf . It has different Vds, and lots of other parametes, so maybe I got the mega built on cheaper parts?

Garreth: I took out everything from the board - no shields, no sensors, nothing. Then I connected ONLY 9V battery to 2.1mm jack power input and I started measuring.

Are you sure the battery remained more than 7.3volt (6.6volt Vin + 0.7volt reverse protection diode) during measurements. 9volt batteries droop very quickly. Leo..