The anatomy of a headphone jack

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.

drawing

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 :

Yjl5u

” 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.

The ultimate guide to using LEDs with headphone jack

drawing112

Lighting up an LED using the headphone jack is probably one of most easiest tasks. Take the mic of the TRRS pin ( or left in a TRS ) and connect it to the shorter end of the LED. Take the ground and connect it to the longer end of the led and you are good to go !

A potential difference of ~3V exists between the two pins that is sufficient to light up a LED. Why is there a potential difference in the first place ? Well, this will answered in great detail in one of our post on the Anatomy of a headphone jack.

Now no one wants to stop with just lightning up a LED, so let’s improvise..

 

Controlling LED brightness

Like we said: A potential difference of ~3V exists between the two pins that is sufficient to light up a LED.  By controlling the volume, we can reduce this potential difference and thereby dim the LED.

 

You can control 2 LEDs (min.) with a single headphone jack

With a simple headphone jack, one is capable of controlling 2 LEDs at the very minimum. Take 2 LEDs and connect them both to the Left/Right in the configuration shown below:

drawing-1

If one plays a square wave through the Left/Right then the first LED would light during the positive half of the cycle and the second one during the negative half. This is because LEDs are conductive only in one direction.

You can watch a demonstration of this in the following video.

And as a bonus, we did a frequency sweep  from 1 – 30 Hz (Square Wave) and here is how that looks:

Hang on a second!

If you can do that, then you play songs and also visually witness Beats phenomenon right? Absolutely!

Visualizing songs using LED

Beats phenomenon

Headphone jack as a switch

In all our above setups, we connected the jack directly to the LED. But one might need the LED to be brighter. So, to do that we had to bring in a operational amplifier ( LM324 ). This can be powered using a OTG (On-the-go) cable or using an Arduino.

drawing-2

Now using this we can use the headphone to perform switching operations. And this is what we demonstrate in the following series of videos:

Schematics/Circuit diagrams will be uploaded soon! Thank you.

 

 

 

Preparing a headphone jack for hacking

This is one of the most frequently asked questions regarding our project on the headphone jack : I have an old headphone, how do I configure it to do all the stuff that you feature on your blog ? This post will be a pictorial DIY edition of it.

One of the first steps is to procure an old headphone ( in working condition or otherwise).

headphones-678033_640

And then cut off the mic and the rest of the earphones with it. ( But don’t throw it away! ) The reason why we do this is because when you want to hack into a device, its a boon to have accessibility to the Input/Output ports.

schematics

When you strip open the wire that you have, in the case of a TRRS headphone jack you will find 4 wires (Left,Right,Mic and ground) and with a TRS (Left, Right and Ground). The next step is to attach female jumper wires to them so we can plug in anything we want.

aaaa.jpgIMG_20170615_001144

These wires are not your conventional “plug and play” type i.e If you take these wires  and plug them into anything it won’t work. This is because they have a non-conductive plastic-like coating in them that prevents the wires from shorting.

Therefore soldering them to the jumper wire is a bit tricky. But in our experience it helps to preheat the wires before soldering and also to wrap the wire in a braid fashion for longer life.

IMG_20170615_020254IMG_20170615_021617

And similarly you solder the rest of the wires as well. Now in order to find out which wire corresponds to what, connect a speaker between the Left/Right and the ground, plug it into your computer and start playing tones.

IMG_20170615_023307drawing1

If you are asking where am I going to find a speaker ? Well just use the speaker from your headphone that you stripped off in step 1 and solder two wires to its terminals like the picture above and you are all set.

 

 

The headphone jack meets an actual spark gap!

So, we had the opportunity to test out the headphone jack with an actual spark gap and it was absolutely wonderful. Check it out:

With the data we can actualy find out the frequency of the spark occurrence. In our case it turned out to be ~ 34 – 36 Hz. And since this is in the Audible range we can actually hear this (somehow we missed this when making the video)

Screenshot from 2017-06-10 20:01:07

Audio file : GoogleDrive

**

Part – I – Lightning detector with a simple headphone jack

Part – II – Detecting switching ON/OFF of Tube Light using headphone jack

Part – III – Cigarette lighter spark detection using headphone jack

 

It is ridiculously easy to generate any audio signal using Python

Updated: May 15,2019

Now it comes as a surprise to many people when I tell them that generating an audio waveform is extremely simple.

One needs to have basic understanding on how audio signals work and basic python programming to generate any audio wave form. This post will show you exactly how.

Python packages needed: Numpy, Scipy

Screenshot_2019-05-15_11-06-02

How to play the audio the generated audio file on computer ?

1. Command line using SoX

play -t raw -r 44.1k -e signed -b 8 -c 1 test.wav

where -r = sampling rate -b = sampling precision (bits) -c = number of channels

2. Use Audacity (check video)

 

Link to code : GitHub

You can find a list of other waveforms that can be generated using SciPy here

Known Issues:

[1] This does add any headers to the audio file and therefore you cannot play it on any media player as is . Check this reddit post if you really want to have one.

[2] Adding headers to the above code seems to be making it slower. And this is a problem if you want to make larger audio files.

[3] The code generates only 8-bit audio signal. Feel free to play around with the code to change it to other formats.

