Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Using a microphone with an Arduino (Read 2079 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Using a microphone with an Arduino

I am entirely new to the Arduino (but I'm familiar with programming). In order to built a VU meter, I want to put a microphone to the analog 0 pin of the Arduino and display the value via the serial connection.

I googled and found this circuit:

... and I tried to build it with this result:

The values on the serial monitor don't change depending on the music volume.

What is the easiest way to measure the volume on the analog input of the Arduino?

Also, I have a TDA2822M, but I don't know if it is helpful for this project. The caption on the microphone reads XF-18D.
My arduino code:
Code: [Select]
void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.println(analogRead(0));
  delay(300);
}
The serial output: 1023 1022 1022 1022 1022 1023 1022 and so on

How can I check if the microphone works at all? Is it directional?

 

Re: Using a microphone with an Arduino

Reply #1
There is an Arduino forum.

The Arduino's analog input needs a "DC reference", plus, it can be damaged by the negative voltages including the negative-half of an AC audio signal.    Use two equal-value resistors to bias the Arduino's input at 2.5VDC.  Your AC signal will ride on top of that bias.

With the DC bias silence should read about 512.  Low signal levels will give you readings slightly above and below that value and if you have a 5V Peak-to-peak signal, you'll get readings between 0 and 1023.  You can subtract-out the bias in software if you wish.

You might want to re-think that 300mS delay, since you are reading a waveform that's continuously varying in the approximate range of 20-20,000Hz.   As you may know, CD audio is sampled 44,100 times per second.   (The Arduino's ADC isn't accurate at that speed.)
 
Typically, you'd take several (or many) readings, and then take an average (of the absolute values), or find the peak or RMS, then spit-out a result and loop again.  The easiest thing to do is read as fast as possible in a loop and find the peak over a 1/10th second (or so) duration.

Quote
Also, I have a TDA2822M, but I don't know if it is helpful for this project.
If you've already built the transistor circuit you might as well use it, if it works.    I would have used an op-amp.  Or, I'd buy a microphone board.  That one doesn't have variable gain but they do publish the schematic if you wanted to copy the circuit.