Go Down

Topic: Getting sound level from audio jack (Read 1 time) previous topic - next topic

Stabbler

Hi all,

I am currently in the process of making a hacked billy bass. I am using the following tutorial:
http://www.instructables.com/id/Animate-a-Billy-Bass-Mouth-With-Any-Audio-Source/

The part that is confusing is about getting the audio sound levels as an input.
In this tutorial the maker just hooks up the audio jack to the analog input port.

I have done some research. Instead of making it clearer, it got more confusing.
From this thread I understand you should not hook the audio jack directly to the anolog pin of the arduino.

Note that I am a complete newbie to electronics, instead of just following instructions I like to understand what I am doing.

In the thread the following schematic was posted:



I am unable to comprehend what that circuit does and how it functions.
Things I do not understand/basic electronic lessons needed:

  • What is the capacitor used for. A simple google search tells me a capacitor stores energy and then quickly discharges it.
    Wikipedia:
    Quote
    A capacitor (also called condenser, which is the older term) is an electronic device that stores electric energy. It is similar to a battery, but can be smaller, lightweight and a capacitor charges or discharges much quicker. Capacitors are used in many electronic devices today
    I don't see what the function of that could be in this schematic.
  • Why does the A0 pin has to be connected to the 5V pin? (with a resistor) It is some sort of voltage divider.
    When there is no input from the audio source. The voltage to A0 will be halved: So it will be 2.5V at rest.
    What happens when there is coming input from the audio source?
    How will that interact with the signal to A0?
    I assume when there is no incoming signal: Current on A0 will be 2.5v -> A0 input will read 512.
    I read that such a audio jack produces an AC Current. To measure how loud the sound is should I take the absolute value of 512 - [actual input from A0 pin]?
  • What voltage range does the audio input produces. I am planning to hook it up to my phone or laptop. Does this range differ per audio source or is it always within a specific range?
  • I will probably use the NodeMCU(esp8266) instead of Arduino. The key difference (I think) is that it uses 3.3V instead of 5v. Does this matter for the schematic. If I use the same voltage divider: The input at rest will become 1.15V right? So it is still half. So I can use the same schematic for this right?
    If it is not possible with a nodemcu I will purchase an Arduino


Please be gentle, as I am very new to this.

Thanks in advance!

vffgaston

#1
May 13, 2018, 11:19 am Last Edit: May 13, 2018, 11:24 am by vffgaston
Hi,

Well, it is not an easy circuit to fully understand it just by "wikying" ...

To help you we will need to know what your background is: basic electronics, programming, electrical circuits, ...

Regards

Stabbler

Hi Gaston,

Thank you for your reply. I am a software developer so my programming skills are ok.
I have always had an interest in the hardware side of things. I have played a bit with a raspberry pi, and recently purchased some Esp chips.

I have never really made complicated circuits.I have just plug some sensors/buttons in.
The only knowledge I have regarding electronics is from Highschool Physics class. Which is not much I am afraid.

The difference (how I perceive it, I could be wrong) between the 'sensor' I am trying to build now and the one I used is that the other sensors were 'powered' by the ESP/Raspberry pi. Thus the voltage is always between suitable ranges of the RaspberryPi/ESP. (Input of the sensor is also the max voltage out.)

Thanks for taking the time to reply.


MikeLittle

You have 2 INPUTs tied together. Where is the audio OUT?

DVDdoug

Quote
I am unable to comprehend what that circuit does and how it functions....


...Why does the A0 pin has to be connected to the 5V pin? (with a resistor) It is some sort of voltage divider.
When there is no input from the audio source. The voltage to A0 will be halved: So it will be 2.5V at rest.
What happens when there is coming input from the audio source?
How will that interact with the signal to A0?
I assume when there is no incoming signal: Current on A0 will be 2.5v -> A0 input will read 512.
I read that such a audio jack produces an AC Current. To measure how loud the sound is should I take the absolute value of 512 - [actual input from A0 pin]?
Right!!!

Audio signals are AC.   They swing positive & negative.   The Arduino can't read negative voltages.  In fact it can be damaged by negative voltages (or voltages greater than +5V) and/or the audio signal can be "damaged" (distorted).

With the voltage divider in place, the DC voltage is added to the audio signal.     With low level/quiet signals you'll get ADC readings that "swing' slightly above and below 512 and high/loud signals can read between 0 and 1023.    You can subtract the bias out of the reading in software if it helps in your application.

Quote
What is the capacitor used for.
A series  capacitor "blocks" DC, but allows AC through.   The capacitor along with the resistors form a high-pass filter.    Since DC is zero Hz, it gets blocked.   (If the capacitor value is too low, it will also block the bass, etc.)

Without the capacitor, the connected device could potentially mess-up the 2.5V bias and/or the DC bias could get-into the connected device and cause unknown/undefined problems.

Stabbler

