MSGEQ7 Simple Spectrum Analyzer

Abstract

Mixed Signal Integration has a cool little chip that has 7 built-in bandpass filters. Run an audio signal through it and you have an instant audio spectrum analyzer! This is a simple spectrum analyzer based on an Arduino. Each of the 5 LEDs represent a single section of the chip’s 7 sections of audio spectrum.

MSGEQ7 on Adafruit Protoboard

Final Assembly

Electronics

If you want to replicate this setup, here is the hardware you’ll need to get.

Parts list:

  • (1) – MSGEQ7 (Sparkfun)
  • (5) –  LEDs
  • (5) – 470Ω Resistors
  • (1) – 180kΩ Resistor
  • (1) – 22kΩ Resistor
  • (1) – 33pF Capacitor (Ceramic)
  • (1) – 0.01µF Capacitor (Ceramic)
  • (2) – 0.1µF Capacitors (Ceramic)
  • (1) – Pushbutton
  • (1) – Stripped Audio Cable
  • Header Pins
  • Jumper Wires
  • Adafruit Perma-Prototype Board (or Breadboard)

Schematic:

MSGEQ7 Schematic

The application example from the MSGEQ7 Datasheet provides the circuit necessary.  The 200k and 33pF are probably the most critical components.  200k is not a E24-value, so I used 180K.   The 33pF shouldn’t be an issue to find.  470 ohms were picked to keep the amount of current flowing through the Arduino I/O pins low.

Firmware

Since there are only 5 LEDs, I decided to make each frequency band adjust the brightness via PWM.  The more energy at each a particular band will result in brighter LEDs.  The code was complied in Eclipse with Arduino-0023 Core on an Uno with a ATmega328.

Code is also available from Pastebin:  MSGEQ7 Simple Spectrum Analyzer

#define msg7RESET 11
#define msg7Strobe 12
#define msg7DCout 0
const int LEDpins[7] = {3,5,5,6,9,9,10};	// there are 5 LEDs and 7 freq bands. So, repeat LEDs

#define pushButton 2

void setup() {
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
  for (int x=0; x<7; x++) {
	  pinMode(LEDpins[x], OUTPUT);
  }
  pinMode(msg7RESET, OUTPUT);
  pinMode(msg7Strobe, OUTPUT);

  pinMode(pushButton, INPUT);		// never actually used in this example.
  digitalWrite(pushButton, HIGH);  // Enable internal pull-up
}

void loop() {
	digitalWrite(msg7RESET, HIGH);			// reset the MSGEQ7's counter
	delay(5);
	digitalWrite(msg7RESET, LOW);

	for (int x = 0; x < 7; x++){
		digitalWrite(msg7Strobe, LOW);		// output each DC value for each freq band
		delayMicroseconds(35); // to allow the output to settle
		int spectrumRead = analogRead(msg7DCout);

		int PWMvalue = map(spectrumRead, 0, 1024, 0, 255);  // scale analogRead's value to Write's 255 max
		if (PWMvalue < 50)
			PWMvalue = PWMvalue / 2;		// bit of a noise filter, so the LEDs turn off at low levels

		analogWrite(LEDpins[x], PWMvalue);
		digitalWrite(msg7Strobe, HIGH);
	}
}

Demonstration

YouTube Video showing the light’s action along with some music.  The music was created using GarageBand’s magic instruments.  I liked the groove and how well the lights responded to it.  Enjoy!

Project by AntiPuppet:

Long comments, URLs, and code tend to get flagged for spam moderation. No need to resubmit.

ALL comments submitted with fake or throw-away services are deleted, regardless of content.

Don't be a dweeb.

Leave a comment

