Electronic – best way to detect if vehicle is running

automotiveraspberry pi

The plan is to place a Raspberry Pi in a vehicle togheter with a camera and fully automate the startup/shutdown of the raspberry. So – what is the best way to detect that the vehicle is running?The first thing that comes into my mind is – check if the alternator outputs some voltage. The first problem appears when starting car.The alternator produces some voltage. This can be solved with some electronics (RPi power controller RPipc), to give power to the raspberry after 20 seconds when the alternator starts producing some voltage.

The second problem is shutting down raspberry. Again – RPipc can monitor alternator output and if alternator is not producing any output (or below some voltage), then send a signal to raspberry GPIO and then the script stops all apps and shuts down raspberry pi.After one minute (some time) RPipc turns off power to the raspberry pi.

Power to raspberry pi can be provided via some relay witch is controlled by RPipc.

At this moment i do not plan to place some ODB2 tool to vehicle and attach it to raspberry pi. And my car ODB connector is under a cover in the front of the center console: ODB connector location If i want to permanently add the ODB diagnostics tool, i am going to need to solder another connector.

EDIT:
Also RPipc must wake up after it receives a signal from the alternator and cut power when the vehicle is turned off. But my question is about how to detect if the vehicle is turned on (engine is running).

EDIT 2: Here is schematics for voltage feeder

Best Answer

Most cars have 2 12V lines, a permanent one (12V from the battery) and switched, which is active after half a key turn in older cars, and after the ignition button activation in newer cars. You can use a voltage divider and connect it to a digital IO to detect it. Also, add a varistor to it, car voltage lines have nasty spikes which can easily fry your electronics.

Detecting whether a motor is running or not, you need to sample the 12V line and see if it is above 12V. Usually, the alternator generates 13 to 14V.