Tuesday 21 November 2017

microphone - How to get audio from a sensor for an Arduino



I am working on an Arduino project that requires recording sound that is playing and flashing LED strips to go with whatever is playing in the air. Currently I am using a sensor called the KY-038 but I am unsure how to get audio from it or if it is even possible to get actual audio from it instead of just volume. Basically what I want is some help getting the correct sensor and a guide or some directions on how I can turn the data from the sensor into something that I interpret on an Arduino.




Answer



The audio detector you have chosen is IMO not viable for your project needs. The KY-038 is a very simple sensor and from it's schematic (shown below) you can see that the gain is adjustable but with no pre-amplification to the analog output. The potentiometer in the main adjusts the threshold for the level detector, though it also has a gain effect for the Electret microphone (which has an inbuilt FET). Unfortunately the gain and output impedance of the Electret are tied, and this makes it a very poor candidate for providing good audio input to the Arduino A/D without an external pre-amp/buffer.


enter image description here


The op-amp in the KY-038 is an LM393 and if you examine the schematic in detail you can see that you can make the circuit somewhat into an analog amplifier with an offset adjust ...however it's none ideal. Put a 50k Ohm resister from A0 to ground and a 100k Ohm from D0 to A0. You can then adjust the potentiometer to get 2.5 V on the D0 output and use this as the analog signal.


I don't recommend you do this, but would recommend you buy a more suitable audio mic/amplifier module ($2-3) such as that sold by many Ebay suppliers based on the MAX4466. The volume control actually works on this module and it has quite reasonable sensitivity!


Assuming you get to be able to get the audio you require, providing conversion to enable you to understand both amplitude and frequency components can best be done by implementing an FFT on the Arduino. If this is your first foray into FFT I recommend you use a bouncing ball project such as that provided by Adafruit. This uses the same MAX4466 based microphone amplifier and may represent a good starting point for you to learn.


If you want to roll your own FFT and A/D code, then you will need to be able to run your A/D at a high continuous conversion rate. I don't recommend that you go above the maximum 9.6kHz conversion rate you get on the Arduino. Nyquist Theorem says that at that 9.6kHz sampling rate, the highest frequency component you can resolve is 4.8kHz.
If this is not enough bandwidth for you then you will need to increase the A/D conversion rate by altering the ADCSRA register. The prescaler for the A/D is 128 by default, you can read the ATMega328 datasheet 28.9.2 to learn more. The higher the conversion rate the more problems with noise you will have and this will impact the number of bits you can rely on for amplitude.


The last comment is that in the question you say you want to record the audio. This implies that when you play it back you want to understand it. ...yet another reason to drop the KY-038 and get a better mic/preamp module with good gain and linearity.


No comments:

Post a Comment

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...