Go Down

Topic: Read 3.5mm audio jack volume values with Arduino UNO. (Read 1 time) previous topic - next topic

Stoil

Hello,
Yesterday I started building a new project for reactive led lighting. I found this thread -> https://forum.arduino.cc/index.php?topic=476900.0
and this configuration http://i.imgur.com/Aop9U1r.png which is this schematic https://forum.arduino.cc/index.php?action=dlattach;topic=476900.0;attach=211774 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.

zwieblum

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

Stoil

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

zwieblum

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.

Stoil

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

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.

Stoil

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.

zwieblum

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

Stoil

This is the diode - https://components101.com/1n4007-diode
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 :(

zwieblum

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

Stoil

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!

MarkT

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!
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Grumpy_Mike

#12
Jun 04, 2019, 04:06 pm Last Edit: Jun 04, 2019, 04:13 pm by Grumpy_Mike
This is how you should wire an audio input to an Arduino:-


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.

DVDdoug

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 active peak detector (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 World's Simplest Lighting Effect.    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.)   

Stoil

@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!

Go Up