Read audio level from amplifier

Hello. I want to "read" audio level on Nano clone from audio mixer based on TL072CP (AVT742 diy module, scheme below). I will have three inputs (DFPlayer Mini, XY-BT-Mini and audio jack) connected to AVT742 and output to small PAM8403 amplifier, then to speakers. I would like to read audio level between mixer and amplifier, probably one channel only (but two channels is only duplication of circuit).
Regarding to AVT742 documentation, it can be powered by 6 - 24V DC and on 6V it outputs 3Vpp max audio signal without DC component (9V power - 6Vpp; 12V power - 9Vpp). According to this - what will be the best method to get audio level? Power AVT742 with 12V, then connect a diode from output to Arduino pin and use analogRead() function? If I am right, output signal will be -4,5V to +4,5V max and using diode will give me 0V to ~+3,8V signal? Will 9Vpp input destroy PAM8403? Because it probably "wants" only audio jack input levels, not ~4,5V max.
Any ideas?

avt742.png

avt742.png

then connect a diode from output to Arduino pin and use analogRead() function?

A series diode is no good. The forward voltage drop means you won't read anything until you get over about 1/2 volt.

A voltage protection circuit can protect against voltages over Vcc as well as negative voltages. (For line-level audio, increase the current-limiting resistor to about 10K.)

Will 9Vpp input destroy PAM8403? Because it probably "wants" only audio jack input levels, not ~4,5V max.

The amplifier should be OK but you should protect the Arduino. Most audio circuits have "headroom" so it's not unusual to "overload" an input. And, there might be a volume control pot on the PAM input? If that happens it won't happen for long because you'll turn-down the volume. :wink: ...Usually, we worry more about burning-out the speakers if something like that accidentally happens with a high-power amplifier.

...It seems like you already know this but regular audio is a continuously-changing waveform that's negative half the time with a zero-crossing twice per cycle, so the "raw" readings are essentially random. And when you kill the negative half of the waveform, half of your readings will be zero. So, you need to find the peaks or the average of the positive values, etc.

Most audio circuits have “headroom” so it’s not unusual to “overload” an input. And, there might be a volume control pot on the PAM input? If that happens it won’t happen for long because you’ll turn-down the volume. :wink: …Usually, we worry more about burning-out the speakers if something like that accidentally happens with a high-power amplifier.

PAM8403 circuit is 2x3W and it is 2.5-5V powered, so if sometimes it burns I could change it for something more powerful and speakers are 3W too. Volume of XY-BT-Mini will be controlled simply by phone volume, DFPlayer will be controlled by Arduino with buttons (playing and volume).

It seems like you already know this but regular audio is a continuously-changing waveform that’s negative half the time with a zero-crossing twice per cycle, so the “raw” readings are essentially random. And when you kill the negative half of the waveform, half of your readings will be zero. So, you need to find the peaks or the average of the positive values, etc.

I know, but if I connect Arduino directly to 9Vpp signal (apart from any protection etc), analogRead() read between 0V (0) and +5V (1024) so negative part of waveform will be 0 (or trash). Maybe will be better power AVT742 with 6V (and get 3Vpp) and then add DC component to signal (f.e 2.5V) and then should be 1V - 4V. Or maybe I should use some photocoupler to extract signal to Arduino?

PAM8403 circuit is 2x3W and it is 2.5-5V powered, so if sometimes it burns

The mixer is capable of higher voltage but of course you're not going to "blast" it like that. If you happen to turn it up to the point of distortion you'll just turn it down and everything will be OK.

I know, but if I connect Arduino directly to 9Vpp signal (apart from any protection etc), analogRead() read between 0V (0) and +5V (1024) so negative part of waveform will be 0 (or trash).

Again, you won't have 9V under normal conditions... It will probably be less than 1V. I don't know what the gain of the PAM amplifier is but probably takes less than that to get the full 3W out of the amplifier.

...The voltage will go about 1/2V negative before the diode "kills it" and I'm pretty sure it will read exactly zero. You'll have to ignore the zeros in software, or you can simply take an average and don't worry about the zeros. (The negative voltage only gets "killed" on the diode-side of the resistor so your audio signal going to the amplifier will be undistorted.)

I think I understand. But theoretically, if I connect one channel from AVT742 mixer output (so basically from TL072 amplifier) directly to Adruino's pin and get value via analogRead() (without diode), I will get value from 0 (when there won't be signal or when it will read at negative part of signal) to something (512 for 2,5V). This shouldn't interfere with output and shouldn't broke Arduino (because it sould be less than 5V). Am I right? Arduino, audio inputs, audio outputs, PAM amplifier will have common ground.

Right. The Arduino should be fine with the protection circuit. And, you'll probably be surprised how low the line-level voltage is. It's really the negative voltages that are more important.

The mixer circuit might not even be able to put-out enough current to damage the Arduino but the resistor in the protection circuit also prevents the negative half of the waveform from being distorted.

Okay. I found yours schematic: https://forum.arduino.cc/index.php?topic=476900.msg3259263#msg3259263 will it work for me? It should be 512 (or 2,5V) for no signal and 0 or 1023 for maximum level. I have 10uF 25V capacitors on stock, it shouldn't matter, right?

Yes, the 2.5V bias circuit will work.

It will protect against negative voltages as long as you don't exceed 5V peak-to-peak (which you usually don't for a line-level signal).

It should be 512 (or 2,5V) for no signal and 0 or 1023 for maximum level.

Correct - Just remember it's a wave which will "occasionally" read 0 or 1020 when you happen to sample a positive or negative peak.

Typically, you'd subtract-out the bias and then find the positive peak, or peak of the absolute value, or the average of the positive, values or the average of the absolute values, etc.

You have to use an ideal rectifier with op-amp, with a capacitor and a discharge resistor. Output signal, after the output capacitor, is about 1Vpeak max, then you have to gain about 5 to get 5V max.
Go to Arduino via a 10k resistor and clip with a 5.1V Zener.
Keep in mind:

  1. This isn't a real RMS meter: this is a peak meter you can adjust to read the RMS value of a sinusoidal signal.
  2. If you want to drive some leds, you have to do it by exponential values, because human hear is logarithmic: 1023 725 515 365 259 184 130 92 65 46 33 23 17 12 8 6 4 3 2.
  3. You have to read a slowly variable signal, otherwise Arduino will read randomly different points of the sinusoidal signal giving random values.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.