How to read data from audio jack?

I am planning make a sound reactive LED controller with Arduino Nano which reads audio signal from any audio jack (probably 3.5mm), e.g. computer line-out, music players. The louder the music, the brighter the LEDs.

I had tried to use a microphone module to read the sound level before, but the result was not what I expected. The performance is unstable since it depends on the distance between the microphone and the speakers.

Therefore, I think reading the audio signal directly from the audio jack could result in better performance.

The questions are:

  • Can I read the sound level directly from the audio jack with Arduino?
  • How should I connect the electrical components?
  • Do I need any resistor or capacitor? Why?

I am using a USB DAC which has two audio outputs, one is pure DAC output and the other one is amplified. The amplified output is currently connected to my speakers (or headphone/ear monitors), so I would like to read the audio signal from the pure DAC output.

Sorry if there is any stupid question, I have never studied electrical engineering, I only know how to do programming.

1 Like

This is the place to start:- http://interface.khm.de/index.php/labor/experimente/arduino-realtime-audio-processing/

Read that and get the idea of what you are doing. You need two resistors and a capacitor like the input side shows.

I am using a USB DAC which has two audio outputs, one is pure DAC output and the other one is amplified.

Never come across an USB DAC have you got a link? What has the Arduino got to do with this?

Can I read the sound level directly from the audio jack with Arduino?

Yes but for the largest dynamic range you need to have a signal that is +/- 2.5V.

Do you actually want the sound signal or just the envelope?

kitce:
The questions are:

  • Can I read the sound level directly from the audio jack with Arduino?
  • How should I connect the electrical components?
  • Do I need any resistor or capacitor? Why?

No, not directly, you need two resistors for coupling the audio signal into Arduinos analog input, i.e. A0.

I've searched acircuit schematics for you
This circuit can be used for coupling the audio output from your smarthone or "line out" from your PC into Ar duino:
4be69acdcaf8ebdcecd3a3ce8e51a12c63f5327b.gif

You can leave out resistor R1 and capacitor C, but you need those two 100K resistors R2 as voltage divider.

Value of R2=100K is not critical.
You can use R2=68K or R2=82K as well.

But don't use this circuit with coupling of output from power amplifiers, which could provide dozens of volt output power.

This is circuit is suitable for PC "line out" audio level or for audio output from your smartphone only, not for output from power amplifiers.

Grumpy_Mike:
This is the place to start:- http://interface.khm.de/index.php/labor/experimente/arduino-realtime-audio-processing/

Read that and get the idea of what you are doing. You need two resistors and a capacitor like the input side shows.
Never come across an USB DAC have you got a link? What has the Arduino got to do with this?
Yes but for the largest dynamic range you need to have a signal that is +/- 2.5V.

Do you actually want the sound signal or just the envelope?

I found some YouTube videos doing the similar things (e.g. VU meter with blinking LEDs) without resistors and capacitors, they just connect the "Tip" of the audio jack directly into an analog pin on Arduino. AFAIK, the signal from the audio jack is AC, which may be out of the range 0-5v, but why would they do in this way and succeed?

Are the resistors and capacitor used to make the audio signal into the range 0-5v? I expect to read the analog value as 0-1023 (loudness) (maybe only L/R channel first, or both L and R channels to take an average), then map into 0-255 (brightness)

Actually the Arduino has nothing to do with the DAC directly. Instead, the Arduino should deal with audio jack. I am just listing the devices be involved in this project. You can consider the DAC as just a normal audio signal, like a 3.5mm audio jack of a MP3 player or PC line-out.

I would like to read the level of the sound signal first to control the brightness of the LEDs for PoC (proof of concept), probably read the frequency in the future to detect the beat/bass of the music as well.

jurs:
No, not directly, you need two resistors for coupling the audio signal into Arduinos analog input, i.e. A0.

I've searched acircuit schematics for you
This circuit can be used for coupling the audio output from your smarthone or "line out" from your PC into Ar duino:
4be69acdcaf8ebdcecd3a3ce8e51a12c63f5327b.gif

You can leave out resistor R1 and capacitor C, but you need those two 100K resistors R2 as voltage divider.

Value of R2=100K is not critical.
You can use R2=68K or R2=82K as well.

But don't use this circuit with coupling of output from power amplifiers, which could provide dozens of volt output power.

This is circuit is suitable for PC "line out" audio level or for audio output from your smartphone only, not for output from power amplifiers.

