Go Down

Topic: audio input thoughts... (Read 1 time) previous topic - next topic


I've been searching around but can't really figure out a simple way to get a bit decent sine-level detection on the analog input.

I enter a audio sinewave into the arduino to get max voltage difference (.7v) but the output is giving 'erratic' results.

I understand that sound is something different than a nice and steady voltage level on e.g. potmeter but at the moment I can't really detect anything useful from the audio level.

Is there a simple way - hardware wise - to just flatten out the sound a bit so it's easier readable by the arduino? I don't really care about the fact that I have to 'upscale' the sound level internally which degrades resolution. I would rather not use any active components on the input.

Where I'm thinking at now is to use a diode to remove the negative volts, probably leaving .35 volts in level difference and then? A capacitor in leveling out the sines? I'd probably need to set a sound frequency in which the capacitor works at it's best?

And would the sinewave be best to use? (I could also use a square wave but remembering AC/DC conversion-lessons in the past I thought sines would work best flattening out)

Am I in the right directon here or has someone been-there-done-that and advises me to leave this be?


If you're putting negative voltage on an Arduino input pin, that won't work. You will need to rectify it first. But, I think you'll have trouble. You mention max V diff. of .7V, so I infer that your peak +V is .35V. A diode typically has a forward voltage drop of .7V, so there goes your whole signal.

It is true that once you've rectified it, you can use a capacitor to filter and get closer to DC, but your voltage will still have ripples.

More description of what it is, functionally, you're trying to do, would likely help here. Since you mention using square wave instead, it would seem you're generating the sine wave as well. What is it that's generating the signal?
... it is poor civic hygiene to install technologies that could someday
facilitate a police state. -- Bruce Schneier


You try running your AC thru a cap to two 10K resistors from +5 to Gnd, the resulting level is 2.5V, your AC would wiggle the 2.5 V up & down.
Keep in mind the 10K sampling rate of the ADC limits your usable audio to 5K max. (Nyquist theory, need sampling to be fast enough to catch at  least 1 high sample and 1 low sample to be able to recreate the incoming wave).
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.


Thanks for the input, indeed - lifting the whole signal would be a much better idea. I'm trying to control a light on the audio output level of an iPad. I'm using synthesizer software to generate sound levels. Just sliding the volume would brighten/dim the light. Using left and right channels seperately I could even try and control 2 channel output.


You need a peak detector.
Or google for lots of schematics.


  Take a look here http://interface.khm.de/index.php/lab/experiments/arduino-realtime-audio-processing/ there are some schematics and sketchs to sample audio signal. Then you can use these sketchs and instead of the output part you may substract the offset, calculate some power values, and output the values on the light. The function analogWrite() might be disabled in this sketch but PWM works on pin 11 (pin 11 is used to output audio cf sketch).

Hope I have been helpful :)


Keep in mind the 10K sampling rate of the ADC limits your usable audio to 5K max. (Nyquist theory, need sampling to be fast enough to catch at  least 1 high sample and 1 low sample to be able to recreate the incoming wave).

Exactly, we have to follow 2*F rules when we need to know spectral content or when incoming waveform should be restored after passing communication line. But it's not the case for magnitude (RMS) measurements, and 10K sampling works works great with input analog frequencies up to 20 kHz, or even higher.

Go Up