You have 2 INPUTs tied together. Where is the audio OUT?
The audio output will come from an external source. Which will be used as an input for the arduino. The Arduino will not have an Audio Out. (The plan is to use a splitter to send the audio to a speaker.

Quote from: DVDdoug
With the voltage divider in place, the DC voltage is added to the audio signal.     With low level/quiet signals you'll get ADC readings that "swing' slightly above and below 512 and high/loud signals can read between 0 and 1023.    You can subtract the bias out of the reading in software if it helps in your application.
That is a neat trick. One thing that I am missing is that there is no protection for when the current from the audio source is to big. In theory when the volume is high enough it might still reach >5V?
Or will this value never be reached? (Because of guidelines for audio output devices perhaps?)


Quote from: DVDdoug
A series  capacitor "blocks" DC, but allows AC through.   The capacitor along with the resistors form a high-pass filter.    Since DC is zero Hz, it gets blocked.   (If the capacitor value is too low, it will also block the bass, etc.)

Without the capacitor, the connected device could potentially mess-up the 2.5V bias and/or the DC bias could get-into the connected device and cause unknown/undefined problems.
Thank you for the explanation, tomorrow after work I will look for more information about capacitors and their uses. (And try to understand the math and behaviours behind it.)


I came across another schematic as a possible solution for what I am trying to do. I will try to understand that schematic myself first (and then probably post it here to check if my understanding of it is correct).

Thank you very much! Your help is appreciated.

Thanks you!

Grumpy_Mike

Quote
In theory when the volume is high enough it might still reach >5V?
It is unlikely from an audio jack.

However that circuit will not help you find the audio sound levels as an input, it will allow you to read in the audio waveform.

You must learn that most Instructables electronics articles are crap, written by people who think they know more than they do. What you need to do this is a peak envelope detector circuit. Like this one:- https://en.wikipedia.org/wiki/Envelope_detector

MarkT

Though you can do the peak detection in software of course, if you are sampling the input
waveform.  Minor quibble - that circuit lacks any over-voltage protection - adding 10k between
the voltage divider and the analog pin will make it pretty-bomb-proof.  Make R1 100k, R2 10k,
C can be around 1uF - if its polarised the negative goes to the audio input jack.

Adding an opamp for hardware peak detection increases the hardware complexity, software
approach avoids that.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Grumpy_Mike

Quote
Minor quibble - that circuit lacks any over-voltage protection
But you are not likely to get over 5V peak from an audio jack. You also have the forward volts drop of the diode and the capacitor to absorb brief spikes.
A 10K series resistor will reduce the attack speed of the detector and make it a lot more sluggish in its response.

Stabbler

Hi guys,

Thanks for your input. As Grumpy Mike suggests, I should make an envelope detector.
I thought I would use the schematic posted here.

I am running into a question.
What kind of capacitor should I use? I see different kinds: Ceramic, aluminum, .....
Does it matter which one I buy? As long as I have the right value? 10uf?

Grumpy_Mike

#10
May 25, 2018, 04:01 pm Last Edit: May 25, 2018, 04:03 pm by Grumpy_Mike
Quote
I thought I would use the schematic posted here.
Bad idea, it is crap, no diode.

Quote
Does it matter which one I buy?
No.

Stabbler

So I searched a bit on the internet, all I need to do to adjust the schematic, is insert a diode before the resistor?

Grumpy_Mike


MarkT

But you are not likely to get over 5V peak from an audio jack. You also have the forward volts drop of the diode and the capacitor to absorb brief spikes.
A 10K series resistor will reduce the attack speed of the detector and make it a lot more sluggish in its response.
I'm thinking nylon carpets and static for the source of spikes really, and the 10k on the analog pin doesn't
affect the attack speed surely?
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Stabbler

Hi All,

Been a while as I did not have time to play with this project. Yesterday evening I fiddled a bit with the project.
I tried to make the envelope follower linked to by Grumpy Mike. Unfortunatly it did not seem to work.
(I have probably attached something wrong.)
I used a potentio meter for the Resistor, to dynamicly change it. Put a diode on it and a 2.2Uf capacitor, as well a 10uf capacitor.
I got no inputreadings on the A0 pin whatsoever.
I still don't understand how the schematic works. Where in the schematic should I measure the voltage (i.e. connect to A0). As I think I might have that wrong.

I did try the other schematic I posted (This one). I realise this schematic is bad, and it can damage the arduino. (So anyone reading this, don't try this..)
I was able to get the desired effect. (Although it is very jumpy.)
When inserting a diode to this schematic (between the potentiometer and the Capacitor) I can't detect a signal anymore.
(I am pretty sure I inserted the Diode the correct way(Such that the positive current can flow though it.)

Any ideas on what I am doing wrong?

My 'ideal' solution is to use the Envelope Follower provided by Grumpy Mike. Can it be that I used an incorrect Capacitor what value of Capacitor would you guys suggest? Also, does any diode work? On the packaging of the diode I am using it sais: 1N4001 

Go Up