Download as pdf or txt
Download as pdf or txt
You are on page 1of 30

Sign In (https://www.hackster.io/users/auth/arduino?

current_site=arduino&setup=true&redirect_to=%2Fprojecthub%2Fjavagoza%2Fsound-spectrum-visualizer-with-arduino-

nano-33-ble-3c6261)

Sound Spectrum Visualizer with Arduino


Nano 33 BLE © GPL3+
(http://opensource.org/licenses/GPL-3.0)
Visualize sound frequencies spectrum with an OLED 128x32 display, Arduino
Nano 33 BLE and an electret microphone amplifier (MAX9814).

audio (/projecthub/projects/tags/audio) display (/projecthub/projects/tags/display)

home automation (/projecthub/projects/tags/home+automation)

music (/projecthub/projects/tags/music) sensor (/projecthub/projects/tags/sensor)

5,681 VIEWS 11 COMMENTS 20 RESPECTS

COMPONENTS AND SUPPLIES 

Arduino Nano 33 BLE


(/projecthub/products/buy/622
× 1 
14?
( (/proj (/projecthub/product
s=BAhJIhMzNzA0MTIsUHJvamVj
/ ecthu s/buy/62214?
dAY6BkVG%0A)
p b/pro s=BAhJIhMzNzA0MTI
(/projecthub/pro
r ducts sUHJvamVjdAY6BkVG
ducts/buy/62214
o /buy/ %0A)
?
s=BAhJIhMzNzA0 j 62214
e ?
MTIsUHJvamVjdA
c s=BA
Y6BkVG%0A)
t hJIhM
h zNzA
u 0MTIs
b UHJva
/ mVjd
p AY6B
r kVG%
o 0A)
d
u
c
t
s
s
/
b
u
y
/
6
2
2
1
4
?
s
=
B
A
h
JI
h
M
z
N
z
A
0
M
T
I
s
U
H
J
v
a
m
V
j
d
A
Y
Y
6
B
k
V
G
%
0
A
)

Electret Microphone Amplifier


Max9814
× 1 
(/projecthub/products/buy/80
( (/proj (/projecthub/product
067?
/ ecthu s/buy/80067?
s=BAhJIhMzNzA0MTIsUHJvamVj
p b/pro s=BAhJIhMzNzA0MTI
dAY6BkVG%0A)
r ducts sUHJvamVjdAY6BkVG
o /buy/ %0A)
j 8006
e 7?
c s=BA
t hJIhM
h zNzA
u 0MTIs
b UHJva
/ mVjd
p AY6B
r kVG%
o 0A)
d
u
c
t
s
/
b
u
y
/
8
8
0
0
6
7
?
s
=
B
A
h
JI
h
M
z
N
z
A
0
M
T
I
s
U
H
J
v
a
m
V
j
d
A
Y
6
B
k
V
G
%
%
0
A
)

0.91 inch OLED I2C Display 128


x 32 Pixels
× 1 
(/projecthub/products/buy/80
( (/proj (/projecthub/product
453?
/ ecthu s/buy/80453?
s=BAhJIhMzNzA0MTIsUHJvamVj
p b/pro s=BAhJIhMzNzA0MTI
dAY6BkVG%0A)
r ducts sUHJvamVjdAY6BkVG
o /buy/ %0A)
j 8045
e 3?
c s=BA
t hJIhM
h zNzA
u 0MTIs
b UHJva
/ mVjd
p AY6B
r kVG%
o 0A)
d
u
c
t
s
/
b
u
y
/
8
0
4
5
3
?
s
s
=
B
A
h
JI
h
M
z
N
z
A
0
M
T
I
s
U
H
J
v
a
m
V
j
d
A
Y
6
B
k
V
G
%
0
A
)
Capacitor 4.7 nF
Depending on your RC Low pass filter and × 1
your selected cutoff frequency

Capacitor 470 µF
(/projecthub/products/buy/564
× 1 
90?
( (/proj (/projecthub/product
s=BAhJIhMzNzA0MTIsUHJvamVj
/ ecthu s/buy/56490?
dAY6BkVG%0A)
(/projecthub/pro p b/pro s=BAhJIhMzNzA0MTI
ducts/buy/5649 r ducts sUHJvamVjdAY6BkVG
0? o /buy/ %0A)
s=BAhJIhMzNzA0 j 5649
e 0?
MTIsUHJvamVjdA
Y6BkVG%0A) c s=BA
t hJIhM
h zNzA
u 0MTIs
b UHJva
/ mVjd
p AY6B
r kVG%
o 0A)
d
u
c
t
s
/
b
u
y
/
5
6
4
9
0
?
?
s
=
B
A
h
JI
h
M
z
N
z
A
0
M
T
I
s
U
H
J
v
a
m
V
j
d
A
Y
6
B
k
V
G
%
0
A
)
Resistor 2K
Depending on your RC Low pass filter and × 1
your selected cutoff frequency

APPS AND ONLINE SERVICES 

Arduino IDE 
(https://www.arduino.cc/en/main/ (https://www.arduino.cc/en/
(https://www.ar software) main/software)
duino.cc/en/mai
n/software)

ABOUT THIS PROJECT 

Introduction
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.
The visualizer in action

Construction

Connections
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.

Circuit without low pass filter

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]

The circuit with the low pass filter

Rough calculation of maximum sample rate


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

Estimating maximum sample rate


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 Interface


User Interface

The 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.

Frequency bands for our visualization

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?
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 module

Electret Microphone Amplifier Max9814

Electret 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
Checking Microphone Module reponse with Analog Devices ADALM1000

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 Pixels


This 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
(https://github.com/adafruit/Adafruit_SSD1306)and the adafruit_GFX.h
(https://github.com/adafruit/Adafruit-GFX-Library)libraries. Follow the next instructions
to install those libraries.
We are using Adafruit libraries. Remember you can buy something from Adafruit to
support them.

0.91 inch OLED I2C Display 128 x 32 Pixels

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.
CODE 

Sound Spectrum Visualizer for Arduino Nano 33 BLE Arduino


  (/PROJECTHUB/CODE_FILES/490110/DOWNLOAD)

Sound Spectrum Visualizer for Arduino Nano 33 BLE


uses arduinoFFT https://github.com/kosme/arduinoFFT
uses Adafruit_GFX https://github.com/adafruit/Adafruit-GFX-Library
uses Adafruit_SSD1306 https://github.com/adafruit/Adafruit_SSD1306

SCHEMATICS 

S DOWNLOAD (HTTPS://HACKSTERIO.S3.AMAZONAWS.COM/UPLOADS/ATTACHMENTS/1222234/SOUNDSPECTRUMV
c
h
e
m
a
t
i
c
s
f
r
i
t
z
i
n
g

 soundspectrumvisualizer_qLzRsVPVlc.fzz

S
c
h
e
m
a
t
i
c
s
f
r
i
t
z
i
n DOWNLOAD (HTTPS://HACKSTERIO.S3.AMAZONAWS.COM/UPLOADS/ATTACHMENTS/1222235/SOUNDSPECTRUMV
g
COMMENTS 

Please log in (/projecthub/users/sign_in?


id=370412&m=project&reason=comment&redirect_to=%2Fprojecthub%2Fjavagoza%2Fs
ound-spectrum-visualizer-with-arduino-nano-33-ble-3c6261%23comments) or sign up
(/projecthub/users/sign_up?
id=370412&m=project&reason=comment&redirect_to=%2Fprojecthub%2Fjavagoza%2Fs
ound-spectrum-visualizer-with-arduino-nano-33-ble-
3c6261%23comments&source=popup) to comment.

AUTHOR

(/projecthub/javagoza)
Enrique Albertos (/projecthub/javagoza)
4 PROJECTS 9 FOLLOWERS

FOLLOW (/PROJECTHUB/USERS/SIGN_UP?ID=476476&M=USER&REASON=FOLLOW&REDIRECT

PUBLISHED ON
November 22, 2020

 RESPECT PROJECT (/PROJECTHUB/USERS/SIGN_UP?ID=370412&M=ARTICLE&REASON=RESPECT&R...

 WRITE A COMMENT

 Share

MEMBERS WHO RESPECT THIS PROJECT

(/projecthub/dextergomes01) (/projecthub/skioppetto) (/projecthub/aula-jazmati)

(/projecthub/user53316570) (/projecthub/randombrein) (/projecthub/alf6)

(/projecthub/javagoza) (/projecthub/damiencatheline)
and 12 others

SEE SIMILAR PROJECTS


YOU MIGHT LIKE

SIMILAR PROJECTS YOU MIGHT LIKE

(/projecthub/BnBe_Club/mqtt-communication-with-the-nano-33-iot-wemos-d1-
boards-5f7f0e?ref=similar&ref_id=370412&offset=0)
MQTT Communication With the Nano 33 IoT & WeMos D1 Boards
(/projecthub/BnBe_Club/mqtt-communication-with-the-nano-33-
iot-wemos-d1-boards-5f7f0e?ref=similar&ref_id=370412&offset=0)
Project tutorial by BnBe Club (/projecthub/BnBe_Club)
9,826 VIEWS 2 COMMENTS 18 RESPECTS

(/projecthub/jingwen_zhu/getting-started-with-p5-ble-js-using-arduino-nano-33-ble-
120ea6?ref=similar&ref_id=370412&offset=1)
Getting Started with p5.ble.js Using Arduino Nano 33 BLE
(/projecthub/jingwen_zhu/getting-started-with-p5-ble-js-using-
arduino-nano-33-ble-120ea6?ref=similar&ref_id=370412&offset=1)
by jingwen_zhu (/projecthub/jingwen_zhu)
8,532 VIEWS 2 COMMENTS 21 RESPECTS

(/projecthub/liss/happy-birthday-melody-on-arduino-nano-with-3-way-polyphony-
c80c31?ref=similar&ref_id=370412&offset=2)

Happy Birthday Melody on Arduino Nano with 3-Way Polyphony


(/projecthub/liss/happy-birthday-melody-on-arduino-nano-with-3-
way-polyphony-c80c31?ref=similar&ref_id=370412&offset=2)
Project tutorial by Liss (/projecthub/liss)
19,023 VIEWS 8 COMMENTS 61 RESPECTS

(/projecthub/150129/spot-welder-controlled-with-an-arduino-nano-8e90dc?
ref=similar&ref_id=370412&offset=3)
Spot Welder Controlled with an Arduino Nano
(/projecthub/150129/spot-welder-controlled-with-an-arduino-
nano-8e90dc?ref=similar&ref_id=370412&offset=3)
Project tutorial by Michael Marinis (/projecthub/Michael_Marinis) and PCBWay (/proje...
11,880 VIEWS 10 COMMENTS 26 RESPECTS

(/projecthub/touchmysound/automatizing-percussion-with-solenoids-the-sound-
compass-ce30b5?ref=similar&ref_id=370412&offset=4)
Automatizing Percussion with Solenoids: "The Sound Compass"
(/projecthub/touchmysound/automatizing-percussion-with-
solenoids-the-sound-compass-ce30b5?
Project tutorial by touchmysound (/projecthub/touchmysound)
5,490 VIEWS 4 COMMENTS 14 RESPECTS

(/projecthub/guntassingh2005/sps30-with-nano-33-ble-sense-46ec49?
ref=similar&ref_id=370412&offset=5)

SPS30 with Nano 33 BLE Sense


(/projecthub/guntassingh2005/sps30-with-nano-33-ble-sense-
46ec49?ref=similar&ref_id=370412&offset=5)
Project tutorial by Guntas Singh (/projecthub/guntassingh2005)
1,133 VIEWS 1 COMMENT 0 RESPECTS
1,133 VIEWS 1 COMMENT 0 RESPECTS

(https://www.arduino.cc)
Powered by
(https://www.hackster.io)

You might also like