Most of us live under the simple algorithm : Plug a headphone into the jack and move on with life. But the beauty of it is what happens during those instances when you insert the jack and the mobile/laptop recognizes the device to be indeed a headphone jack.
Most modern smart-phones and laptops detect a headphone using the following simple principle :
Establish a potential difference between the mic and the ground ( ~ 2- 3 V ) and observe the resistance. If its high, its air and probably nothing has been inserted. If its really low, then a headphone jack has been inserted.
And the fact that a potential difference is constantly being given between the mic and the ground allows us to plug in a led and light it up .
Corollary 😉 :
All that the phone is looking for low resistance value. You can very easily fool the phone to think that an aluminum foil is a headphone jack.
Older headphone jacks
This answer by Rick on stackexchange answers this question so accurately :
” Headphone jacks have extra contacts inside, which act as switches. The the drawing below, pins 4 and 5 are intended for sensing that the plug was inserted. They are not intended for audio signal. When the plug is not present, the switche, which are formed by 2 & 4 and 3 & 5, are closed.
When the plug is inserted, these switches are open. The plug flexes 2 and 3 slightly, and they break contact with 4 and 5. You could insert a 3.5mm plastic rod [a dummy] into the jack, which will open the contacts, and the phone might think that earphones are plugged in. ”
Headphone jack plugged in or not ? (Software end)
In a previous post , we talked in depth about the /dev/input directory in Linux. This video talks about how the computer knows whether a headphone jack has been plugged in or not from a software point of view.