This question already has an answer here:
I want to create a stand-alone internet radio device. Therefore I want to use an existing subwoofer box with connected speakers. Inside the subwoofer box there is the electronics for the sound system. There is also a 5V supply wire where I can connect my Raspberry to.
But what if my radio is running and I don't want to listen to it anymore? I can't just plug out the subwoofer box from the socket. This will cause the Raspberry Pi to lose its supply. The filesystem on the SD card will be harmed if such a plug-out is performed when OS is running. I'd like to properly shut it down by recognizing the plug-out and executing
sudo halt after that.
What is the best solution for my intention? I have thought of a backup battery for the Raspberry Pi. Just like the battery which is used on motherboards. But will 3.3V be enough? Is there a battery which can provide that much current to run the Raspberry Pi (Note: a HD44780 display and a WLAN dongle is also connected to the Raspberry Pi)? How can I assure the battery is not used when the regular 5V supply is available (to not use battery AND 5V supply at same time).
Any help is appreciated.