I will be using the Raspbian Lite OS.

I want my Users to be able to switch the device on/off.

I am using a battery source for the main application.

I was thinking of providing kiosk browser UI (which I found some sample code for) to allow the user to click on my virtual button to shut the device down when not in use.

But, 'durrh' just occurred how can i get my user to switch the device back on? Or should I be looking at some 'sleep' functionality rather than looking to completely power off?


First, the bad news: The Raspberry Pi has no "sleep mode" - it simply does not exist. The good news is that Raspberry Pi doesn't use a great deal of power when it's running, BUT you should compare these power consumption figures against your battery capacity.

There are some "tweaks" available to further reduce power consumption; e.g. some hardware can be disabled via configuration file, and clock speed can be reduced. 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:
1. 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.
2. 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. Minimize power consumption via shutdown command

Given these drawbacks, perhaps a better alternative to the power switch described in the previous paragraph is to use the GPIO pins with a script to control the Pi's state. However, you should note that the RPi will continue to use power (approximately 60 mA) after the shutdown command takes effect. Basically, this solution takes the following steps:

  1. Halt the RPi (via the command sudo shutdown -h now). [see Note 1]

  2. 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.

3. Add hardware modules to achieve (near) ZERO power

There are other solutions that, for example, use an Arduino micro-controller to effect a switch closure and RPi shutdown in lieu of the momentary pushbutton described above. These solutions offer the potential advantage of a complete zero power shutdown without the increased risk of file corruption from an abrupt removal of power.

OTOH, if you'd like an "add-on" bit of hardware that will effectively add a "sleep mode" to your RPi with minimal effort on your part, you may want to look at WittyPi, or Sleepy Pi 2.

In closing...

Your question has thrown a light on an interesting and challenging problem, and as you can see there are a number of solutions that have been developed to tackle that problem.

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.

NOTE 1: Although halt and shutdown commands are implemented somewhat differently, there is no difference in power consumption once the machine is in this state.

  • If the RasPi is in halt state (after shutdown) does it consume power? May it be possible that you add this info to the answer? – Ingo Dec 21 '18 at 18:44
  • thanks for such a comprehensive answer I did look at the GPIO route + script before and purchased the components. I was looking at all possibilities as well though. I think the way I prefer to go is to minimise what is running and 'sleep' that way. thanks again :) – Andrew Simpson Dec 21 '18 at 18:52
  • 1
    I'm worried using the cable switch might encourage the user to regard that as the proper way to turn the device off, which all by itself it isn't. Not shutting the OS down properly will: 1) Slow your boot time because the root filesystem must then be checked when the pi is switched on again, 2) Significantly increase the risk of arbitrary filesystem corruption, which may or may not be fixable by the boot fs check. – goldilocks Dec 21 '18 at 18:57
  • @goldilocks: That's a valid point; I'll add a cautionary note. – Seamus Dec 21 '18 at 19:16
  • BTW: I have a few of those cables that came with Anker 5V 2.5A supplies, and they are all bad in the sense that no matter what supply they are used with, I get continuous undervolting on a Pi 3 (the Anker supplies themselves are also subpar, no matter what cable they are used with). Despite being sold "for the Raspberry Pi", there's some 1 star reviews there that reflect this too. – goldilocks Dec 21 '18 at 19:20

To be able to save battery power you will need additional hardware like a wittypi2 http://www.uugear.com/product/wittypi2/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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