First, the bad news: Currently, only the RPi4B has what might be considered a "sleep mode". And at 40mA, or approximately 5 watt-hours per day, this could only be considered "sleep mode" if you're still living in the era of bag phones. While the Raspberry Pi doesn't use a great deal of power when it's running, 72 watt-hours per day is beyond the capacity of batteries typically used for "mobile" (or even transportable) devices. YMMV, but you should compare these power consumption figures against your battery capacity.
There are other "tweaks" available to further reduce power consumption; e.g. some hardware can be disabled via configuration file, and clock speed can be reduced for less demanding applications. Here are some specific suggestions on reducing power consumption, and here are some more. If you're interested in minimizing power consumption in this way, determine what hardware resources you can live without, and edit your question (or post a new one) - we'll try to help.
I'll organize my answer to your question under 3 headings:
1. Brute force power removal
As far as allowing your users to switch the device on and off, perhaps the simplest solution is to wire your battery lead (positive side) through a switch. You can buy a switch that is said to do this from several vendors; e.g. this one from Amazon. The advantage this solution has over the one below is that power consumption is reduced to ZERO. However, be aware that there are a couple of cautionary notes for this approach:
- Powering off your RPi by removing power may create file integrity issues on your SD card, and is not considered good practice. In any event,
fsck
will be invoked on the next boot sequence, which will require additional time to boot.
- Some of the hardware sold in the "hobbyist market" is not manufactured to the highest standards. Be aware of this, and look out for new issues with your RPi after adding new hardware.
2. Reduce power consumption via shutdown
command
A better alternative to the brute-force power switch described in the previous paragraph is to reduce power using (one of the) halt
/poweroff
/shutdown
commands, and then toggle the state of GPIO3 pin with a pushbutton switch to restart the Pi. However, you should know that the RPi will continue to use power after the shutdown
command takes effect (see Note 1 below). Basically, this solution takes the following steps:
Halt the RPi via the command: sudo shutdown now
. (see Note 2 below)
Restart the RPi by connecting pin GPIO3 to Ground. This can be done using a "momentary" pushbutton switch that shorts GPIO3 to GROUND.
One clever way to configure the momentary pushbutton switch to "toggle" the RPi between OFF and ON is to monitor the state of GPIO3 in software, and execute a script that runs the shutdown
command above to halt the system. Once the system is halted, the next push of the toggle button will restart the RPi. This technique is covered in more detail here.
Of course there are other ways to halt the system, and then use the momentary pushbutton to restart it. For example, you could add a line in your crontab
file to shut the RPi down at a designated time (at 9:00 PM for example), then turn it on again by pressing the momentary pushbutton switch. Or you could write a script to monitor usage of some resource, and shutdown
based on that usage.
Update: If you have an RPi4B, there are additional options that will further reduce power consumption in shutdown
mode.
3. Add hardware to minimize RPi energy consumption
There are other solutions that, for example, use external hardware - even micro-controllers (e.g. Arduino) - to remove power from the RPi when it's not needed. These solutions do not reduce the RPi's power requirements, but they can greatly reduce its energy consumption; i.e. power over time.
Generally speaking, these energy-reduction solutions invoke a shutdown
of the OS to preserve filesystem integrity, followed by disconnecting the RPi's external power source to . As of this writing, an automated re-start of the RPi is possible only from an external source; e.g. realtime clocks, sensors or other external systems (incl. "HATs").
Energy-reduction solutions are available as commercial products, or perhaps more usefully as DIY solutions that allow customization for a particular use-case:
4. In closing...
Your question has probed the interesting topic of power management on the Raspberry Pi. The holy grail of RPi power management is battery operation, but given its current hardware design this remains a challenge for many applications. However, demand from the user community, clever solutions from developers/users, and The Foundation's gradual improvements to their proprietary firmware are making useful inroads. In the meantime, a number of solutions that have been developed - some commercial and some DIY.
Suggest you try something simple to start, then build on that. You can post specific follow-up questions once you've got the basic functionality working.
Notes-
NOTE 1: How much power does the RPi consume after entering shutdown
mode"?
- In general, this depends upon which model of RPi, but...
- For my RPi 3B+, I measure 80-90mA
- For my RPi 4B, I measured 40-370mA.
- Others have made measurements - for example
NOTE 2: Although halt
and shutdown
commands are implemented somewhat differently, there is no difference in power consumption once the machine is in this state.
halt
andshutdown
are not the same state, and power consumption is different (halt
has much higher power draw in general). That said, I've not found an "official" spec on power consumption in shutdown mode, only anecdotal data. – Seamus Dec 21 '18 at 19:22halt
command from linux triggers this state but it seems it is not the case as you show. But that's all academic and not important. – Ingo Dec 23 '18 at 09:18