I’m running a Raspberry Pi in my car with an official screen (link: https://www.amazon.com/dp/B073S3LQ6Q/ref=cm_sw_r_cp_api_i_dl_ZSPC0NJXFQVBZ19PXGCP?_encoding=UTF8&psc=1). It’s for obd. When I turn off the car, the radio’s lights and USB ports stay on for about 5 seconds and then turns off. The cigarette lighter turns off immediately.

Long story short: I want to write a script that shuts off the Raspberry Pi when it detects the screen turning off.

It might be basic and I’m sorry. I don’t use Linux or the Pi that often and I couldn’t find anything when searching.

  • 1
    it's not a pie ... vimeo.com/617402918 ... lol
    – jsotola
    Commented Mar 29, 2022 at 23:16
  • you are thinking about it the wrong way ... don't be thinking "Raspberry Pi" ... be thinking "Linux computer" ... Linux logs almost every event ... check logs for events that coincide with screen power off ... use that to trigger a script
    – jsotola
    Commented Mar 30, 2022 at 1:03
  • Your question is far from clear. You need a definite signal which may be derived from the power which goes off. However you detect it, 5 seconds is too short for reliable shutdown.
    – Milliways
    Commented Mar 30, 2022 at 5:59

1 Answer 1


Like @jsotola and @Milliways stated, this is not the best way place to ask this question, since I think it's more of an electronics question than a Raspberry Pi question. And I also think that 5 seconds would not be enough to shut the Pi down properly. I'll try to give you my best advice.

Safest / most stable way

Where do you feed the Pi from in your car? The cigarette lighter? I would strongly advice against that. If you are planning to keep this system in your car, I would do some small surgery to your car, and make a simple circuit to shut down the Pi properly.

First of all, I would power all devices directly from a 12V cable which comes from your car battery (with a buck-converter, since 12V will destroy the Pi).

Every single vehicle also has a switched 12V connection. (Find it with a multimeter, by measuring wires and turning on/off your contact switch). I found my cable behind the switches that turn on my lights. You can use this switched 12V as a 'flag' for your circuit, to know when the user wants to shut down the system.

When you detect that the switched 12V has gone to 0V, you can then instruct the Raspberry Pi to shutdown peacefully. As last thing before it shuts down, you would need to trigger a relay that disconnects the constant 12V supply from your system, else you won't be able to turn it on next time :P

Now, next time when the 12V switched goes back on, you need your relay to enable the constant 12V back to your Pi. And the whole circle can work again.

This way, you will know for certain that the Pi will be able to shut down properly, because it will disconnect it's own power supply as his last step before shutting down.

I don't have a schematic for you, but you should be able to pull this project off, with 2 relays and a beefy enough buck converter (and maybe some passive components)

Easiest way (but dangerous)

You could also just pray for the best, and hope that the EXT4 File System saves your butt every time (when you just remove the power from the Pi to shut it down). I would strongly suggest against this, because after enough power cycles, something will probably go corrupt eventually (even with EXT4).

You could also try and detect the screen going off like you said, but since you don't know for certain that it will always shut off in time, it would be almost as dangerous as just always pulling the power supply from the Pi.

I've had this happen to me as well. Doesn't happen that often, but is a pain when it does.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.