Project tutorial
Dancing Fountain: Arduino with MSGEQ7 Spectrum Analyzer

Dancing Fountain: Arduino with MSGEQ7 Spectrum Analyzer © CC BY-NC

Using the Arduino to control 3 modes of Spectrum Analyzing Technique with the MSGEQ7.

  • 61 views
  • 0 comments
  • 0 respects

Components and supplies

Necessary tools and machines

Apps and online services

About this project

Introduction:

The reception of an audio signal and converting it into visual or mechanical reaction is very interesting. In this project we shall use an Arduino Mega to be connected to a spectrum analyzer MSGEQ7 that takes the input audio signal and perform band pass filtering on it to divide it into 7 main frequency bands. The Arduino will then analyze the analogue signal of each frequency band and creates an action.

Objectives:

This project will discuss 3 modes of operation:

  • LEDs are connected to PWM digital pins to react to the frequency bands
  • LEDs are connected to digital pins to react to the frequency bands
  • Pumps are connected to the Arduino Mega through Motor drivers and react to the frequency bands

Theory:

if we talk about the MSGEQ7 Spectrum Analyzer IC we can say that it has internal 7 band pass filters that divides the input audio signal into 7 main bands: 63 Hz, 160 Hz, 400 Hz, 1 kHz, 2.5 kHz, 6.25 kHz and 16 kHz.

The output of each filter is chosen to be the output of the IC by using a multiplexer. That multiplexer has selectors lines controlled by an internal binary counter. So we can say that the counter should count from 0 to 6 (000 to 110) to allow one band to pass at a time. That makes it clear that the code of the Arduino should be able to reset the counter once it reaches the count 7.

If we have a look on the circuit diagram of the MSGEQ7 we can see that we use RC frequency tuner to control the internal clock of the oscillator. then we use filtering RC elements at the input audio signal port.

Procedures:

