Go Down

Topic: How to read data from audio jack? (Read 1 time) previous topic - next topic

kitce

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.



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.

Quote
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?

Quote
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?

jurs

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:


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.



kitce

#3
May 13, 2017, 01:56 pm Last Edit: May 13, 2017, 02:20 pm by kitce
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?
https://www.youtube.com/watch?v=YMJFigrKXpw

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.

kitce

#4
May 13, 2017, 02:15 pm Last Edit: May 13, 2017, 02:23 pm by kitce
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:


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:

Grumpy_Mike

#5
May 13, 2017, 03:53 pm Last Edit: May 13, 2017, 03:55 pm by Grumpy_Mike
Quote
but why would they do in this way
Because they are idiots and don't understand what they are doing.

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

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



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


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

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




jremington

#7
May 13, 2017, 06:03 pm Last Edit: May 13, 2017, 06:05 pm by jremington
Quote
Am I doing it right?
No, wrong on several counts. You are wasting both your time and everyone else's with Fritzing.

kitce

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?

DVDdoug

#9
May 13, 2017, 06:46 pm Last Edit: May 13, 2017, 06:47 pm by DVDdoug
Schematic attached (2 equal-value resistors and a capacitor).

Grumpy_Mike

#10
May 13, 2017, 08:05 pm Last Edit: May 13, 2017, 08:07 pm by Grumpy_Mike
Quote
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.

kitce

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.

Grumpy_Mike

Quote
How about this one?
Yes a lot better.

kitce


Grumpy_Mike


Go Up