Tinkering Tuesday – Playmobil Stage – Audio Spectrum Analysis using Sound Sensor Module

In this post I will describe my results using a sound sensor board to analyze music to make a sound reactive light show. Based on my last post I will exchange the audio input from the Auduino with the analog readings of a cheap sound sensor board.

Past parts of this series:

Tinkering Tuesday – Playmobil Stage – Introduction (englische Einführung, restliche Parts sind nur auf Englisch verfügbar)

Tinkering Tuesday – Playmobil Stage – Playmobil parts

Tinkering Tuesday – Playmobil Stage – LED Stage Lights
Tinkering Tuesday – Playmobil Stage – Disco Ball with stepper motor
Tinkering Tuesday – Playmobil Stage – LED Rings

Tinkering Tuesday – Playmobil Stage – Audio Output from microSD with Arduino

Tinkering Tuesday – Playmobil Stage – Audio Spectrum Analysis from WAV input with simple logic, FHT and MSGEQ7

Sound Sensor Board Keyes KY-037

I ordered a sound sensor board from ebay, which seems to be the Keyes KY-037 (2,09 EUR for 3 pcs). More details can be found at https://tkkrlab.nl/wiki/Arduino_KY-037_Sensitive_microphone_sensor_module (there is also another version, the KY-038 which seems to be only differing in sensitivity, see https://tkkrlab.nl/wiki/Arduino_KY-038_Microphone_sound_sensor_module) and the power point presentation found at http://brd4.braude.ac.il/~ksamuel/ElIn.31361/Lectures/022-Basic%20Definitions%20and%20Concepts%20Sensors%20and%20Actiators%202013-10-10.pdf (slide 40 ff.).

The wiring is very simple. Just connect ground and 5V and depending whether you want to use digital or analog input the pin D0 and/or A0. In the following schematic you can see both:

Analog input

Using the example sketch from tkkrlab for the analog reading I got some reading in silence from the analog pin. That base reading can be adjusted by using the screw on the board. I adjusted it to around 100 for the first tests:

First I modified the sketch to not delay the reading based on the value so I had all the data.

int sensorPin = A1; // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor
void setup ()
Serial.begin (9600);
void loop ()
sensorValue = analogRead (sensorPin);
Serial.println (sensorValue, DEC);

I then played a song on my PC („Wecker“ from my band Monkey Fly: https://www.youtube.com/watch?v=3l2iKzLA9VY) and exported the readings to excel to draw a graph resulting in a wonderful waveform:

Here are the numbers:

You can see that the readings at 500 have a little wider span than those at 100, so I will go with this being in the middle of the value range for analog readings (0-1023). The adjustment around 750 is not bringing any more accuracy.

I also did a test with different volume levels (using the same song and the same speaker level I adjusted the volume via Windows to 50%, 75% and 100%:

The peaks are much lower but I think this will work for some sound reacting lights. I just have to dynamically adopt the thresholds to the minimum and maximum over some readings or implement a potentiometer to adjust the sensivity dynamically.

Digital input

Just for completeness I also tested the digital readings. Still having the screw to an analog level of around 750, I installed the following sketch reading the analogValue when a HIGH is recognized at the digital Input (yes, there is some delay but it has to be precise enough here). Playing my song back I got no feedback, even on the bass notes. Clapping gave analog readings around 500.

Bringing the analog readings back down to around 100 resulted in the digital input always being HIGH. I turned the screw until the reading got LOW at around 560 again.

Using the Basic input sketch from the audio input I also get similar readings so I could easily switch between both inputs:

-- base reading without sound
Time: 230 Min: 502 Max: 505 Avg: 503 Span: 3, 2, 1
Time: 229 Min: 502 Max: 505 Avg: 503 Span: 3, 2, 1
Time: 229 Min: 501 Max: 506 Avg: 503 Span: 5, 3, 2
Time: 230 Min: 501 Max: 506 Avg: 503 Span: 5, 3, 2

-- Intro of the song (silent part)
Time: 229 Min: 499 Max: 508 Avg: 503 Span: 9, 5, 4
Time: 229 Min: 501 Max: 506 Avg: 503 Span: 5, 3, 2
Time: 230 Min: 500 Max: 506 Avg: 503 Span: 6, 3, 3
Time: 229 Min: 499 Max: 506 Avg: 503 Span: 7, 3, 4
Time: 230 Min: 500 Max: 508 Avg: 503 Span: 8, 5, 3

-- Intro of the song (loud part)
Time: 229 Min: 461 Max: 531 Avg: 503 Span: 70, 28, 42
Time: 229 Min: 477 Max: 525 Avg: 503 Span: 48, 22, 26
Time: 230 Min: 476 Max: 524 Avg: 503 Span: 48, 21, 27
Time: 229 Min: 478 Max: 527 Avg: 503 Span: 49, 24, 25
Time: 230 Min: 486 Max: 521 Avg: 503 Span: 35, 18, 17


I think the analog input will work together with the results from my previous post on the audio analysis. The plan is to combine the sound sensor and the wav playback. So if there is no sound playing on the other Arduino I will read the sound sensor but for this I have to notify on playback. Let’s see how I will do this.

More to read

Sound Sensor Modul: http://linksprite.com/wiki/index.php5?title=Advanced_Sensors_Kit_for_Arduino (auch Laser)

Sound Sensor Modul: https://tkkrlab.nl/wiki/Arduino_KY-038_Microphone_sound_sensor_module (auch Laser https://tkkrlab.nl/wiki/Arduino_KY-008_Laser_sensor_module)

Sound Sensor Modul: http://brd4.braude.ac.il/~ksamuel/ElIn.31361/Lectures/022-Basic%20Definitions%20and%20Concepts%20Sensors%20and%20Actiators%202013-10-10.pdf

Spectrum analysis using electret microphone and LM386 amp: http://shin-ajaran.blogspot.de/2014/11/arduino-spectrum-analyzer-for-music-to.html

Schreib einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *