I'm designing a schematic to supply power to another PCB. It uses a LM317 to reduce the voltage to a fixed value. I would like to use a 9V battery as main source, but considering that the device will also be used in a car, I would like to include also a connector for external power.
The connector I'll use on the PCB is a standard 2.1mm coaxial connector like this one: http://www.adafruit.com/adablog/wp-content/uploads/2011/05/21mmdcjackbbfront_LRG.jpg
Instead of using a separate switch I would like to use the third pin of the socket to detect when the connector is plugged in and automatically use external power, disconnecting the battery.
My problem is that I have no idea on how to do this :D Any help?