1
\$\begingroup\$

Some days ago I have made a multiplexed 3x8 LED grid based on Arduino RGB Controller. In my case I don't use RGB but row1, row2 and row3. While I already made some nice animations but I'm not really happy with the result. The matrix is 1m x 2,8m, I'm planing to append it over some sort of "home music studio". As you know visualizing audio stuff is cool! So the static animations on that LED matrix would be useless if not following the beat. I need to add a spectrum analyer. Luckly all the analog I/O are free to use. Another point that makes this grid perfect for a 8 channel spectrum analyzer is the fact that I'm allowed to use PWM on the 3 rows. This means I have a theoretical spectrum grid of 256*3 x 8. Naturally the curve from 0-100% of the LED's brighness is not linear, that can be solved by using a simeple exponential function. Anyway the animation should be nicer than just fully turning on/off the LEDs.

First of all let me tell you again, I'm not an electronical enginer and I doing my best to understand stuff by myself, but in this case I'm not able to do it properly. My only measuring system is a very slow limited multimeter. I also broke an arduino some months ago, so I don't just connect stuff.

Can the arduino create a spectrum analyzer using only one pin?

yes! FHT

And so I started to read about that

  1. I need to somehow convert the audio signal to 0-5V
  2. I need to read the data on the ADC0 (left audio channel) and do some math and send it to the LEDs.

I'm stuck at point 1.

Every Audio device headphones output's max defer so I need a potentiometer. The audio voltage is low milliamps but also most of the time lower voltage.

From the various circuits I choosed the following one. Before I connected it to the arduino I used a buzzer to test if I get something out. Yes but, I get sound if I invert GND with signal(Jack in) and I also get sound if I invert the polarity of the capacitor C1. There is also no type of protection in this circuit, I am stucked.

Note.: I also tested differnt other circuits and got alwasy the same results, except in this the potentiometer has no effect.

enter image description here

Result:

With a simple analog read I always get 0(ZERO).

schematic

simulate this circuit – Schematic created using CircuitLab

Reading more about the problem I found many posts that use op-amps. Since my local electronics component store has only a limited number of IC's, I sometimes buy random IC's if they are compatible with Arduino and other microcontrollers. And I also salvage old stuff. Here is a list of components I could use.

  1. MC1458 DUAL General-purpose operational amplifier
  2. TDA2822M DUAL low-voltage power amplifier
  3. UA741CN General-purpose single operational amplifier
  4. AD7395 Dual, Serial-Input 12-/10-Bit DAC

As I have no oscilloscope and other professional stuff to measure electronic current, I hope you can show me how to properly connect an audio signal to my microcontroller's ADC.

Consider the fact that I know nothing. Complex explaination without a schematic wouldn't help to solve the problem for me and probably many other people.

The question:

How to PROPERLY connect a standard headphone jack (mp3 player)/ audio out cable to a 0-5V Analog to digical converter Microcontroller's pin?

Main problems:

  1. With the tested online available circuits I get no readings from analog pin 0. Analog pin 0 works perfectly (tested potentiometer only).
  2. Now, I don't want to connect something to the MC's pins without knowing for sure that I output 0-5V at the correct amperage.

Extra:

  1. I don't know why I always get reading 0 from Arduino even if I can hear the buzzer?
  2. I never used a op-amp so I don't know what inverting input and non-inverting input is?
  3. What does the C1 capacitor and why does it work if I invert the polarity?(buzzer)
  4. Inverted audio cable pins also produce the same sound on a buzzer, why?
  5. I'm testing on an Arduino micro but the final line in would be used on a Arduino micro, not sure if relevant.

EDIT 1

This uses the same op-amp I have

Noise can be horrible !

https://bochovj.wordpress.com/2013/06/23/sound-analysis-in-arduino/ https://bochovj.files.wordpress.com/2013/06/circuitschematics.png

EDIT 2

Arduino Prescaler: up to 19kHz, not 17 what I have written in the comments.

