Click here for a free subscription to "HDE" our site newsletter.

Automatic Power Off Shutdown For Raspberry Pi

Automatic orderly power off for microcontrollers

Raspberry Pi B+ image Raspberry Pi B+ Microcomputer

Microcontrollers need to be shutdown properly

Microcomputers like the Raspberry Pi and the Beaglebone are now affordable enough to use in all kinds of situations that they would previously never be considered for. Not so long ago a lot of the applications that these computers are being used in would have been built using a cheap microcontroller or even non-smart electronic components. Neither of these approaches need special measures to be applied when power is removed but microcomputers do, like most other computers do.

What happens if you don't do an orderly shutdown?

Computer operating systems tend to make extensive use of files stored on hard drives or SD flash cards. Some of these files are important operating system files and if they get damaged in some way the whole system may be affected. The easiest way to corrupt a file is to remove the power from the computer while it is writing a new version of the file. This is why most computers come with a shutdown procedure that must be followed before the power is removed.

Now that's all well and good if you are dealing with a desktop computer and the user knows how to shut it down properly as most of us do. It's a different story if the computer is monitoring a weather station or controlling the lights. Who is going to be bothered with shutting it down properly? I certainly will not so what can we do about it?

Power fail detection and automatic shutdown

The task is in fact quite simple to define. We need to detect when the power has failed and use a battery to keep the computer alive long enough to complete the shutdown procedure. The power fail signal can be fed to the computer via a GPIO pin to alert it to the power fail and start the shutdown.

The Power off delay circuit

In this article I'm going to go over the circuit that I'm currently using to provide the delay following a failure of the mains power. The output of the circuit is used to hold a relay energized which applies battery power to the computer until the delay expires.

Microcomputer automatic shutdown circuit Auto power off and shutdown circuit

In the circuit above I'm using a 12V power supply applied top left and a 9V battery supply to the right. The two supplies are seperated by diodes D2 and D9 which ensure that no current is drawn from the battery while the 12V supply is present and that the 9V supply does not feed into the 12V power supply when the mains power is removed. The diode D7 and resistor R12 provide a small 'trickle-charge' current for the battery whenever the mains is applied.

The DC/DC device is a 'Buck' converter which supplies 5V for the Raspberry Pi if either the 12V or 9V supply is available. This will be the case until the mains power is removed and the power off delay time has elapsed.

On the following pages I will describe the circuitry starting with the power off delay circuit.

Now subscribe to our newsletter and don't miss a thing

Comments (1)

Topic: A Power Off Delay For Computer Shutdown
Full StarFull StarFull StarFull StarEmpty Star 4/5 (1)
Full StarFull StarFull StarFull StarEmpty Star
Jacob (US) says...
In your Power Failure Detection Circuit you reference D12 and D13. I see them in the closeup of your circuit, however, they are missing in your overall layout. What happened to D6? Did it go away or is it in series just before D13?
17th February 2017 7:01pm

Add Comment

* Required information
(will not be published)
Bold Italic Underline Strike Superscript Subscript Code PHP Code Quote Insert line Bullet list Numeric list Link Email Image Video
Smile Sad Huh Laugh Mad Tongue Crying Grin Wink Scared Cool Sleep Blush Unsure Shocked
Enter code:
Notify me of new comments via email.
Remember my form details on this computer.
I have read and understand the privacy policy. *
I have read and agree to the terms and conditions. *
Click here for a free subscription to "HDE" our site newsletter.