How do they get away with audio input connected directly to a pin?

Hello, newbie here trying to learn about circuits a bit more.

I'm trying to understand how this tiny audio visualizer works, but I'm stuck at the audio input: video example.

I found a schematic of how it's connected at instructables.

and a "drawing" of the circuit

He's using an Attiny13a, but I'm guessing applying this to an arduino would have similar results.
As far as I understand, he's joining the left/right channels and connecting directly to pin 4.

There are multiple posts on this forum about audio input, so I want to summarize them before I continue: everybody suggests never to connect analog audio directly to a pin, because it's AC, and arduino is DC. Also, because audio will have negative voltages, while the arduino pins support -0.5-+5v, so there's a chance it can kill the arduino.

There are multiple circuit suggestions, but the common is the one I'm attaching. Some don't add the resistor between the audio and the capacitor, and others have different values for the capacitors and resistors, but the idea is always the same, to convert AC to DC and offset values to be in the range 0-5v. Is that correct?

If so: how does he get away with this circuit for this tiny audio visualizer? Is he just compromising the processor to be able to keep the circuit simple? And if so, would something like put the audio device at risk (mp3 player or whatever is used to generate audio)? or even though it's bad advice, an audio signal from an mp3 player is unlikely to cause damage?

Another example of someone connecting analog audio directly to a pin: Arduino Audio Input - YouTube

Basically their are a lot of idiots out their who have no clu as to what they are doing or if they are damaging the Arduino. The tell tail instructables tag normally denotes an idiot.

The attached file shows the correct way of connecting audio but it is drawn rotated.

hey, I recognize your name from the posts I've been reading :slight_smile:

cool, I figured it wasn't a good idea.

For some reason audio input seems elusive. Most tutorials/books for newbies I've seen don't do anything beyond examples using electret mics. I would've thought this topic would be more popular, and that there'd be a few breakout board solutions for newbies.

I only found 2 things that would make it easier from sparkfun:

But both seem overkill.

It looks like smd components would be the best option to keep this tiny, but I'll learn how to build this with breadboard friendly components first.

Thanks for the help. Now I know what components to order. It'll be a while until I can test it.

If you want to do some sound effects the this might be interesting Adafruit Audio FX Sound Board - WAV/OGG Trigger with 2MB Flash : ID 2133 : $19.95 : Adafruit Industries, Unique & fun DIY electronics and kits or this one Overview | Wave Shield Voice Changer | Adafruit Learning System

Or their is this Audio Adapter Board for Teensy 3.0 - 3.2, 3.5 and 3.6 : ID 1780 : $17.50 : Adafruit Industries, Unique & fun DIY electronics and kits have a look at the video from this page, it is long but it shows some of the complex things that the Teensy can do simplified for a beginner.

Most tutorials/books for newbies I've seen don't do anything beyond examples using electret mics.

Well check out the topics in my book:- Audio Arduino their are some very complex projects but also some simple ones. Their is a lot of MIDI stuff but also the sound processing you seem to be looking for.

Instructibles have no quality control of any sort as far as I can tell, although you might find some
kind soul adding corrections in the comments if lucky.

but the idea is always the same, to convert AC to DC and offset values to be in the range 0-5v. Is that correct?

Not really convert AC to DC (that's rectification), but rather add a DC offset to the AC signal. Its common
to use the mid-rail voltage as a virtual ground in low voltage analog circuits these days (in the old days
+15/-15V split supplies were the rule, and 0V was signal ground).

Also found this audio analizer module. It uses the Msgeq7, similar to the sparkfun one.

Thanks for all the info. Audio/sound is like an entirely new universe, so much to learn.

This is what I did with a pair of those chips on a Raspberry Pi:-

You could do the same with an Arduino an a program running with the Processing language.

ha, that's pretty creative!

I made some progress on my side, but I'm not if it's correctly built.
The thing is connected to A0, and reading with analogRead, I get a value of about 510 when there's no sound, and only goes between 498 to 525 when playing music from a phone. Good enough for what I want, although it'd be better to have a wider range

Now, I'm not really sure if I'm supposed to use the capacitor I'm using. It's 10uF 50v, and the negative side is on the side of the audio input...is that the correct placement? After some reading, I think I was supposed to get a normal capacitor instead of a polarized one?

Also, I don't know if I placed the resistors correctly. I'm guessing there's a difference depending on which side goes where.

I attached a couple of photos of the thing. Any help on confirming if I'm doing things right would be really really appreciated.

The only thing I'm sure is wired correctly is the passthrough from the left jack (input) to the right (output). I joined the left+right signals because the TRS jacks are not too breadboard friendly, and that's the only way they stayed in place.

What do you think? is it cringy or there's hope?

[edit: exceeded file size with the original attachments.]

something I just discovered is that if I disconnect the headphones from the output jack, the values are way different, the range is bigger, it goes from like 400 to 600.

I get a value of about 510 when there's no sound,

Yes you will, those two 100K resistors ensure that with no audio input they act as a potential divider and supply half the 5V supply voltage to the input. If 5V gives a reading of 1023, then half 5V or 2.5V will give a reading of 512, so 510 is the sort of value you would expect.

and only goes between 498 to 525 when playing music from a phone.

That means you have to either turn up the volume or put an amplifier between the phone jack and the input.

You can't get very big capacitors that are not polarised and given that the audio input to the Arduino is sitting at a DC level of 2.5V then yes the negitave end should be towards your audio and the positive towards your Arduino.

is it cringy

Yes, shorting two outputs together is never a good thing to do. It could damage your phone.

if I disconnect the headphones from the output jack, the values are way different, the range is bigger, it goes from like 400 to 600.

Yes it will do. Your headphones are loading your audio signal, that is placing a low resistance in parallel with it. If you want to not load your audio signal then plug your output jack to something with a high impedance like an amplifier.

Grumpy_Mike:
Yes you will, those two 100K resistors ensure that with no audio input they act as a potential divider and supply half the 5V supply voltage to the input. If 5V gives a reading of 1023, then half 5V or 2.5V will give a reading of 512, so 510 is the sort of value you would expect.

I might migrate the project to a smaller microcontroller with only 3.7v. Looks like based on the values I'm getting, it should still work. I'll need to read a bit more on this though, but thanks!

That means you have to either turn up the volume or put an amplifier between the phone jack and the input.

yeah, the headphones were the issue, I think without them, the values is good enough.

Yes, shorting two outputs together is never a good thing to do. It could damage your phone.

Yep, next step is redoing this in a bigger breadboard so I can use both left/right channels. And I might create a breakout board for the TRS jacks so they're easy to plug in the breadboard.

Yes it will do. Your headphones are loading your audio signal, that is placing a low resistance in parallel with it. If you want to not load your audio signal then plug your output jack to something with a high impedance like an amplifier.

It definitely worked with a bluetooth speaker with aux input, and with a little synth that amplifies the audio.
Lesson learned: this is an aux output, not a headphone output. I might just use a splitter before connecting the audio to the circuit or add an amplifier, but that's beyond what I'm trying to achieve right now.

I already added a little oled screen and very rough visualizer. It all works! I'll clean it up and might post a little video.

Thanks a lot for all your help. This little project definitely left me willing to learn a lot more!

I might migrate the project to a smaller microcontroller with only 3.7v. Looks like based on the values

The deviation numbers will be greater with a smaller referance voltage. The top resistor now goes to 3.7V instead of 5V.