70 thoughts on “MSGEQ7 Simple Spectrum Analyzer

  1. Hi,
    Thank tou for the great post.

    I’m using a very simliar script to read audio from the same chip but the problem is that every time I turn the system onthe frequencies are not always in the same array index, sometimes the lowest bass is on spectrumValue[5] sometimes in spectrumValue[3] and so on so i can’t get it to look right.

    Any toughts?

  2. Hi James, looking to use something similar in a project I’m doing, would this code be easily adapted to create a spectrum analyser that is more of a 5 x 5 LED configuration rather than the 5 single LEDs. Looking to hook this up to my other ongoing project that is a MIDI controller for reaper which will be used to control the EQ in reaper and then use this spectrum analyser as a display. Do you think this is possible, which i presume it is, and the ease of this project?

    • Also, i currently have 7 different colour LEDs, so i pressure i could use the chip to its full capacity and split into 7 bands too?

    • 1 LED per band is relatively easy. To have multiple lights per band would take a bit of effort. Either each LED would need its own I/O pin or you would need shift registers. Then you run into issues with how to power that many LEDs at once. Even with a 2560 AVR board, which has plenty of I/O pins, you could only turn on 20 or so LEDs at once. (AVRs are limited to something like 200mA total.) Shift registers add a bit of delay which can be an issue since there is already a slight delay getting the reading from the MSGEQ7.

      So is it possible? Yes. Is it going to be the best spectrum analyzer? No.

      If I were approaching this project, I would use a shift register on each band. And hope it is fast enough.

      • Thanks, i have seen some examples online of DIY LED Matrix, where the pins of the LEDs are overlapped, just wondering if you’ve ever come across this and whether that would be able to be incorporated into your idea…

          • Cant seem to get my head around how i would implement this into an LED matrix, should it work the same way, or will i have to send the data of the 7 frequency bands from the chip to the leds in a different way, the more research i do the more conflicting argument i seem to read. My extent of arduino up to this point goes as far as simple DMX and MIDI controllers, so some of posts i read in forums can go straight over my head, but I’m really wanting to do this project even if the spectrum analyser turns out to just be a fun added graphic as it won’t be the most accurate, but i feel like completing this project will help my understanding and ability of using arduino.

    • Determine an “on” and “off” value of the analogRead, for each band. If the value is lower, use digitalWrite() to turn the replay off. If higher, turn it on. You’ll need a driver, like a transistor,to drive the relay. Also, relays are SSSLLLOOOWWWW, but you find that out when you do some testing.

      • Thanks! What would be an alternative for use with incandescent bulbs? I’m trying to create a vintage style color organ with modern safer components, but love the look of the halogen bulbs as opposed to LED’s. Any tips?

        • I don’t know what you mean by “alternative.” Relays are relays. There are solid state relays, which are like transistor switches for AC. And there are electromechanical relays, which are slow.

  3. Just a note on bad chips – I bought 10 MSGEQ7s on ebay. The first two I used were fine so I assumed I had a good batch. But having spent hours wondering what was wrong on the next project I then swapped a few around and discovered that only 4 out of the 10 worked. The others ranged from nothing at all to random flickering.

  4. Hi Sir,

    I do my project atmega 32a microcontroller at atmel studio but i want sound frequency meter circuit and coding. because this is in ardino how to convert ateml?
    please, help me!

  5. Hi James,

    I have the same question as 1 guy before me, which you didn’t respond to. I built the same circuit as you did, but i hooked a rgb led strip to it (red green and blue with 1 mosfet each). The led strip is running at 12V, so I decided to take an Arduino Nano which can handle this voltage. The problem i have is: when i use the 12V power supply for the leds and the arduino, i get a very strange noise (every color is blinking at about the same frequency). This, however, doesn’t happen when i use the normal usb cable of the arduino. Any Ideas?

    Thanks =)

  6. Hi James,

    Thanks for your wonderful write-up. This has been instrumental for helping me figure out this chip. I’m using the arduino outputs to switch 7 LED strips through a Darlington Transistor. It all seems to be working fine, but I have one issue. Three of the channels are constantly on, even when I grounded the input. I’m splitting off the audio signal from an audio signal. I believe it’s the 160Hz, 1kHz, and 2.5kHz channels that are always on. The color will change with the audio signal, but it does not have as high of a range (since there is a constant DC background). Have you experienced anything like this? Thanks so much for your help!

    • If grounding the input doesn’t cause the channels to go back to (or near) 0, then it suggests there’s a problem with the chip.

      Inside of the chip are a bunch of filter networks. It is possible they were damaged. Have you been able to try a different chip?

  7. Hi, I have collected , but does not work. LEDs are simply shone . Sometimes it does not shine . What could it be ? thank you

  8. Looks like a cool little project that is explained very well. I would like to try this but with an electret microphone, rather than audio in. I’m very new to micro electronics so just wanted to ask if this would make any difference. i.e. would the 22K resister still be needed before the 0.01uf capacitor? Thanks in advance.