http://apcmag.com/arduino-project-audio-spectrum-analyser.htm/

But by knocking down the 128-prescaler to 32, we now increase the sample rate by the same factor up to 38.4kHz. Thanks to Nyquist again, that gives us an audio bandwidth of 19.2kHz, which is close enough to 20kHz-perfection.

EDIT 3

schematic

simulate this circuit

\$\endgroup\$
12
  • \$\begingroup\$ Are you aware of MSGEQ7? Would that be useful? \$\endgroup\$ Commented Aug 14, 2015 at 9:22
  • \$\begingroup\$ I think it would not work with my setup... the led grid already uses almost all pins. the msgeq7 needs more pins.. then i would need an external multiplexer ic... with FHT i only need one pin and have an array ready to use softwareside.. that allows me to display everything how i want.Also like i said my local electro supply is very limited... i think they don't have an msgeq7.... \$\endgroup\$
    – cocco
    Commented Aug 14, 2015 at 9:25
  • \$\begingroup\$ Also at the end the FHT way is more precise than the MSGEQ7 as it allows up to 256 bands vs 7. All in one pin. \$\endgroup\$
    – cocco
    Commented Aug 14, 2015 at 9:38
  • \$\begingroup\$ So, have you calculated how fast you need to sample your ADC to resolve all of the frequencies you want? What is the clock speed and the minimum ADC settling time? Does all of this support your requirements? \$\endgroup\$ Commented Aug 14, 2015 at 10:28
  • \$\begingroup\$ i read that the examples sample at 38khz and that would be up to 17khz in 256 bands. if it's that what you mean...but until i don't get a proper analogRead i can't go on. \$\endgroup\$
    – cocco
    Commented Aug 14, 2015 at 10:32

1 Answer 1

3
\$\begingroup\$

This should do what you are asking - it takes the audio in (AC-coupled) and amplifies it (inverted, but that won't matter) with a variable gain of up to about 5.5 (use R1 to adjust gain). It also centre-biases the signal around 2.5V (analogRead = 512 on the Arduino).

schematic

simulate this circuit – Schematic created using CircuitLab

However, please do pay attention to the other comments on here regarding sampling rates and the amount of processing needed to be done to get the result you want. Also, don't swap out the opamp without some thought - that part is rail-to-rail input and output rated, which you will need in order to use the full input range of the Arduino's ADC.

\$\endgroup\$
19
  • \$\begingroup\$ My supply for shure does not have that opa344 ... can i do the same with the ic's i listed?UA741CN,MC1458?? \$\endgroup\$
    – cocco
    Commented Aug 14, 2015 at 12:33
  • \$\begingroup\$ Nope - you need an opamp with an output that can swing very near its voltage rails - known as a rail-to-rail output opamp (RRO or sometimes R/RO). None of the opamps you list is suitable. But the one I have suggested is available from CPC, Farnell, Mouser, Digikey, RS, is low cost and comes in a DIP package for easy prototyping. \$\endgroup\$
    – stefandz
    Commented Aug 14, 2015 at 12:41
  • \$\begingroup\$ And those resistor capacitor mix solution (where i posted the schematics)... why does that not work on my arduino micro? \$\endgroup\$
    – cocco
    Commented Aug 14, 2015 at 12:44
  • \$\begingroup\$ The one schematic you have inline should have partially worked, although not with a full 0 to 5V swing as there is no gain (and in fact there is attenuation, which doesn't help). You should have read 512 (or thereabouts) pretty much all the time, with small variations up and down. You would have needed to make sure that the audio ground input was connected to the Arduino ground though - this is not very clear in your schematic. \$\endgroup\$
    – stefandz
    Commented Aug 14, 2015 at 12:52
  • \$\begingroup\$ i could not find a proper audio jack in,... anyway there is a line that starts from one of the audio inputs(-), passes trough some caps and resistors and goes into the arduino ground(GND). \$\endgroup\$
    – cocco
    Commented Aug 14, 2015 at 12:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.