I'm loving using my Pi with Openelec for my media center, but the need to pull the cord to cut power was just keeping it below the WAF(Wife Acceptance Factor). So I sat down and came up with this. In the future, the arduino will be replaced with an ATTiny, but for now I already had this on hand.
First off, I will start with what does NOT work...
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: What Does NOT Work
Rule #1 for my design was that the Pi should need NO software or modification for this to work. One should be able to hook up any Pi with an operating system on it and have it work. This eliminated almost every option out there right now.
In my researching, I learned that the UART TX pin goes high on bootup, and stays that way, until a shutdown is completed, and then it goes low. I spent some time going with that, but it ultimately was a dead end. The Pi knows it is high/low, but the arduino/microcontroller still just sees a floating pin, regardless of the configuration.
Step 2: What DID Work
In the end, I realized that using an arduino/microcontroller to sense a digital high/low on the Pi was not going to work, BUT it did lead me to the right path... When a pin on the Pi is high, it is outputting ~3.3v, but when it goes low, it drops to under 1v, so I just needed to connect a ground between them, and watch for the voltage to drop under 3v using an analog pin.
Step 3: The Bad Schematic
The schematic above was drawn to help, but it's pretty bad, so I will spell it out...
+5v to Arduino
+5v to Relay
Ground to Arduino
Ground to Relay
Arduino Ground to Raspberry Pi Ground
Arduino Ground to IR Receiver Ground
Arduino 5v to IR Receiver Vcc
Arduino pin 11 to IR Receiver OUT
Arduino pin 5 to Relay IN1
Arduino pin A0 to Raspberry Pi pin 8(UART TX)
Relay out inline with Raspberry Pi power input
Step 4: The Arduino Code
First off, you will need to delete the IRRemoteRobot libraries that are built in to the Arduino software, and then install the IRRemote libraries included here. Then program your Arduino with the IR Decoder code. This will show you the HEX codes of the IR signals in Serial.print. Find the Hex code of the button you want to use to turn on your Pi.
Then edit the "PI Power.ino" code by changing the variable "const long StoredCode". Leave the "0x" and change the Hex code after that. Then upload that to the Arduino.
This code is written so that it will stay off until the remote button is pushed. Once on, the arduino will ignore remote button presses, and will wait for a clean shutdown to be performed. On Kodi-based distros this is easily done also by remote. Once a clean shutdown is performed, it cuts power, and then goes back to watching for the remote button press.
Step 5: Final Notes
Now when you first plug everything in, the Pi will power on for a few seconds, then kick off and stay off. Just the nature of the relay while the arduino is booting. After that, it won't happen again. Just use your remote to power it on. When you issue a shutdown from the OS, it will wait until the shutdown is completed, and then cut power to the Pi.
I have Openelec on my Raspberry Pi, and I set it up with a Real Time Clock and a GPIO IR receiver. Everything fit inside the case of a Motorola SB6121 modem, with the HDMI port and power routed to the back side with the USB and ethernet ports. Now it is a completely self contained system that can be entirely controlled with a remote, and doesn't even need internet to keep time.
I know that the first pic looks pretty nasty in there, but in my defense it is a "first time test", and will get redone at a later point.