What I mean by unstable is that the output wouldn't be consistent at all, if there are objects blocking the sound, if there are other sounds in the area, if the sound I want is too far, etc, the microphone would catch them differently each time and I want it to be consistent, to plug a device into the arduino and read the data from within the code.
Human hearing is the result of heavy processing in the brain, with inputs from two ears, and has a very distant relationship to actual sound waves.
Computer programs need to be reasonably sophisticated to make proper interpretation of microphone signals, and that has nothing to do with "microphone instability".
It is quite a difficult task to recognize certain sounds, even things you think of as simple, like a whistle. The important thing is to have fun while you are learning this.
data which could be used to calculate a color for the dominant freq/pitch/volume?
You say you want to "get the sound directly" but don't identify the source of the sound (e.g. an audio headphone jack). If the signal is available in electrical form one would need to know the parameters of the electrical signal to advise you on how to condition it for the Arduino analog input, but you haven't provided a clue as to what that might be.
I do not want to use a microphone, if I can connect an aux cord to a speaker and hear music from it, it sounds logical to me that I can connect some cord into a controller, read the data and use it however I want to, the only thing being I do not know how to make it work exactly on an arduino uno and which type of cord I would need or any other special electronic parts.
I know about FFT I just don't know what type of data I would get from the cord I would use to convert to the appropriate data.
The electrical signal is an analog of the sound / air pressure change signal.
You need to bias the analog input of the Arduino to half the Arduino rails with a pull up and pull down resistor of say 100K, and connect it through a 1uF or so to the Aux output. Connect the ground of the Aux output to the ground of the Arduino.
Yes, amplitude is one characteristic of audio, but the solution for taking an electrical signal from a cellphone audio jack is probably different than tapping across the speaker stack for a death metal band playing a stadium concert.
The question simply is, "what device do you plan to take the sound signal from?"
Since the Arduino can't read the negative half of the AC audio waveform (it can actually be damaged by negative voltages, or voltages greater than +5V) you need a bias circuit:
That's all you need for line-level or headphone-level signals. With lower-level signals you'll need amplification and with "high power" speaker signals you'll need a voltage divider and/or over-voltage protection.
With the bias circuit, silence will read about 512 (on a "standard" Arduino with a 10-bit ADC). You can subtract-out the bias in software or with FFT you can simply ignore the zero-Hz bin.
If you can live with 7 pre-selected frequency bands, the MSGEQ7 chip works without FFT/FHT and you won't need the bias circuit. (The MSGEQ7 is mis-named... It's a spectrum analyzer chip, not an equalizer chip.)
Typically a smartphone audio output will be limited to something on the order of 1 V peak to peak so the circuit in post #11 is safe, though it wouldn't be a bad idea to add an input limiter, that is a series resistor of ~100 Ohms between the capacitor and input pin and reverse biased Schottky diodes at the input pin, one to power and one to ground to limit the analog input pin from over voltage peaks.
Since the input range of an Uno is 0-5 Volts the ADC values will span only a portion of that range. For a light show project that may be "good enough", but adding an on amplifier with an appropriate voltage gain (about 4x) would give higher resolution.
If you had a sound source that drove unpowered speakers, the voltage swing would be much larger, hence why it's important to know the characteristics of the source to determine what needs to be done to condition the signal for the Arduino end.
Thanks for the info, since I’m new to electronics and only know basic electricity I’d like to make sure I understood correctly:
The circuit in post #11 the kind user posted is supposed to make all negative voltages positive, to not damage the arduino so they would only range from 0-1 volts (if a phone ranges from -1 to 1)
Then an input limiter is supposed to limit the voltages to be only 0-5 so it won’t damage the arduino.
About the amplifier - if a phone can output only -1 to -1 volts and I’d use an amplifier let’s say as you said 4x would the volts range from -4 to 4 volts? And would it even work? since these volts are not actual volts the audio itself is outputting (if I understood correctly)
And how would one create an amplifier?
And how would I use these volts? What would they represent? Let’s say I read them from within the code, what type of data would I be able to extract from these volts?
Sorry if any of the questions are stupid as I said I only know basic electricity (basic formulas, circuits etc)
No it adds a DC bias to the signal so that it lifts the ground point from 0V to half way up the rail. This diagram in Post #11 is what I described in words in post #9. Maybe you were not paying attention?
No, the voltage would range from 2.5V ( half the rail ) + 1V which is 3.5V to 2.5V - 1V which is 1.5V.
Optional, but it unlikely you will get a peak to peak audio signal greater than 5V without an amplifier.
You did not understand correctly. These volts ARE the actual volts of the audio. However, unless you have a negative voltage rail handy then you would not apply an amplifier to the signal until it has been passed through the bias circuit so the amplifier would work off the same voltage rail as the Arduino. In that way you would automatically limit the audio signal from going outside the limits of the voltage the Arduino can stand.
You would feed these volts into an analogue input of the Arduino and read them using the analogRead() function call. The reading will get will be a number between 0 and 1023. With no audio signal the number would be half of this range, approximately 512. Any audio signal would be a deviation from this value either up or down from it. Above this base value represents a positive audio signal, below it a negative audio signal.
If you want to play with digital audio then download Audacity, it will let you look at waveforms, do stuff with it like filtering, and here the results.
A sequence of them would allow you to apply an FFT and get frequency information from them. You could then light up different LEDs when different frequencies were present. You must read and store these voltage readings as quickly as possible and there are tricks where you can speed up the reading of the Arduino's A/D, (analogue to digital) converter. You need to take at least two samples (readings) for the highest frequency you can get from the FFT.
If you like you could buy my book on the topic Arduino audio and audio projects
but it covers way more than you are asking about, but there is a project that shows a spectrum from an inputted audio signal.
Oh so I understood incorrectly, I thought the bias circuit was just getting rid of the negative volts, and someone said that if I'm using a phone the peak is 1 volt so I assumed the range in general is -1 to 1 volts, so instead what it does if I understood what you said is basically lift the 0 volt to be 2.5v in order for negative volts to appear as positive if I understood correctly now? like now the minimum voltage which would not damage the arduino would be -2.5v and it would appear as 0v because of bias circuit, and if there would be anything lower than -2.5v in negative volts it would damage the arduino?
If I do use an amplifier, because if I understood correctly it should give me more data range to work with, I should use a limiter right?
What I mean by "these volts are not actual volts the audio itself is outputting" is the volts coming from the amplifier, I meant they are not the original voltages the phone is outputting but they are amplified so give a more variety of data (?).
Now I understand this paragraph because I read it earlier and was confused because I didn't understand entirely what the bias circuit does.
So basically I'd first need to connect the audio (or phone in this case) to the bias circuit to "get rid" of the negative voltages then pass it through the amplifier if I want more data (?) then through a limiter to not damage the arduino then finally running code on it?
And how would I connect a phone to the arduino and read the audio from it? can I simply take an AUX cord? or is there a special part I need for it?
Thanks in advance, and thanks for the elaboration on everything!
There are several ways of specifying an AC voltage, you are confused over the two.
Peak voltage is measured from the peak to the zero point in the wave. Where as peak to peak voltage is measured between the positive and negative peaks.
So a 1V peak voltage is exactly the same as saying a 2V peak to peak voltage. They both different ways af describing exactly the same voltage waveform.
Potentially yes. In actual fact it would have to be greater than -0.7V and then the static protection diodes in the chip kick in. These can be damaged if they take too much current but they should be OK for a mV or so. You can limit this current by a simple series resistor of say 1K.
Correct.
No because no amplifier can generate more output than the voltage that is driving it. So if you were to use an operational amplifier between the input bias resistors and the analogue input of the Arduino this would automatically limit you to the voltage powering that operational amplifier.
That doesn't matter they are still represent the audio signal.
No not variety range. The peak numbers will be higher / lower than they would be without the amplifier.
Correct
No the amplifier does that for you. Without an amplifier then the more cautious would add a series resistor, but your problem would be not enough voltage rather than too much.
Yes. You will need a matching jack socket at the Arduino end to plug it into.