power source: wall charger AND battery

Hello,

for my project, it is very important to have a reliable power source! Therefore, I will use the electricity from my house with a wall charger (AC-to-DC adapter (wall-wart)). However, because I need a reliable power supply, I want to use a battery pack (6 batteries à 1.5V = 9V) in the unwanted case of a blackout (power outage).

How can I do the following: Use always wall-wart and only if there is a blackout then use the batteries. ?

Thank you

If you are primarily using mains power but also want a battery backup; why not use rechargable battery? Here's an example of a small module that can take DC from a wall wart like you planning to use keep a LiPo battery charged, and if the power goes out it draws from the battery. If you want to build a similar charging circuit from scratch there are designs available in various places online.

This idea might be also worth a try. However, I would be happier with a solution using normal unrecharable batteries that supply my Arduino in case of a blackout. Could I just use both power supplies togehter? Something like a Uninterruptible power supply would be perfect because then my Arduino doesn't even has to restart.

There are many examples of homebuilt UPSes, this page should be a good place to start looking at your options.

Edit: Just so you know, the module I linked to switches over automatically. It also shouldn't cause anything it's powering to restart when switching to or from the battery.

I found this site FARMHACK - FARMHACK and it seems very easy.
On the bottom of the schematics, there is written "to Arduino", that means VIN ?
And at the top: This should go to Arduino's GND?

karlok:
I found this site FARMHACK - FARMHACK and it seems very easy.
On the bottom of the schematics, there is written "to Arduino", that means VIN ?
And at the top: This should go to Arduino's GND?

Yes you are correct on both counts. VIN is the pin used to connect to an input voltage you want to pass through the on-board voltage regulator, and you want to tie all the grounds together to a GND pin.

Edit: FYI, you could use rechargable NiMH AA batteries if you wanted. The total voltage would be a little lower (the cells are ~1.2 VDC instead of ~1.5 VDC), but they'd still be over the minium extra voltage necessary for the regulator to supply 5 VDC correctly. However since this circuit just controls what source the voltage regulator uses, you would need to have a separate charger and perhaps another set of 6 batteries to swap when needed.

Hello,
I added a picture how I imagine this how it will look like if its complete.
Is it right?

karlok:
Hello,
I added a picture how I imagine this how it will look like if its complete.
Is it right?

Yes, you can wire it up like that and it should work fine.

Oh, thank you very much!!! I think this is the easiest solution for my issue. Unfortuantely, I cannot test it because of a lack of diodes. It is just one thing that I miss and would be great if this was possible somehow, to see if V1 or V2 is used, maybe with some kind of digitalRead and two wires attached after the diodes? Any idea to do this?

karlok:
maybe with some kind of digitalRead and two wires attached after the diodes? Any idea to do this?

Remember, you don't want to attach these voltage levels directly to any Arduino I/O pins, they will be at least 1 volt over 5 VDC those pins are made for. What you could do is have each pass through the input side of an opto-isolator (also called an opto-coupler) with the photo-transistor powered by the +5V pin from your Arduino. The photo-transistor in the two opto-isolators can be biased to work as a switch and can safely be wired to an I/O (you'll need one per opto-isolator).

Far-seeker:
they will be at least 1 volt over 5 VDC those pins are made for

Oh, I forgot this.
I will think about a solution for this when I have finished the actual idea.

I have still a problem:
I am afraid that the current "I" is the sum of the two power supplies. I already know that the voltage "U" will not be the sum because the power sources are switched parallel.
Is this really the case, and if it is the case: Do I have to be afraid that the Arduino cannot work with that?

You don't need to worry about this in this case. While it is true that the current at a node is the the sum of all currents flowing into it, in this case these currents shouldn't be excessive.

This is partially because both the wall wart and the battery are (more or less) constant voltage, variable current power sources. While it is possible to draw upto some limit of current from either source, neither source is trying to force a specific level of current into the circuit (as would be the case for a constant current source). So the actual current drawn is going to be determined by the load the rest of the circuit presents to the power source; the most the power source can supply if positive is shorted to negative, a little bit less if the load is slight, or not a lot if the load is large.

The other reason it's not going to be an issue is the built-in current limiting features of standard Arduino boards. Because the power is going through the voltage regulator circuit, it will basically only draw the current necessary to power the board and anything powered from the board. Now a short either on the Arduino board, or in another part of the circuit could possibibly cause damaging amouts of current to be drawn, but unless there is a problem like that the current won't be excessive.

Of course, this isn't the case if you want to attach 5 VDC to the +5V pin, or 3.3 VDC to the +3.3V pin . Then you would need some way to limit the current to below the microprocessor's rated maximum current (this information will be in the datasheet for the specific microprocessor chip in question).

Thank you very much! Now, I feel sure that this will won't cause trouble.
I think this is a very easy way if you want to have more than one power source
However, can I be really sure that the battery's voltage is always less then the one from the wallwart? It is very important for me that the battery is only used if the main power supply isn't working anymore. (I want that the batteries aren't even used if everything is normal.)

With a design this simple, being completely sure the batteries won't draw any current while the main power is still on isn't possible. 1.5 VDC is only the nominal voltage for alkaline primary cells. A completely new battery may actually measure higher than 1.5 VDC on multimeter, and one that's partially discharged will measure somewhat less than 1.5 VDC. So it is possible for a very fresh set of six alkaline AAs (e.g. if they each are about 1.6 VDC) to initially have higher voltage than a 9 VDC wall wart outputs (which may also be slightly above exactly 9 VDC). However, most of the time the batteries will have at least slightly lower voltage, and that should be enough to keep any current drawn from the batteries very small unless the main power goes out.

That sounds good. There should be a preassembled module for this, something like an "uninterruptible power supply for Arduino" that also has the feature to select the priority (the order) of each power supply (i.e. wallwart first, battery pack second, maybe something else third...).

karlok:
That sounds good. There should be a preassembled module for this, something like an "uninterruptible power supply for Arduino" that also has the feature to select the priority (the order) of each power supply (i.e. wallwart first, battery pack second, maybe something else third...).

There might be, or at least someone else building one and posting the schematics, and I just haven't run across it yet. You might want do a Google search with similar terms.

Well ideally there should be an i2c/spi that tells when it is being powered from different sources. Particularly if the Arduino needs to store stuff to EEPROM or SD card, it might like some advance warning about the power changes. And when you have the wall power, it should charge the secondary batteries.