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.
closed as too broad by Matt Young, PeterJ, Voltage Spike, Dmitry Grigoryev, Brian Carlton Aug 15 '17 at 22:46
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
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.
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.
What you want is called a microphone. Those put out tiny signals roughly proportional to the instantaneous sound pressure.
Typical microphones put out from less than a mV to a few mV. You therefore need to amplify the raw microphone output by about 1000. That's not too hard to do with two opamp stages each amplifying by about 32.
AC couple the result onto the output of a resistor divider that makes 1/2 the supply voltage of your microcontroller. Then feed this voltage into a A/D input. The rest is firmware.
If you only care about the volume of sound, not the actual sound, you can do the volume detection in a analog circuit and feed the result into the A/D input. The advantage of this is that you can sample the A/D at a much lower rate.
Still, just sampling the A/D at, say, 50 kHz, then doing everything after that in firmware is a reasonable approach. Even if you just wanted volume at maybe up to 20 Hz bandwidth, that can be done in firmware from the 50 kHz sample stream.
In order to change colors with frequency, you need to split the audio signal to several (3?) frequency bands and have each band control a different color. To do this, you need 3 parallel band pass filters, say one tuned to bass frequencies controlling the red LEDs, one on mid controlling the green and one on high controlling the blue (if we assume you have an RGB strip). I'm quite sure the analog output from your sensor can't drive this though and I suspect you need some amplification or buffering in your signal path. Then you could get these 3 outputs to your analog ins or to the bases of transistors controlling the current to the LEDs.