My knowledge in electronics is poor.

I want to output audio stream from mic to audio And I use following code in Arduino

 val = analogRead(analogPin);
tone(SND_PIN, val);    

It outputs some value, for example 1023, what is this? Is this code right, and can we connect to mic directly from arduino?

  • \$\begingroup\$ How many bits is your ADC? What circuitry have you got on the analogue pin? If the correct circuit is on the ADC input pin and your o/p in digital is 1023 then it would follow that you are using an 11-bit ADC. However, if you are using a 10 bit ADC then your analogue circuitry needs fixing. \$\endgroup\$
    – Andy aka
    Apr 15, 2013 at 10:40
  • \$\begingroup\$ The Arduino function "tone" in your example expects a frequency as its second argument ("val"). However, the value you get from the internal ADC via analogRead is not a frequency, but a simple "snapshot" of the voltage at the pin. \$\endgroup\$
    – fm_andreas
    Apr 15, 2013 at 12:02

2 Answers 2


The value is the output of a sensor reading from an Analog-to-Digital-Converter(ADC). An ADC converts from real world values to something the microprocessor can understand, a series of bits.

So a real quick overview of how an ADC works: You feed it a Vref voltage, and a signal. That signal is supposed to be between GND and your Vref. It then gives you a binary representation of what voltage your signal was. The number of bits of your ADC is the amount of granularity it can give you. So let's say your Vref is 5V, and you feed into the signal a sine wave going from 1V to 3V. Now let's also say you have a 10-bit ADC. Your value is going to be oscillating between (1/5 * 1024) to (3/5 * 1024).

So that's what your getting when you print out val on the serial port. Now, as to whether your mic and audio equipment can be hooked up directly to pins on an arduino, we probably need more information to answer. Please let us know which part #s you have and any details you have about them etc. and we can provide more information about that. For example, you might need an amplifier or other supporting parts. To get you started check out this example of an arduino with an electret microphone.


Check that the voltage into the ADC pin is varying. Use a potentiometer to vary its DC value until you can see the println output number varying as you expect.

Then try the microphone. Most likely you will see values close to half the ADC's range with very little variation. That would indicate you need more gain - an amplifier between mic and ADC where you can vary the gain - 40dB or 100x voltage gain would be a first guess without knowing your microphone or sound levels.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.