[4] A lot of technical details were conveniently not included in code in order to appeal to the theme of this post. And therefore this code is not “efficient”.

Lightning detector with a simple headphone jack

Okay, this probably one of those posts that is ecstatic to draft because of the shear wonder that it encapsulates. We captured lightning using nothing more than just a mere headphone jack and its so simple that anyone around the world with an access to an old headphone jack can do it too!

Setup

schematics

Take an old headphone jack and strip off the mic part and you are good to go OR if you have a dedicated USB sound card you can use that!

Theory

drawing

Sparks of any kind produce electromagnetic disturbances and it is these disturbances made by lightning that we will be detecting. That is the reason we are stripping off the microphone from the headphone jack and keeping only the wire.  The wire will act as an antenna to pick up the signal.

Just to be clear, this is NOT related to the sound of the thunder by any means.

Test with Gas Lighter

Before we test the headphone jack with lightning, we needed to know how the headphone jack reacted to sparks and how a spark looks like when recorded with a headphone jack.

Since gas lighters are capable of producing sparks, we thought that it would be a great place to start. Here’s what we observed:

** Although we use a USB sound card in our videos, this works with an ordinary TRS/TRRS headphone jack as well.

Capturing lightning

Now that we have a good idea of what is going on with a gas lighter, we can predict a similar pattern with a lightning as well. Why ? Well, because lightning is the same phenomenon but, at a much bigger scale.

How do you do it ? First things first, to state the obvious one needs lightning. But besides that the setup is similar to the previous one except that unlike the gas lighter, we have to use the human body as an antenna by holding the wire coming from the mic pin of the headphone jack in our hand

Processing the recording

The audio file that we acquired has been uploaded to Google Drive (links below) but we strongly suggest that you try it out yourself to get a feel for this powerful technology that many people disregard as quotidian.

This is how the raw audio file might look (recorded with Audacity):
2

Now we amplify this signal on Audacity. (Effect –> Amplify)

3

4

Now you see these three prominent peaks, now these are for sure caused by the lightning. How are we so sure? Well, we were able to visually validate the data. What are those other peaks ? They are lightning too (!!!), but ones that are happening at a distance (probably many kilometers away).

Now in order to be completely sure, we repeated the same experiment another evening.. And here’s what we got:

Screenshot from 2017-05-18 10:05:53

This was a much more dramatic day with lots of lightning! ( as is evident from the numerous peaks )

How cool is that you can something as simple as a headphone jack to procure information about lightning that is probably happens kilometers away. This was absolutely ecstatic!

What does one peak look like ?

Here is a close up of one peak that was recorded:

AnpxY1

Sampling rate: 44100 Hz

Screenshot from 2017-05-24 12:43:23

Sampling rate: 384000 Hz

This resembles very closely to a Guassian Wave packet . ( In physics, a wave packet (or wave train) is a short “burst” or “envelope” of localized wave action that travels as a unit )

Wave_packet_(dispersion)

We believe that the electromagnetic disturbance that is detected during a lightning / spark is a Gaussian wave packet.  (If you believe otherwise let us know why by pinging us at 153armstrong@gmail.com or in the comments section)

 

Video Demo:

Will be uploaded soon! (subject to environmental weather conditions ;P)

If you found this post interesting, check out

Part- II-  Detect switching ON/OFF of Tube-light with a simple headphone jack

Part – III – Cigarette lighter spark detection using headphone jack

Part – IV –  The Headphone jack meets an actual spark gap!!!!!!

Thunder Audio file (44100 Hz): GoogleDrive link

Thunder Audio file (384000 Hz): GoogleDrive link

Don’t do this! – Headphone jack

Technically, one should not give more than 3V/3.3V (according to the Android Documentation) between the ground and the left/right/mic pin of the headphone jack. But there is this innate curiosity to know what would happen if one was crazy enough to do so.

We request you to not try this at home since doing this can damage your sound card! But nevertheless here is what would happen:

Testing basic headphone jack functions (Android)

In this post we will be trying to emulate basic functions as prescribed in the Android Documentation.  In order to understand the functions we first need to understand the circuit layout of the headphone jack which is as follows:

Screenshot from 2017-05-22 11:11:21

Now with this circuit in hand you can perform a series of tasks. This has been summarized in the table below.

Screenshot from 2017-05-22 11:03:00

This post will primarily focus on the Function A since that is the one that is commonplace in all mobile phones with a headphone jack. In the following video, we demonstrate how to emulate the following functions using a headphone jack

  • Play/Pause
  • Open Google Voice
  • Next song
  • Radio
  • Emulating Google voice

LiFi using Solar Panel and headphone jack

In this post we shall be exploring the usage of the solar panel and a headphone jack as a probable LiFi based module. We will be making use of the Arduino’s ToneMelody example to play tones on a LED. The LED will be shone on a Solar panel whose output will be relayed on to the computer with a 3.5mm headphone jack.

drawing

Video Demo:

Now, some people might be uncomfortable in using an Arduino. OK! Instead of using the Arduino one can use combine the mobile phone and headphone jack to generate the tone instead. The schematics of this is given below:

drawing-1

Video Demo: