1

Sorry if this has been asked before, but I've read tons of threads and it seems the answer is only implied on a couple of occasions.

I'm an electrical noob, but I understand that a 9v battery plugged into a wall wort with a diode would serve as a battery backup if the power was cut from the wall wort. I also understand that Vin on an arduino already has a diode to do this.

I'm currently powering a temp/humidity that is dumping data into MySQL using a standard A-B USB cable and 5V DC USB power supply. I'd like to incorporate a 9V battery plugged into Vin and ground, so that if DC power turns off, I can dump the data onto the SD card instead (since my MySQL server may or not be running during an outage).

9
  • A few questions: 1) How much current does the board take when active? That helps size the battery. I doubt a standard 9V battery is large enough. 2) Is it acceptable for there to be a brief interruption? (eg. while switching supplies) 3) How long an outage are you planning for? Minutes? Hours? That helps size the backup battery.
    – Nick Gammon
    Apr 15, 2016 at 21:59
  • Another question: Are you powering from USB for any reason? Except simplicity? If you powered from a wall-wart and put 12V into the power jack, then the simple solution of using a diode to Vin from a suitably-sized battery should work. (The battery would need to be 10V or less to allow for the diode voltage drops).
    – Nick Gammon
    Apr 15, 2016 at 22:57
  • @Nick Gammon 1) I haven't tested this yet, but I'm sure it will be quite a bit. The completed project will include the Uno, ethernet shield, sd card, and 2X16 LCD display. 2) A brief interruption (anything less than a few minutes should be fine) 3) Hours, most likely. If an outage is more than a couple hours, the freezers will be emptied to reefer trucks. Apr 18, 2016 at 20:42
  • @Nick Gammon No, there's no reason I'm using USB. I guess that's part of my question. Is the 9V solution possible with the wall wart, because if so, I can use that. I'm only powering off USB because that's what the uno usually comes with. I'm not doing any data transfer with it or anything. Apr 18, 2016 at 20:43
  • I doubt that the 9V battery will last hours. It might last long enough to send out a cry for help. Presumably one would be enough. But if the power goes off it might take a while for the temperature to drop enough to send an alert. You could try 6 x AA batteries - that would give you 9V and hopefully last a while. You could also test if the batteries are low with a voltage divider and an analog read. If the power goes, will you be able to use the Ethernet shield? Won't the router also be off?
    – Nick Gammon
    Apr 18, 2016 at 20:51

2 Answers 2

3

No, when you have 9V hooked up to Vin and 5V coming in from the USB, it will use power from the 9V battery, not usb and the battery will quickly be depleted.

1
  • You are right. I misread the question as being about something plugged into the power jack.
    – Nick Gammon
    Apr 15, 2016 at 10:15
3

My problem with that is that the other side of the diode on the Arduino is normally powered up. So for example if you have a 12V supply in the power jack you'll have 11.3V at Vin (because of the diode drop). Thus you are pumping 11.3V into your 9V battery which won't be designed to handle it. It will probably get hot and explode.

You would need another diode specifically between the battery and Vin. And make sure that Vin is at least 10V so that the normal mains power does not charge the battery.

Bear in mind a 9V battery doesn't have much capacity. With the power LED on, taking sensor readings, and sending data via Ethernet (if that is what you are doing) you may have only bought yourself 15 minutes.

I have a post about a temperature and humidity sensor which runs all the time from 3 x AA batteries. I think the batteries need replacing about every two years. The data is written to an SD card which you remove and plug into your computer when you want to.


when you have 9V hooked up to Vin and 5V coming in from the USB, it will use power from the 9V battery

Looks like I misread the question. @mwwalk is quite right. If you supply more than 6.6V through Vin then the circuitry switches the USB off. See here:

Uno power switching

Vin is provided by the power jack (after a diode which drops it by 0.7V) - see blue ellipse. In any case (power jack or not) Vin goes through a voltage divider (two 10k resistors to the left of the red circle). This is compared to the output of the 3.3V voltage regulator. Therefore GATE_CMD is HIGH if Vin exceeds 6.6V. This turns off the MOSFET (green circle) and disconnects the USB power.

2
  • You're project looks pretty sweet, but unfortunately SD writing won't work for me. I'm trying to develop a temp and humidity sensor that can be used for monitoring environmentally controlled rooms, areas, and freezers in a manufacturing facility. I'm putting the data into MySQL so that current temp/humidity can be shown on large TVs live, as well as pulled up from anywhere in the shop via browser. Apr 15, 2016 at 13:12
  • Well, you did say I can dump the data onto the SD card instead. I thought you were actively considering this.
    – Nick Gammon
    Apr 15, 2016 at 21:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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