See how a bar graph respond to music and sound in a little OLED display. Lowest frequencies toward the left end of the graph, highest frequencies toward the right.
ConstructionConnections
- Connect Mic GAIN depending the sensibility that better suits your system: VCC to mic GAIN for 40dB, low sensitivity, GND to mic GAIN for 50dB, medium sensitivity or let floating the mic GAIN for 60dB, high sensitivity.
- Connect Analog pin 0 A0 to mic amp OUT
- Connect 3.3V, GND, SDA (or analog 4 A4) and SCL (analog 5 A5) to I2C SSD1306
- connect a 470 uF capacitor between VCC and GND in power bus
Getting low frequency noise?
The noise comes from any electric devices near your measuring system that are working. All of the electronic devices work with a fixed frequency and voltage of alternative current (AC) with the frequency of 50 Hz or 60 Hz is the power line frequency in your country. You can use a faraday cage to eliminate the noise easily. Put your circuit inside a box and connect the box to ground. Ground well the circuit.
Pinout of Arduino Nano 33 BLE
Using arduino core AnalogRead and the Arduino Nano 33 BLE we can only get about 35, 000 samples per second so we cannot use FFT for frequencies above 17.5 Khz, as we have to read the clock and make several comparisons in a busy waiting loop we are going to be cautious and take an upper limit of 8 kHz . So we can use a simple RC low pass filter to avoid annoying solutions beyond that frequency.
R = 180Ω C = 0.1uF for a Cut-off frequency fc = 8842 [Hz]
Here using a 2K Ohm resistor and a 4.7 nF capacitor for a Cut-off frequency fc = 17000[Hz]
Using the normal Arduino analogRead() function is too slow for sampling audio, so let's calculate the maximum sample rate.
We are going to estimate how many samples we can get using arduino core AnalogRead and the Arduino Nano 33 BLE.
Let's run this little program to have an estimate.
/*
* Rough calculation of maximum sample rate with AnalogRead
*/
#define ANALOG_PIN A0
#define SAMPLES 1000000.0
int newTime;
int analogValue;
void setup() {
Serial.begin(9600);
Serial.println("Sampling... please, wait. ");
}
void loop() {
// put your main code here, to run repeatedly:
newTime = micros();
// 1 millon samples
for (int i = 0; i < (int)SAMPLES; i++){
analogValue = analogRead(ANALOG_PIN);
}
float elapsedTimePerSampleUs = (micros()- newTime) / SAMPLES;
Serial.print("Time per sample (us): ");
Serial.println(elapsedTimePerSampleUs);
Serial.print("Max sampling freq(hz): ");
Serial.println(pow(10,6) /elapsedTimePerSampleUs );
}
Using arduino core AnalogRead and the Arduino Nano 33 BLE we can only get about 35, 000 samples per second. The approximately double-rate requirement, consequence of the Nyquist theorem will limit our spectrum visualizer to frequencies below 17 kHz. We can use a low pass filter to skip frequencies above that limit.
We have to read the clock and make several comparisons in a busy wait loop, we are going to be cautious and take an upper limit of 8 kHz.
// take samples
for (int i = 0; i < SAMPLES; i++) {
unsigned long newTime = micros();
int value = analogRead(ANALOG_PIN);
vReal[i] = value;
vImag[i] = 0;
while (micros() < (newTime + sampling_period_us)) {
yield();
}
}
The User InterfaceThe screen is divided in eleven frequency zones and you a logarithmic scale grouping frequencies similar to how the human ear perceives them.
Humans can detect sounds in a frequency range from about 20 Hz to 20 kHz. (Human infants can actually hear frequencies slightly higher than 20 kHz, but lose some high-frequency sensitivity as they mature; the upper limit in average adults is often closer to 15–17 kHz.)
Will use zones 3 to 13 (11 zones) for our representation.
Each bar represents the maximum value in the band with spaced lines and the mean value in the band with a filled rectangle.
Values are shown using decibels with a preselected reference obtained in a heuristic way.
How it works?The audio samples are converted into a frequency spectrum using a fast Fourier transform or FFT.
Then the spectrum is divided and grouped in 14 zones and only 11 zones are represented in dB.
About the microphone moduleElectret Microphone
Electret is a quasi-permanently charged dielectric. It is made by heating a ceramic material, placing it in a magnetic field then allowing it to cool while still in the magnetic field. It is the electrostatic equivalent of a permanent magnet. In an electret microphone a slice of this material is used as a part of the dielectric of a capacitor in which the diaphragm of the microphone forms one plate. Sound pressure moves the diaphragm. The movement of the plate varies the capacitance according to the sound pressure. Given the built-in fixed charge of the dielectric, the voltage across the capacitor will also vary. The electret capacitor is connected to the input of a built in FET amplifier. Electret microphones are small, have excellent sensitivity, a wide frequency response and generally a very low cost.
MAX9814 Microphone Amplifier
The MAX9814 is a microphone amplifier with automatic gain control (AGC) and low noise microphone bias and and has a few options you can configure with the breakout.
The MAX9814 module has three amplifier settings (40dB, 50dB, 60dB). The default is 60dB, but can be set to 40dB or 50dB by jumpering the Gain pin to VCC or ground.
Internal low-noise microphone bias 1.25V, 2Vpp. The ouput from the amp is about 2Vpp max on a 1.25V DC bias, so it can be easily used with any Analog/Digital converter that is up to 3.3V input.
The Attack/Release ratio also can be modified, from the default 1:4000 to 1:2000 or 1:500.
For connecting directly to a Line Input, you need a blocking capacitor / coupling capacitor to block the DC component. You can use a blocking capacitor in series above 1uF, depends on your system, if in doubt try from 33 uF to 100uF. A coupling circuit allows AC signals to flow from one part to another while blocking the DC components. In audio circuits, this is done to prevent DC components from distorting the audio output. The effectiveness of a coupling capacitor depends on a broad array of frequency-dependent parameters including insertion loss, equivalent series resistance and series resonant frequency.
Power supply: 2.7V to 5.5V
Sensitivity
Sensitivity, the ratio of the analog output voltage or digital output value to the input pressure, is a key specification of any microphone. Mapping units in the acoustic domain to units in the electrical domain determines the magnitude of the microphone output signal, given a known input.
The sensitivity of a microphone is the electrical response at its output to a given standard acoustic input. The standard reference input signal for microphone sensitivity measurements is a 1 kHz sine wave at 94 dB sound pressure level (SPL), or 1 pascal (Pa, a measurement of pressure). A microphone with a higher sensitivity value has a higher level output for a fixed acoustic input than a microphone with a lower sensitivity value. Microphone sensitivity in decibels (dB) is typically a negative number; therefore, a higher sensitivity is a smaller absolute value.
For analog microphones, the sensitivity is typically specified in units of dBV, that is, decibels with reference to 1.0 V rms.
Reference level and Frequency Response
The frequency response of a microphone describes its output level across the frequency spectrum. The high and low frequency limits are described as the points at which the microphone response is 3 dB below the reference output level at 1 kHz. The reference level at 1 kHz is customarily normalized to 0 dB.
0.91 inch OLED I2C Display 128 x 32 PixelsThis is a small display, only about 1" diagonal. It is made of 128x32 individual white OLED pixels, each one is turned on or off by the controller chip. No backlight is required. This reduces the power required to run the OLED.
The model we’re using here has only four pins and communicates with the Arduino using I2C communication protocol. This model has no RESET pin. You just need to connect to the Arduino Uno I2C pins:
- Arduino Nano: SDA (A4); SCL (A5);
To control the OLED display you need the adafruit_SSD1306.h and the adafruit_GFX.h libraries. Follow the next instructions to install those libraries.
We are using Adafruit libraries. Remember you can buy something from Adafruit to support them.
Next steps
Arduino Nano 33 BLE uses a can do be better getting analogs reads. Next version I will use FFT and Analog input optimized for the nrf52840.
Comments