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. Just getting 1’s and 2’s on the serial monitor (meaning no input at all, right?). I’m winding how easy it is to blow the chip, I may have wired it incorrectly at first. Or it just might be a bad chip from eBay. Can I apply a test voltage somewhere to troubleshoot?

    • Personally, I would spend very little time debugging a part from eBay. They are often b-runs, counterfeits, or parts that didn’t pass test. Not worth saving a few dollars in my opinion.

      That said, it is relatively easily to blow the inputs.

      • Thanks a lot for the help. I’ll order another chip from a more reputable source and be sure to get the wiring right the first time.

  2. I got the spectrum analyzer working, and I want to have the data from it control an LED RGB individually addressable strip light. But, when I plug in the LED strip lights, they create “noise” that causes inaccurate readings on the spectrum analyzer (not sure if the mic or the spectrum analyzer are picking up the noise). If I switch the LED strip lights to a different power supply, it clears up. But, ideally I’d like to power the LEDs off the same power supply, coming from the arduino, too. Any ideas how to clean up the power to filter out the noise from the LEDs?

    Thanks for a great instructional!

  3. Hi there, I got your code via Liz Clark’s blog and built the kit in the video by mounting the LEDs in acrylic / plexiglass blocks. Am pleased with the result. Kind regards Robert

  4. Hi,
    I have a problem with the msgeq7, that i get minimal peaks at the first reading if i use reset and all 7 frequencys. full description here: http://forum.arduino.cc/index.php?topic=217362.0
    Its very complicated. all i need is your help, to just run my program (correct pins maybe), play some music and post the whole serial output after one minute (it might be very long, use pastebin). so i can see if my chip is broken or the chip in general has some issues. please also post your wiring, cause everyone is using a different wiring. and if you know where you bought it, it would be also nice to know where. This is my wiring (pic is not mine, and I have a 22k resistor between condenser and audio in)
    http://nuewire.com/wp-content/uploads/2011/07/schem1-450×600.png
    download programm (you dont need to understand, just change pins maybe and start)
    https://mega.co.nz/#!CFpwxTjK!Qwqflh_gNaLdow1pivCvMxDUeCoSjkJcniKpobPMwHc

    message me via [email protected] so I am notified that you posted something. Or just directly email me your results. The email is not a fake, I will receive it 😉
    thanks for your help!

  5. The first 2 lights flicker constantly, the rest light up when I snap my fingers close to the mic, or put loud music near the speaker.

    Close up images of the setup are here if you could spot any errors in the wiring:

    http://imgur.com/M7txNfj
    http://imgur.com/iGWy0Hd

    And the code I have been using is identical except for:

    #define msg7RESET 13
    #define msg7Strobe 12
    #define msg7DCout 0
    const int LEDpins[7] = {3,3,5,5,6,9,10};

    ...and...

    PWMvalue = PWMvalue / 30;

      • I have the same electret microphone you are using. You are going to need a feed the output of the microphone into a voltage divider or through a resistor before feeding it to the input of the MSGEQ7. The MSGEQ7’s input can only take a max of 100 mVpp = .1V “Peak to “Peak” or 100mv. The microphone can output up to VCC/2 which is somewhere between 200mVpp-5v.

  6. Hi James.

    I have followed this guide and added an electret microphone to detect audio isntead of the 3.5mm jack. Unfortunately some of the LED’s remain on when no audio is being directed at the microphone, see here: http://imgur.com/v3RYBP6

    Could you offer any advice on why this may be happening?

    Cheers!

    • Without an oscilloscope it will be tough to tell. However, it could just be noise the microphone is picking up or the on-board amplifier (usually just an op-amp) is introducing. Are the lights solid or do they appear to flicker at all?

  7. Great tutorial James, I just finished my project today, had to modify PWMvalue = PWMvalue / 2; to PWMvalue = PWMvalue / 35…. the leds remained on ( dimmed ), don’t know if I did right, I’m not savy with C++

    Any idea how can I control each channel’s intensity?

    Cheers,

    Peter

    • Peter, why did you need to modify the PWMvalue? Or what effect were you trying to achieve?

      As for controlling each channel’s intensity, that is how the code works now. So I’m not sure what you mean. In the for() loop, each channel of the MSQ is measured then the corresponding LED is set. You could also set those LEDs outside of the for() loop, but it makes the code unnecessarily complicated.

  8. Hi, I have purchased the bliptronics Arduino spectrum shield. Connecting it with the Arduino UNO i am getting some noise on the LED’s and the response in not as accurate. The LED’s remain switched on and flicker with audio levels quite less.

    With the shield i have connected strobe on D4, reset on D5, and output on A0.
    Im not able to figure out how to get the same response as shown in your video. It would be much appreciated if you could help out..

  9. hi
    is very nice, I want to do it, but I do not understand the schematic

    can you send me the complete schematic of the progect??

    thank you

    macca96