Creating a Spectrum Analyzer using an Arduino and a Non-Inverting Operational Amplifier

preview_player
Показать описание
This is a summary of everything I learned trying to create a Non-Inverting Operational Amplifier circuit in order to feed an audio signal from a soundbar to an Arduino microcontroller so I could drive LED lights based off of the music playing.

Hope this is helpful and that I didn't make an egregious errors in the video lol.

Once I have the project setup inside my van I'll upload the source code I used.
Рекомендации по теме
Комментарии
Автор

Ive watched several videos on this subject. What stands out from all the other videos is the fact you cover way more theory, if I had found this video in the beginning of my venture I wouldn’t know all the things you didn’t cover here. Thanks for all your time and energy. It helped more then you could know.

jjqformerlyjailbreak
Автор

Auto Gain control in preamps like this is traditionally done using a JFET and a peak detector circuit. The JFET serves as a voltage-controlled "potentiometer".

deniss
Автор

you don't need 2 power supplies, for negative voltage make Virtual Ground with a voltage divider with 2 resistors and 2 caps of same value

redwoodimage
Автор

Fantastic video. Your detailed explanations were very helpful for my novice level understanding of op amps. This is a project I might try to build.

RodHartzell
Автор

Impressive. Great narration and video effects. I learned very much today. Keep up the great work.

denniswilbanks
Автор

Automatic gain for the win. Long ago I made a circuit to "listen" to music and flash neon to it. I made a wide range AGC. I could plug the input into a wall socket and it would be fine, yet it could pick up the signal from a turntable without a preamp.

kevinmerrell
Автор

very nice. It's so good to see analog still being taught; alan, retired analog engr.

alanh
Автор

At 2:47 "More detail's better, right?" Quite right, so why not amplify the signal up to ± 5V and simply clip off the negative half before feeding it into the arduino? You would get double the resolution, since the negative half of an audio signal contains just the same information as the positive half.

At 9:14 "having the resistance of R1 near zero is probably a bad idea". No, it really isn't. It's quite normal for an opamp to be used as a non-inverting buffer, where the output is connected directly to the inverting input. Opamps are designed to work like that, and the current drawn by the inputs is normally quite negligible, certainly for audio applications. There really is problem with "leaking" or "current drain" through the feedback. The TL072 has an output impedance of 0.25Ω and can easily supply 50mA, so stop worrying about current draw.

As @Joel Styler pointed out, you must have something like a 100nF ceramic capacitor across the supply close to the IC, as it's crucial for stability. I also agree with him that high impedance means noise pickup and high-frequency loss due to stray capacitance. You could easily drop your feedback resistors down by a factor of 10 or more to improve noise immunity. You're certainly more likely to see R2 around 1K in practical audio circuits.

You also need to tie the unused opamp's inputs to something, rather than leaving them floating. The best bet is to tie the unused non-inverting input to the 2.5V bias voltage you already have, and tie the unused inverting input to the unused output.

The most important improvement you should make to the circuit is to clip the signal going into the Arduino to keep it in the range between ground and 5V. A simple way is to use a TL431 as a 5V Zener across the Arduino input and drive it from the opamp output via a 10K resistor.

If you now know that the output is constrained to the range 0-5V, then the digital pot -- fun as it is to play with -- is complete overkill. A simple trim pot for R1 will be more than adequate and will allow you to quickly set the display to match the music level.

The value of Cfilter sets the frequency at which the gain starts to roll-off and for audio use we would normally set it so that its reactance equals R2 at around 20Hz. That implies a capacitor of around 100nF if R2=100K or 10μF if R2=1K.

You don't need two supplies. Many opamps are designed to be used with single-supply. The TL072 is a BiiMOS opamp and is described in its datasheet as "wide-bandwidth high-output-drive single supply" and it was quite good for its time. Nowadays, there are CMOS opamps that can swing to within less than 100mV of either rail, so one of those (e.g. MCP6002) would be a good upgrade.

Finally, it is good practice for automotive use to remember that the supply voltage can be anywhere from around 12V to 14V, depending on whether the engine is running. So the usual way to make the bias point independent of the supply voltage is to use another TL431 as a 2.5V Zener in place of your R3, ensuring that the non-inverting input (and hence the output) stays at 2.5V regardless of the supply voltage.

