I knew I wanted to put a Raspberry Pi in my car, and I knew I would need a way to shut it down gracefully without having to think about it. Luckily, I'm not the first person to want this.
I found some posts on car-computer forums on Reddit detailing a circuit using 12v relaays, 5v relays and a buck converter in combination with a vehicles 12v constant, ground, and 12v ignition power lines to trigger a safe shutdown of the Pi.
This was the example circuit I based my hardware on. This continually supplies 5v to the Pi until the ignition switch is turned off, then the circuit remains powered by the constant 12v from the vehicle and a GPIO pin is pulled low and runs a shutdown script on the Pi.
All the parts were readily available on Amazon.
After receiving the parts, I set everything up on the workbench with a switched 12v source to emulate the ignition switch in the vehicle. This required some specific software that I will detail in another post.
After confirming that shutting down the Pi safely worked, I mounted the hardware inside a plastic case used for holding photographs using standoffs. I cut a hole on the edge to pass through the power cables from the vehicle as well as the USB cables for the wireless antenna and GPS receiver.
The GPS receiver I'm using is the GlobalSat BU-353-S4 USB GPS Receiver.
The wireless adapter I'm using is an Alfa AC1200. This required a little futzing with to get to work with the Pi, this thread pointed me in the right direction for getting the drivers I needed to make the AC1200 work with the Pi.
For now, the wireless antenna and GPS receiver aren't properly mounted, but I'm thinking about getting some suctions cups and sticking them on a window.
The plastic box containing the Pi and the relays lives in the foam piece that holds the tools for changing my spare tire underneath the panel in the cargo area at the back of my vehicle. I was lucky to have a 12v power port in the cargo area of my car that is controlled by the ignition, so I bought an adapter that plugs into the power port and gives me a power and ground lead to wire into my relay circuit. I also had a constant 12v supply at the rear of the vehicle for a trailer hitch, this was trivial to tap into for the 12v supply.