First off, some background.
I know plenty about computers and software but when it comes to circuit design I know just enough to be dangerous
I intend to install a Zero in my car but need it to power on when the accessory circuit first goes live, stay on over short drops in the accessory feed (e.g. over an engine start), perform a clean shutdown once the accessory feed has been off for a few minutes, and cut power to the regulator/UBEC.
The usual solution is, I guess, a UPS. But that adds significant cost, complexity, and why bother with another battery when there's already a big one under the bonnet (hood for you yanks)?
I've come up with the circuit below. It simulates OK but I'd appreciate some input on the validity of this approach. If I've drawn it out correctly, relay K1, is switched by the accessory line passing battery power both to a regulator/UBEC and back into its own coil (via relay K2) so it stays energised. On shutdown, the Pi switches relay K2 breaking the loop back to K1 thus cutting power to the entire circuit.
Softwarewise, a small daemon to mointor a GPIO pin coupled with the gpio-poweroff devicetree overlay should do the job.
Before anyone points out the obvious:
- Yes, R1 has the wrong value
- Yes, I should have a current limiting resistor between GPIO26 and Q1
- Yes, I've left out the protection diodes across the relay coils
- Yes, I'm aware that the +ve supply in a car isn't an exact 12v. It can vary between aprox 10v and aprox 15v depending on battery state and alternator output.
- S1 is optional. It's there to provide a kill switch in the event of a software failure.
- No, I'm not certain that D2 is needed. It works in simulation with or without it.