I'm designing a PCB to mount and interact with a raspberry pi4. One of the things I need it to do is drive a 24V relay. This circuit has worked great with some controllers I've used where the outputs are hardwired as outputs (they can never be inputs). I want to use this same circuit but am concerned as to what would happen if the driving GPIO (SM_EN) was inadvertently set to input, causing it to read voltage with nearly zero current draw. This would cause no v_drop across the resistors and the PI would see nearly 24V. This toast the PI's GPIO, correct? Can anyone recommend some protective circuit or settings on the PI that would prevent this from happening? Its weird to think of a circuit node as being able to read and set voltages. But, I'd imagine a simple OpAmp buffer circuit would do the trick?
DO NOT do this. If you connect this to a Pi it will put 24V on the GPIO and destroy the Pi.
Using a PNP transistor just makes everything more difficult.
You could control the device with an external transistor. This is similar to Use a 5V Relay Module with the Pi Addendum, although the voltages are different, the principle and problem are the same.