The ultimate guide to using LEDs with headphone jack

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 upcoming posts 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.

 

 

 

LED as light sensor !!?

Sometime ago there was a post on reddit which claimed that you can use your LED as a light sensor to detect the intensity of light. We decided to try it out and oh boy! it completely changed our perspective on the LED.

We just took a LED and performed an AnalogRead on the Arduino. Check this out:

Do not connect a speaker directly to a headphone jack (Speaker Impedance)

During the early days of exploring the headphone jack, we did some crazy stuff all in the name of science. And although many of them resulted in ecstatic moments of awe that we cherished, sometimes things went a little out of hand. But we learned important things from this experience.

In one of our previous posts, we showed you how we nearly fried our headphone jack ( appropriately titled Don’t do this! ). And in this post we will show you how to keep your USB port safe while playing around with speakers.

Speaker Impedance

accessories-1867368_1280

It is important to note that the speaker offers resistance to the flow of electrons. And when dealing with DC, we call it resistance but when one is dealing with AC it goes by the name of impedance.

And by virtue of Ohm’s law , we get that:

Lower the impedance → more current → greater load → increased power

Raise the impedance → less current → smaller load → decreased power

And as a general rule of thumb, small speakers (like the ones on your headphone) offer really high resistance to the flow of current and larger ones offer little to no resistance at all.

This caused us an Arduino because we accidentally connected ~4 Ohm speaker to the Arduino. And due to its low impedance, it became power greedy and destroyed it while also temporarily shutting down the USB port. So, yet another thing that one must be careful about.

How to be careful ?

Now that you know about speaker impedance and what it can do, we strongly suggest that you read the following article  to enlighten yourself:

Understanding Speaker Impedance

 

 

 

 

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.

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.

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.

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

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 from 2017-06-09 20:58:55

 

Link to code : GitHub

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

DIY: Obstacle detector with Audible feedback (IR sensor + Headphone jack + 555 timer)

We were inspired by the buzzer that you find in mobile and laptop showrooms – the ones that produce this annoying high frequency tone if you fiddle a ‘little too much’ with the displayed product.

schematic

We use a 555 timer in its Astable mode to produce the frequency tone and couple it with a digital IR sensor module. We do this by connecting the output pin and the ground parallel to R2 in the figure.

single-ir-sensor

And as a result when there are no objects in the vicinity, the system produces a high frequency tone, but when an object is introduced the sound dies out.  This is attributed to the change in resistance value.

Here is another variation of the same: