# How to read an audio signal using ATMega328?

I was trying to use the ATMega328 ADC port A0 to read a signal. The hardware I used was:

The signal I got seems to be only the positive part of a sine wave. Is it possible that this setup isn't suited for audio recording? What I have to change?

-
Wow, they sell DIY electonics components without even giving you the schematic. Seed Studio sucks. –  Connor Wolf Oct 18 '10 at 0:08
Fake Name: Agreed –  Kellenjb Oct 18 '10 at 0:16
@Fake do you know a better alternative? –  Jader Dias Oct 18 '10 at 1:42
@Jader It all depends on how much work you are wanting to do. Here are some options: sparkfun.com/commerce/product_info.php?products_id=8635 sparkfun.com/commerce/product_info.php?products_id=8872 –  Kellenjb Oct 18 '10 at 4:11
@Jader Dias - Yeah, a breadboard and a op-amp. –  Connor Wolf Oct 19 '10 at 3:27
show 2 more comments

## 3 Answers

Do you have a DC-blocking/biasing capacitor at the input?

The combination of the C with the R sets the lowest frequency that can pass through to the ADC. DC (the ultimate low frequency) is blocked, while AC passes through. In this case, the cutoff frequency would be 1 Hz, which is plenty low for audio.

The DC bias is provided by something in the middle of the ADC range, with low noise. For example:

This would produce 2.5 V at DC, but the AC is closely coupled to ground by the capacitor, so it filters out any fluctuations in the supply. A larger capacitor would improve the noise at lower frequencies.

(Originally I linked to this image, but that would only work if your 5 V supply is noise-free.)

-
Good schematic... I'll check it. –  Jader Dias Oct 18 '10 at 1:41
@blalor strictly speaking 0V doesn't become 2.5V. The general rule is that the DC component of the signal becomes 2.5V –  Jader Dias Oct 18 '10 at 1:54
@blalor if you were able to put an infinitely large capacitor in there, you would see that your entire signal is shifted to be centered around 0v. Hence, removing the DC offset. This is a common method to make sure that there isn't any circuit adding an unwanted offset. R1 and R2 then just add back a known dc offset for ADC purposes in this case. Since we can't have infinitely large caps we settle for smaller caps that cause some of the low frequencies to get cut off. –  Kellenjb Oct 18 '10 at 2:22
Infinitely large caps would take forever to charge up to the bias voltage anyway. –  endolith Oct 18 '10 at 13:48
@Jader: It was from here sites.google.com/site/ki4mcw/Home/arduino-tnc , but it's actually not a good circuit. I'll redraw it. –  endolith Oct 19 '10 at 15:44
show 8 more comments

Without having ever used any of those parts, let me see if I can take a stab. Do you happen to have access to an oscope? If so you might want to check your signal before you start building anything.

Most likely your microphone/amp is outputting a wave that is centered around 0v, meaning you have + and - voltages. Think of a sin wave that fluctuates between -1v and 1v. In order for your micro to use this, you will need to add a DC offset such that you most negative voltage becomes slightly above 0v and your most positive voltage is slightly below the max that your micro can read (probably around 5v).

With out looking into your components in more, it is hard to tell you specifically what you need to do in order to get your DC offset, but maybe this will put you in the right direction.

-
Without is written without spaces –  Jader Dias Oct 17 '10 at 23:45
Corrected for you. –  Kellenjb Oct 18 '10 at 0:08
add comment

The solution is to use an Amp-Op

In a circuit like this:

You can simulate it using the Java Circuit Simulator where you can import the following code:

\$ 1 5.0E-6 10.20027730826997 57 5.0 50
g 240 240 240 288 0
r 240 112 240 160 0 47000.0
r 240 192 240 240 0 47000.0
R 240 112 240 80 0 0 40.0 5.0 0.0 0.0 0.5
r 272 384 336 384 0 1000.0
R 176 384 144 384 0 1 40.0 0.5 0.0 0.0 0.5
w 176 384 192 384 0
c 192 384 256 384 0 1.0000000000000001E-7 -2.9572014071857935
c 192 176 192 240 0 1.0000000000000001E-7 2.5000000000001608
w 192 240 240 240 0
w 256 384 272 384 0
w 336 384 336 192 0
r 416 240 512 240 0 100000.0
w 512 240 512 176 0
w 192 176 240 192 0
w 416 240 416 192 0
w 240 192 240 160 0
a 416 176 512 176 1 5.0 0.0 1000000.0
w 416 160 240 160 0
w 336 192 416 192 0
o 13 64 0 35 20.0 9.765625E-5 0 -1


The gain will be proportional to the ratio between the resistance of the 100k resistor and the 1k one.

-
add comment