Raspberry Pi Shutdown Sequencer

One of the big problems some people have with using the Raspberry Pi, is that if it loses power unexpectedly, the kernel can be corrupted.   You can verify the user community’s frustration by googling “raspberry pi shutdown recovery”, or just go to this link and read the post:   Turning off Raspberry PI without proper shutdown

In this webpage, I demonstrate a solution I created to solve the problem.

Design Goals for this project:

  • Prevent corruption of the linux kernel on a Raspberry PI if power is lost by initiating a and sustaining a controlled shutdown sequence
  • Sense when power is restored, and automatically reboot the Raspberry Pi without human intervention
  • Provide an economical battery backup that will provide power to the Raspberry PI for a few minutes, so that a reboot might be able to be prevented if power is restored before the battery backup is drained
  • Keep cost low by using a variety of “off-the-shelf” UPS systems, including such things as battery cases that provide extra power to cell phones.

 

The next figure shows a block diagram of the design.        Any UPS can work, so long as it provides enough amperage to run the Arduino and the PI.

Block Diagram. In my solution, used a low-end Tripp-Lite UPS because I needed conditioned power, but you can use anything.
Block Diagram. In my solution, used a low-end Tripp-Lite UPS because I needed conditioned power, but you can use anything.

Schematic of the solution.     The TXB0108 Level Shifter can be purchased from a variety of places.  I got mine at Adafruit.

The heart of the sequencer is an Arduino Micro. Any Arduino (such as an UNO) could also work.
The heart of the sequencer is an Arduino Micro. Any Arduino (such as an UNO) could also work.

Timing is a always a little tricky.   This is how I chose to sequence mine.

Timing diagram for initial power on, and also for lost power condition.
Timing diagram for initial power on, and also for lost power condition.
One very likely scenario is that power is restored within a few minutes. Because of the UPS, it may be that the Rasperry PI will never lose power at all. This is all doable with the right program running on the Arduino.
One very likely scenario is that power is restored within a few minutes. Because of the UPS, it may be that the Rasperry PI will never lose power at all. This is all doable with the right program running on the Arduino.

That is about all there is to it.   It works like a champ.

 

 

 

 

Leave a Reply