Read 3.5mm audio jack volume values with Arduino UNO.

Hello,
Yesterday I started building a new project for reactive led lighting. I found this thread -> How to read data from audio jack? - Audio - Arduino Forum
and this configuration http://i.imgur.com/Aop9U1r.png which is this schematic How to read data from audio jack? - Audio - Arduino Forum if I'm not mistaken.
I use this female 3.5mm part - http://www.powerstroke.org/forum/attachments/6-0l-electronics-discussion/242274d1392268638-wiring-aux-3-5mm-headphone-jack-diagram1sm0.jpg and connecting the GND to 1 and 5 for the audio.
Arduino keeps reading 0s. If I put my multimeter (set at 20v DC) across the diode, I get 0.00-0.02 (very rarely more than 0.00). If I put the multimeter across pin 1 and pin 5 of the female socket, I get ~-2.50 - 0.02. What's wrong here ? I tried removing some parts 1 by 1 like the capacitor and then the 100k OHM resistor and saw some values but they seemed totally random.
Any ideas ?
Cheers!

edit: I was using my Xiaomi phone with the volume set at maximum if that matters.

Reverse the jack's polarity. You should read +2.5, not -2.5.

How would I do that ? Are you sure ? I thought the signal was supposed to vary between -2.5 and 2.5 ?

Depends on your audio source. You write "-2.50 - 0.02", that means it's not an AC, but a DC signal, and it' facing down. So just flip wires, what you used as gnd on the input should be signal, what was signal sould be gnd, and then try again.

Ok then, that makes sense, but isn't the signal supposed to vary from -2.5 to +2.5 ? If so, it stops making sense for me at least.
edit: audio source is Xiaomi smartphone

well, the audiosignal should be decoupled with a capacitor, so you get rid of the dc part. Usually the signal is +-1.2V. It pros and cons, if the capacitor is missing.

I do have a capacitor (22 microfarads, 25v), however it is positioned right after the diode. The measurements I took were across the 3.5mm jack and across the diode that follows the input from the jack. The thing that makes no sense to me is that the jack provides -2.5 to 0 instead of -2.5 to +2.5. If that was the case, it would actually pass thru the diode. Now across the diode the voltage is almost constantly 0 which means nothing passes thru it ?
I don't understand.

please make a schematic which shows where you mesure what. And please post a datsheet of your diode.

This is the diode - 1N4007 Diode: Pinout, Equivalents, Description & Datasheet
I am not sure how to mark a schematic. I measure ground at the jack and input right after the diode. This shows almost constant 0.00
The other measurement is jack ground and jack input before diode which results in -2.5 to 0.
I hope you understand, otherwise I'll resort to paint :frowning:

I suppose, you did use the multimeter GND cable on GND, didn't you? :wink: Ok, just flip grond and signal on the input and try again.

Thanks for being patient with me man, I'm not good at electronics, I thought a programming background would be enough but I almost always hit a wall when it comes to this. I'll try as soon as I get back from work and I'll update you on the result. Cheers!

zwieblum:
well, the audiosignal should be decoupled with a capacitor, so you get rid of the dc part. Usually the signal is +-1.2V. It pros and cons, if the capacitor is missing.

Coupling cap, not decoupling cap, and in this situation its also termed a DC-blocking cap.

Decoupling is used to prevent a signal being transferred, coupling is when the signal is intended to be transferred. Supply decoupling is used to prevent signals following unintended feedback paths via the power supply rails, hence "decoupling".

Logic decoupling is rather different in intention, to be more confusing!

This is how you should wire an audio input to an Arduino:-
Audio Bias.jpg

With no audio you will read 2.5V or an A/D reading of about 512. As the Audio increases you will get the readings higher and lower than this. The louder is the signal the further away from this center point the reading will be.

If you just want a signal that follows the envelope of the waveform, that is just the changes in loudness then do not use the above circuit but use this one.

Changing the 100K resistor will change the speed the signal drops when it goes quite, and changing the value of the capacitor will change speed it responds to an increase in signal. The reading you get from an analogue read will start at 0 for no signal to 1023 for maximum volume.

Audio Bias.jpg

You'll get a negative voltage if the diode is backwards. With a negative voltage the Arduino will read zero and it can actually be damaged by negative voltages.

Also, you get a 0.5 to 0.7V voltage drop across the diode. You should read something at maximum volume but you won't read anything at low volumes, and you'll get non-linear readings (if that's important).

I use an [u]active peak detector[/u] (envelope follower) which does not have the voltage drop.

Most people use the bias circuit (simple and no diode).

An envelope follower (passive or active) only gives you volume information. If you want frequency information you can't use it.

The advantage to an envelope follower is you can read the varying DC voltage from a peak detector at about 10 times per second. That makes your software simpler and frees-up processor-time for doing lighting effects rather than "analyzing' the audio. If you are reading the audio waveform (with the bias circuit) you need to read thousands of times per second.

P.S.
You might want to look at my [u]World's Simplest Lighting Effect[/u]. It uses the "easy" bias circuit. It's also got some optional (commented-out) serialPrint diagnostic messages. (In the "real world" my similar effect uses the active peak detector and different software.)

@zwieblum - Thank you friend, that seemed to work. I now get 0-2.5v right after the diode.
@grumpymike - Mine is the second schematic, I saw you suggest it in an old thread. I am not familiar with audio or electronics in general, but what you said about the enveloper follower - does that mean I won't really be reacting to a bass but just to a volume spike ? If so, then would the first schematic be able to help me "detect" bass ? Another question - by using capacitors and resistors with this formula - https://scontent-sof1-1.xx.fbcdn.net/v/t1.15752-9/62154244_2334263120171531_3551502426928316416_n.png?_nc_cat=106&_nc_ht=scontent-sof1-1.xx&oh=d5620a4a38f57cbbd2cce9b6695c24f7&oe=5D9A69A0

am I not filtering frequencies ? Let's say my configuration filters out the higher frequencies, does that mean that the analog values I receive are for the low frequencies (bass)?
@dvddoug - Thanks for the links man, they seem really concise. I'll try one of your circuits if the one I got now does not satisfy my needs.
Cheers!

Well, you have a lowass filter that lets pass all frequencies lower then 7 Hz. Higher frequencies are smoothed out and you see only the envelop. Please read some texts on lowpass and highpass filters, that will answer a lot of questions :slight_smile:

7Hz! That's what the formula indicates but how is that applicable ? I mean, isn't the signal something like 20-20kHz ? What good does 7Hz do me ? :o Now I got very confused :smiley:

Yes, but it's the envelope you get for frequencies > 7 Hz

by using capacitors and resistors with this formula

That is just the formula for capacitive reactance.

Basically an envelope follower is a filter because you are removing high frequencies, the audio signal, just leaving the peak amplitude. Make that capacitor bigger and you are lowering the frequency of the filter again. It is only a first order filter, if you want sharper cutoff then use a higher order filter like a fourth or sixth order one at the frequency of beat you want to trigger off.

Hello friends,
Just came home and tried it out. There's just 2.1V after the diode, however Arduino is reading crap. On top if it, it stopped displaying what it reads on the Serial, weird. No matter how loud is the volume or if a song is playing or not, the values received are the same.
What is going on here