According to the source page (https://www.baldengineer.com/msgeq7-simple-spectrum-analyzer.html) we can see that the source code deals with the outputs as PWM signals that is repetitive. we can change some of the code lines to suite our goals.

First we connect the MSGEQ7 IC on a mini breadboard as per the following schematic:

We can notice that if we have a stereo jack, we can double the input resistor and capacitor to the second channel.

We power the MSGEQ7 from the Arduino VCC (5 volts) and GND. We shall connect the MSGEQ7 to the Arduino board. I prefer to use the Arduino Mega as it has PWM pins suitable for the project. The output of the MSGEQ7 IC is connected to analogue pin A0, the STROBE is connected to pin 2 of the Arduino Mega and the RESET is connected to pin 3.

Modes of operation:

LEDs as PWM digital outputs: according to the source code, we can connect the output LEDs to pins 4 thru 10

constintLED_pins[7] ={4,5,6,7,8,9,10};

Then we can notice the LEDs dances upon the strength of each frequency band.

The suggested code shall be as follows:

#define msg7RESET 3
#define msg7Strobe 2
#define msg7DCout 0
const int LEDpins[7] = {4,5,6,7,8,9,10};
void setup()
{
for (int x=0; x<7; x++)
{
pinMode(LEDpins[x], OUTPUT);
}
pinMode(msg7RESET, OUTPUT);
pinMode(msg7Strobe, OUTPUT);
}
void
{
digitalWrite(msg7RESET, HIGH);
delay(5);
digitalWrite(msg7RESET, LOW);
for (int x = 0 ; x < 7 ; x++)
{
digitalWrite(msg7Strobe, LOW);
delayMicroseconds(35);
int spectrumRead = analogRead(msg7DCout);
int PWMvalue = map(spectrumRead, 0, 1024, 0, 255);
if (PWMvalue < 50)
PWMvalue = PWMvalue / 2;
analogWrite(LEDpins[x], PWMvalue);
digitalWrite(msg7Strobe, HIGH);
}
}

LEDs as digital outputs:

We can connect the output LEDs to any digital pins.

constintLED_pins[7] ={40,42,44,46,48,50,52};

Then we can notice the LEDs flashes upon the strength of each frequency band.

The following video shows the results of the conenctions:

LEDs as digital output video

The suggested code shall be as follows:

#define msg7RESET 3
#define msg7Strobe 2
#define msg7DCout 0
const int LEDpins[7] = {40,42,44,46,48,50,52};
void setup()
{
for (int x=0; x<7; x++)
{
pinMode(LEDpins[x], OUTPUT);
}
pinMode(msg7RESET, OUTPUT);
pinMode(msg7Strobe, OUTPUT);
}
void
{
digitalWrite(msg7RESET, HIGH);
delay(5);
digitalWrite(msg7RESET, LOW);
for (int x = 0 ; x < 7 ; x++)
{
digitalWrite(msg7Strobe, LOW);
delayMicroseconds(35);
int spectrumRead = analogRead(msg7DCout);
int PWMvalue = map(spectrumRead, 0, 1024, 0, 255);
if (PWMvalue < 50)
PWMvalue = PWMvalue / 2;
analogWrite(LEDpins[x], PWMvalue);
digitalWrite(msg7Strobe, HIGH);
}
}

Pumps as Digital outputs:

in this last mode we shall connect L298N motor driver module to the outputs of the Arduino. this enables us to control the operation of the pump based on the output of the MSGEQ7 spectrum analyzer.

As known, the motor drivers enable us to control the operation of the connected motors or pumps based on the generated signal from the Arduino without sinking any current from the Arduino, instead they power the motors directly from the connected power source. Then we can connect the motor drivers to the Arduino as follows:

if we run the code as raw source, the pumps may not operate properly. That is because the PWM signal is low and will not be suitable for the motor driver to run the motors or pumps and deliver a suitable current. That is why I recommend to increase the PWM value by multiplying the analogue readings from A0 with factor larger than 1.3. This helps the mapping to be suitable for the motor driver. I recommend 1.4 to 1.6. Also we can remap the PWM to be 50 to 255 in order to be sure that the PWM value will be suitable.

The suggested code shall be as follows:

#define msg7RESET 3
#define msg7Strobe 2
#define msg7DCout 0
const int LEDpins[7] = {40,42,44,46,48,50,52};
const int Pumppins[7] = {4,5,6,7,8,9,10};
void setup()
{
for (int x=0; x<7; x++)
{
pinMode(LEDpins[x], OUTPUT);
}
pinMode(msg7RESET, OUTPUT);
pinMode(msg7Strobe, OUTPUT);
}
void
{
digitalWrite(msg7RESET, HIGH);
delay(5);
digitalWrite(msg7RESET, LOW);
for (int x = 0 ; x < 7 ; x++)
{
digitalWrite(msg7Strobe, LOW);
delayMicroseconds(35);
int spectrumRead = analogRead(msg7DCout*1.45);
if (spectrumRead >= 1023)
{
spectrumRead = 1023;  
}
int PWMvalue = map(spectrumRead, 0, 1024, 50, 255);
if (PWMvalue < 75)
PWMvalue = PWMvalue / 2;
analogWrite(Pumppins[x], PWMvalue);
analogWrite(LEDpins[x], PWMvalue);
digitalWrite(msg7Strobe, HIGH);
}
}

We can connect the LEDs together with the outputs for the motor drivers, but the LEDs will not flash in a good visible way like before as the PWM values have been increased. So I suggest to keep them connected to the digital pins 40 thru 52.

Code

Source Raw CodeC/C++
This code is a raw code used to test the functionality of the MSGEQ7 IC
#define msg7RESET 3
#define msg7Strobe 2
#define msg7DCout 0

const int LEDpins[7] = {4,5,6,7,8,9,10};

void setup() {

for (int x=0; x<7; x++)
{
pinMode(LEDpins[x], OUTPUT);
}
pinMode(msg7RESET, OUTPUT);
pinMode(msg7Strobe, OUTPUT);
}

void loop()
{
digitalWrite(msg7RESET, HIGH);
delay(5);
digitalWrite(msg7RESET, LOW);

for (int x = 0; x < 7; x++)
{
digitalWrite(msg7Strobe, LOW);
delayMicroseconds(35);
int spectrumRead = analogRead(msg7DCout);

int PWMvalue = map(spectrumRead, 0, 1024, 0, 255);
if (PWMvalue < 50)
PWMvalue = PWMvalue / 2;
analogWrite(LEDpins[x], PWMvalue);
digitalWrite(msg7Strobe, HIGH);
}
}

Custom parts and enclosures

Schematic connection for the MSGEQ7
The main connection for the MSGEQ7 before connecting it to the Arduino.
Msgeq7 schematic diagram l4egbipekk

Schematics

LED as digital outputs
In this connection, we can get the outputs as digital signals. The LEDs flash upon the strength of the input frequencies' power.
Spectrum analyzer with digital leds zheqvviefz
LEDs as PWM outputs
In this connection, we can get the outputs as PWM digital signals. The LEDs fade and shine upon the strength of the input frequencies' power.
Spectrum analyzer with pwm leds oqqxfjxgvi
Pumps as digital outputs
In this connection, we can get the output as digital signals. The pumps runs and the LEDs flash upon the strength of the input frequencies' power.
Spectrum analyzer with pumps nr2ajrqmzt

Comments

Similar projects you might like

32-Band Audio Spectrum Visualizer Analyzer

Project showcase by Shajeeb

  • 48,542 views
  • 93 comments
  • 173 respects

Spectrum Analyzer Using Winamp and Arduino Uno

Project showcase by raul

  • 9,350 views
  • 3 comments
  • 27 respects

Spectrum Analyzer with RGB LEDs

Project showcase by HeinzKetschup

  • 8,847 views
  • 3 comments
  • 39 respects

RGB Backlight + MSGEQ7 Audio Visualizer

Project tutorial by PhilKey

  • 9,565 views
  • 5 comments
  • 21 respects

Digital Wall Clock

Project tutorial by Deep_Sky

  • 8,059 views
  • 5 comments
  • 23 respects

Rings of Saturn LED Music Visualizing Pendant Light

Project tutorial by Modustrial Maker

  • 6,839 views
  • 2 comments
  • 37 respects
Add projectSign up / Login