RexxSchneider
Автор

Looking forward to more of your tutorial videos (electronics related). Very good explanation.

MrMhsn
Автор

I like the idea and the concept of where you were going but did have an issue with the op amp. If the sound input has a brief peak of high energy, the output level could exceed the input specification of the ADC input on the micro controller. And more than likely, there will be a significant excursion past those limits at power up due to the position of the capacitors in the circuit. Or if anything went wrong on the op amp side, you could be dumping about -10 or +10V on the input pin. A quick solution might be to add a resistor between the op amp and the microcontroller, to limit the current flow into the protection diodes on the chip. I generally like to use a rail to rail op amp running at the circuit voltage (usually 3.3V for my designs)., this means i don't need extra voltages and automatically provides a limit on the output within the acceptable range of the ADC input. And no negative voltages either. For a circuit like this, an inexpensive op amp like the MCP6001/6002(dual) would probably be fine. This part is also available in a DIP package as I recall which will make it easier for you. Pretty cheap as well. There are tons of other acceptable op amps from Microchip, Texas Instruments, Analog Devices and others.

Also, you generally don't have to worry too much about the feedback drawing too much current to the - input, the inputs are usually very high impedance. As long as the overall divider doesn't exceed the capable output current of the op amp, there shouldn't be an issue. Staying in the 10K to 100K range is usually a good compromise, if the impedance gets too high, bandwidth could suffer due to input and stray capacitance and be more likely to pick up noise. For low frequencies, I generally work around 10K, for analog video I will use 1K or less.

Also, don't forget a bypass cap on the power pin(s), it will help keep things stable and keep noise lower.

For biasing, I would have probably just used divider resistors to power and ground directly on the + input, eliminating an extra resistor and cap. I don't believe the slight noise improvement of the extra parts will help here, especially with good, stable and clean power supplies.

Those are just my suggestions. Keep learning, sharing and trying new things. If you can get your hands on an old National Semiconductor Linear Applications book, it will help open up a big analog world. I think the earlier 1978 to 1982 versions were best (in my opinion). Good luck and keep going.

joelstyer
Автор

Some things to mention.
You should add series resistor and 2 clamping diodes in parallel to ground (a zener and a reversed shottky) for extra protection.
Also, by setting a different vref on mcu, you could reduce required gain. The uno has a vref pin as well as an additional internal 1.1v vref.
If you set vref low enough, you may be able to remove the opamp entirely with limitation on minimum amlitude for best results.

btwnder
Автор

"I managed to kill my second digi-pot by accident" got me right in the feels, and I've got 40 years experience.

davidgari
Автор

Beautifully explained, Many Thanks Sir..

stanleydsouza
Автор

That was beautifully clear. Thank you. :)

mechanoid
Автор

Input impedance of OpAmp is so high you don't have to worry 'bout currents it sinks.
Ideal OpAmp has infinite input impedance. For your application you may consider any single chip OpAmp you choose as ideal one.

froller
Автор

There is input leakage current in the opamp. This favors lower resistors. Additionally input capacitance can limit frequency response if feedback resistors are too big. Input offset voltage need not be considered because the dc gain is low.

robertdeland
Автор

X9C104 can be 0 ohms without causing ANY problems. In fact, virtually any modern OP_AMP can work as a VOLTAGE FOLLOWER or BUFFER, by connecting inverting input directly to the output.

voicevoicelessKrzysiek
Автор

Hey Chris I'm ready to build this now 😃 in the description it says you uploaded the source code but I can't find it. Any help would be appreciated 🙂

kwisatzhaderach
Автор

With a single audio signal, it makes no difference if it gets inverted or not.

If working with an alternating signal into an opamp with a monopolar power supply, use the series input capacitor as shown, and follow it with a bias voltage sufficient to bring the output within the power supply video shows this, but only for the reason of not presenting negative voltages to the Arduino. BTW, if after amplification by a positive-only opamp circuit, it is desired to have the signal be bipolar/alternating again, follow the output with another series capacitor, then a resistor to ground to re-bias.

youtuuba
Автор

I'm confused about the gain range you chose, being about 1 - 3x
If max P2P is 1v, then your max output would be 3v. But that's your max gain against max input. If your input volume is much less, you can't increase your gain to compensate, you've already maxed it.

danman
visit shbcf.ru