Using Arduino Nano, I'm trying to sample analog input from a Stereo Jack terminal and use those samples to play with LEDs. I bought The Stereo Jack here:
I'm new to circuitry, I made the circuit based on my limited knowledge, from the internet, youtube videos, and some discussions on this site, so I expect some mistakes there.
Let's ignore the Right channel of input for now. For the Left channel, a small signal diode is used, and I connected it to the 5V line and the ground separately using 2 100K resistors, and finally, it goes to the Analog 0 pin of Arduino.
The problem is, I expect to get a value of 512 as total silence, and anything above or below that as a signal (or frequency? whatever). But instead, I got random values between 100 to 300, and it doesn't change whether a music is playing or not, or whether I turned the volume up and down.
The input circuitry is all wrong. To get a reading like that you have to connect a 100K pull-up and pull down resistor to the analogue input. Then connect the Audio signal through a 1uF capacitor to the analogue input. Remove the diodes those are just silly.
You also need to connect the ground of the audio to the ground of the Arduino. Why is there no jack socked on your schematic?
The maximum frequency you can detect on each of the two channels will be 8KHz and that is only if you boost the A/D sample rate to 32KHz by changing the A/D clock prescaller value.
After I succeed in wiring the LEDs and feeding them with dummy data and got a satisfying result in one try, I thought it will not that hard with these audio things . Thank you for telling me that it's on another level .
So the key is the pull-up and pull-down resistor, right? You guessed it right, I don't know about them at all. I'll be back in a few days with an updated circuit after some reads.
I'm using an online tool on circuit-diagram.org to create the circuit. It's open source but sadly has limited components, and there is no jack socket.
That sounds about right. You may already guess it, what I'm trying to do is visualize any music/sound coming out from the computer with the LEDs. Some friends recommended me to use a microphone, but I'm planning to fit the whole circuit inside my PC case (it's big enough), so I don't think I can use it.
With a few RC networks, you may do all the processing the analog way. You would then only need to sample some analog inputs a few times per second.
But this will involve some soldering...
There is a fundamental question here which is: what do you mean by "play with LEDs"? You could for example just change the brightness of a LED according to the amplitude ("loudness") of an audio input; or according to its bass content; or something else.
If you just want "loudness" then you don't need to sample very quickly, i.e. above the "Nyquist rate" which is twice the maximum frequency of the signal. You could sample quite slowly say at 1 kHz over say a 50ms "block" and look at the variability of the 50 samples (i.e. max/min) over that block. Or you could do some analogue pre-processing to "envelope detect" the signal which will just estimate its amplitude, using a diode and smoothing capacitor and a few resistors, and sample that signal every 50ms. Then repeat.
If you want to do something more complicated like look at the frequency content (e.g. bass loudness) then some filtering is needed. This could be done digitally but you then need to sample much quicker, i.e. at the Nyquist rate or above, and the processing gets much harder, probably beyond the capability of a Nano though not an Arduino using a faster ARM core. OR, you could do some analogue filtering to separate out say the bass and treble content, envelope detect those, and sample the resulting signals slowly.
So before thinking about the analogue input circuit, decide what processing you want to do, or enable. to achieve your end result.
I would suggest getting one of these MSGEQ7 boards. This will handle the audio signal correctly and give the Nano the sound's volume on 7 different frequency bands for each of the left & right channels. This will be far simpler than attempting to get the Nano to analyse the audio signal, which it doesn't really have the computing power to do well.
That's one cool chip! Analogue of course. So I guess you just need to connect the multiplexed output to an analogue input and strobe appropriately. Not so much fun though!
What does "not much fun" mean? The software is child's-play compared to FFT. And the chip takes care of the bias issue. (You don't have to write the FFT library yourself but using it is not easer than using the MSGEQ7.)
But we don't know of the OP wants or needs frequency analysis, or if so if 7-bands is enough.
Your circuit already has the pull up and pull down resistors on the left channel, you just need to replace that diode with a capacitor for you to get a signal on A0.