MSGEQ7 Equalizer

11
Feb
2019

An MSGEQ7 IC splits an audio signal into the dc equivalent of its amplitude at 7 set frequencies. Here I'm using two MSGEQ7, one for the left channel and one for the right channel. In each channel, MSGEQ7 IC will output 7 dc signals and with respect to voltage equivalent to each frequency range, output will be there in the form of number of LEDs i.e. max output will correspond to all 8 LEDs of one column to light up and the lowest output in that frequency range will lead to one LED light up. Here is the image of my setup.

View this post on Instagram

It's finally ready. #MSGEQ7 #Arduino Spectrum Analyzer.

A post shared by Shekhar Suman (@shekhar_suman_1) on



Here is the code which I've used for the equalizer:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "FastLED.h"
#define NUM_LEDS 64
#define DATA_PIN 13 
#define CLOCK_PIN 8  
CRGB leds[NUM_LEDS];

//1
int strobePin  = 2;    // Strobe Pin on the MSGEQ7  2   4
int resetPin   = 3;    // Reset Pin on the MSGEQ7   3   5
int outPin     = A0;   // Output Pin on the MSGEQ7  A0  A1
int level[7];          // An array to hold the values from the 7 frequency bands

//2 
#define DATA_PIN2 12     
CRGB leds2[NUM_LEDS];

int strobePin2  = 4;    // Strobe Pin on the MSGEQ7
int resetPin2   = 5;    // Reset Pin on the MSGEQ7
int outPin2     = A1;   // Output Pin on the MSGEQ7
int level2[7];          // An array to hold the values from the 7 frequency bands

void setup() {
 
  Serial.begin (9600);
 
  // Define our pin modes
  pinMode      (strobePin, OUTPUT);
  pinMode      (resetPin,  OUTPUT);
  pinMode      (outPin,    INPUT);
  pinMode      (strobePin2, OUTPUT);
  pinMode      (resetPin2,  OUTPUT);
  pinMode      (outPin2,    INPUT);
 
  // Create an initial state for our pins
  digitalWrite (resetPin,  LOW);
  digitalWrite (strobePin, LOW);
  digitalWrite (resetPin2,  LOW);
  digitalWrite (strobePin2, LOW);
  delay        (1);
 
  // Reset the MSGEQ7 as per the datasheet timing diagram
  digitalWrite (resetPin,  HIGH);
  digitalWrite (resetPin2,  HIGH);
  delay        (1);
  digitalWrite (resetPin,  LOW);
  digitalWrite (strobePin, HIGH);
  digitalWrite (resetPin2,  LOW);
  digitalWrite (strobePin2, HIGH);
  delay        (1);

  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  FastLED.addLeds<NEOPIXEL, DATA_PIN2>(leds2, NUM_LEDS);
 }
 
 
void loop() {
  
  // Cycle through each frequency band by pulsing the strobe.ffdf2
  for (int i = 0; i < 7; i++) {
    digitalWrite       (strobePin, LOW);
    digitalWrite       (strobePin2, LOW);
    delayMicroseconds  (100);                    // Delay necessary due to timing diagram
    level[i] =         analogRead (outPin);
    level2[i] =        analogRead (outPin2);
    digitalWrite       (strobePin, HIGH);
    digitalWrite       (strobePin2, HIGH);
    delayMicroseconds  (100);                    // Delay necessary due to timing diagram  
  }
  int x1,x2;
  x1=0;
  x2=0;
  for (int i = 0; i < 7; i++) {
    Serial.print       (level[i]);
    Serial.print       ("   ");

    int num = map(level[i], 0, 1023, 0, 7);
    int num2 = map(level2[i], 0, 1023, 0, 7);
        for(int j=0;j<=num;j++) {
      if(j==0) leds[(i*8)+j]=CRGB::Violet;if(j==1) leds[(i*8)+j]=CRGB::Indigo;if(j==2) leds[(i*8)+j]=CRGB::Blue;if(j==3) leds[(i*8)+j]=CRGB::Green;if(j==4) leds[(i*8)+j]=CRGB::Yellow;if(j==5) leds[(i*8)+j]=CRGB::Orange;if(j==6) leds[(i*8)+j]=CRGB::Red;if(j==7) leds[(i*8)+j]=CRGB::Purple;
    }
    for(int j=0;j<=num2;j++) { 
      if(j==0) leds2[((7-i)*8)+j]=CRGB::Violet;if(j==1) leds2[((7-i)*8)+j]=CRGB::Indigo;if(j==2) leds2[((7-i)*8)+j]=CRGB::Blue;if(j==3) leds2[((7-i)*8)+j]=CRGB::Green;if(j==4) leds2[((7-i)*8)+j]=CRGB::Yellow;if(j==5) leds2[((7-i)*8)+j]=CRGB::Orange;if(j==6) leds2[((7-i)*8)+j]=CRGB::Red;if(j==7) leds2[((7-i)*8)+j]=CRGB::Purple;
    }
    x1=x1+num;
    x2=x2+num2;
  }
  FastLED.show();
  for(int m=0;m<NUM_LEDS;m++){
    leds[m]=CRGB::Black;
    leds2[m]=CRGB::Black;
  }
  delay(30);
  FastLED.show();
  Serial.println ();  
 
}

By administrator at 03:38:43 PM 0 Comment(s)

Comments

There are no comments yet. Be the first one to add a comment!

Add a Comment

Please enter the email address.Invalid format. (Won't be Displayed)
Notify me of followup comments
Enter the displayed Code: captcha