Thank you for the circuit. I think it is the simplest one I have seen in these few days.

But I found some circuits suggest using 0.47uF capacitor, what are the differences?

One stupid request, I am not very good at reading circuit diagrams, I would be appreciate if you could make me a simulation picture with the Arduino, breadboard and other electrical components, like this:

but why would they do in this way

Because they are idiots and don't understand what they are doing.

and succeed?

They don't. This damages the Arduino input pin, it will fail after a time. It is also only half the Audio signal so is not much good for audio.

Are the resistors and capacitor used to make the audio signal into the range 0-5v?

No. The resistors bias the signal to the 2.5V mid point and the capacitor AC couples the signal so the resistors do not affect the DC component of the audio input.

I expect to read the analog value as 0-1023 (loudness)

No that is not what you will see. You see a reading of 512 for silence, the the louder it gets the further away the reading is, above and below, from this point. If you actually want readings like that then what you actually need is this circuit. It is called an envelope follower, use a capacitor to couple this circuit to your audio input.

Thank you for the circuit. I think it is the simplest one I have seen in these few days.

Hugh! It is the same circuit I pointed you at in reply #1.

But I found some circuits suggest using 0.47uF capacitor, what are the differences?

Slightly lower frequency response on the high pass filter this implements.

I am not very good at reading circuit diagrams, I would be appreciate if you could make me a simulation picture with the Arduino, breadboard and other electrical components,

No. That sort of layout diagram is an anathema to those here. If you want one make it yourself. Click on the schematic tab in Fritzing, copy the schematic, then click on the layout tab and drag your components round until everything is routed. That way you will actually learn something.

Grumpy_Mike:

Am I doing it right?

Am I doing it right?

No, wrong on several counts. You are wasting both your time and everyone else's with Fritzing.

jremington:
No, and you are wasting both your time and ours with Fritzing.

Sorry, I am new in building circuit.
Can you tell which parts are wrong?

1 Like

Schematic attached (2 equal-value resistors and a capacitor).

Audio Input Schematic.png

2 Likes

Am I doing it right?

No.
You have no diode.
The resistor is connected to both sides of the capacitor.

@doug - he is trying to implement the envelope follower circuit. That will do for just the volume indication he wants.

1 Like

Grumpy_Mike:
No.
You have no diode.
The resistor is connected to both sides of the capacitor.

@doug - he is trying to implement the envelope follower circuit. That will do for just the volume indication he wants.

How about this one?

I changed to Arduino Nano and added a power supply, but I think it doesn't matter.

How about this one?

Yes a lot better.

Grumpy_Mike:
Yes a lot better.

But still something wrong?

No, looks good to me.

Grumpy_Mike:
No, looks good to me.

Great.

So with this circuit, I could get the value from 0-1023 for the loudness of the right channel from the audio jack?

Also, I am wondering do I really need to connect the ground of the audio jack?

If I need the left channel in the future, is it okay to just do the same circuit as the right channel and input to another analog pin?

So with this circuit, I could get the value from 0-1023 for the loudness of the right channel from the audio jack?

Yes, providing there is no DC component to the output from the amplifier. If there is you need a seriese capacitor between the diode and the jack.

Yes you do need to connect the ground of a jack, any voltage is measured as a difference between two points, without the ground connection you don't have two points.

Yes another circuit will work just the same.

Grumpy_Mike:
Yes, providing there is no DC component to the output from the amplifier. If there is you need a seriese capacitor between the diode and the jack.

Yes you do need to connect the ground of a jack, any voltage is measured as a difference between two points, without the ground connection you don't have two points.

Yes another circuit will work just the same.

Do you mean the audio jack of the USB DAC? I am not sure about what is DC component.
The audio jack is available for any earphones/headphones/speakers with 3.5mm audio connector, I think its signal is same as those of the smartphones/media players .

Do you mean the audio jack of the USB DAC?

Please supply a link to this.

I am not sure about what is DC component.

Grumpy_Mike:
Please supply a link to this.
https://forum.allaboutcircuits.com/threads/what-is-the-dc-component.7210/

Here you are:
http://www.ebay.com/itm/BlueBird-DAC3-0-CS4398-CS8416-SA9023-USB-DAC-Decorder-headphone-amplifier-/112053201337?_ul=GT

Output:
3.5jack headphone output on back panel, directly drived by decoder chip modul
6.5jack headphone output on front panel, drived by headphone amplification extend card
analog output

I will be reading the signal from the 3.5mm jack.