I've been working on an LED spectrum analyzer for a while now. Because I'm new to all of this I started with just a microphone and some LEDs, KISS, no problem. Very soon I was curious if I could get the LEDs to react to high and low sounds recorded by the microphone. The MSGEQ7 was the perfect solution but I've been at it for a few days now and can't seem to figure out what I'm doing wrong. I've made a breadboard drawing using Fritzing to show you what I've got right now.
My code (found it on the www somewhere) is the following:
int analogPin = 0;
int strobePin = 2;
int resetPin = 3;
int spectrumValue[7];
void setup()
{
Serial.begin(9600);
pinMode(analogPin, INPUT);
pinMode(strobePin, OUTPUT);
pinMode(resetPin, OUTPUT);
analogReference(DEFAULT);
digitalWrite(resetPin, LOW);
digitalWrite(strobePin, HIGH);
}
void loop()
{
digitalWrite(resetPin, HIGH);
digitalWrite(resetPin, LOW);
for (int i = 0; i < 7; i++)
{
digitalWrite(strobePin, LOW);
delayMicroseconds(30);
spectrumValue[i] = analogRead(analogPin);
if (spectrumValue[i] < 10)
{
Serial.print(" ");
Serial.print(spectrumValue[i]);
}
else if (spectrumValue[i] < 100 )
{
Serial.print(" ");
Serial.print(spectrumValue[i]);
}
else
{
Serial.print(" ");
Serial.print(spectrumValue[i]);
}
digitalWrite(strobePin, HIGH);
}
Serial.println();
}
The output in the serial monitor is just 0 0 0 0 0 0 0 all the time and sometimes steadily rises to 12 12 12 12 12 12 12 or a higher. I'm sure the microphone is still working and I'm also sure that the MSGEQ7 is working (I've bought 2 and both of them give the same results).
I know this is post number 1 but everyone has to start somewhere. I hope I'll be able to help other users out on this forum with their problems in the near future!
I am also a beginner when it comes to arduino. I was wondering if that sketch merely read the data coming off the msgeq7 chip or if it was trying to do something else too you just didn't have it hooked up in that picture.
dr_bigben:
I am also a beginner when it comes to arduino. I was wondering if that sketch merely read the data coming off the msgeq7 chip or if it was trying to do something else too you just didn't have it hooked up in that picture.
This sketch is only reading the data from the MSGEQ7 chip if I'm correct. It defines the pins I'm using and sets the pins in their required state (HIGH or LOW). The rest is just for printing out values and has a little built in noise filter.
An answer can only be as good as the question, and if you do feed false information into the question we don't stand a chance of a correct answer do we?
So the question remains as to how you have wired it up, we still don't know as the module you have used has 5 connectors and your diagram only 3. So apart from the power how is the rest of it wired up?
Test the microphone by putting it into another analogue input say A1, and printing out the results. You should see a value of about 246 with no sound, and with sound it will be random about that value up or down about 200, so that is between 200 and 446 or there about. If you do not see this then your wiring or microphone are stuffed.
Grumpy_Mike:
An answer can only be as good as the question, and if you do feed false information into the question we don't stand a chance of a correct answer do we?
So the question remains as to how you have wired it up, we still don't know as the module you have used has 5 connectors and your diagram only 3. So apart from the power how is the rest of it wired up?
Test the microphone by putting it into another analogue input say A1, and printing out the results. You should see a value of about 246 with no sound, and with sound it will be random about that value up or down about 200, so that is between 200 and 446 or there about. If you do not see this then your wiring or microphone are stuffed.
You're absolutely right Mike, I've updated the diagram in my first post. The microphone module with auto gain was not available in the Fritzing program, this is why I used the availably one with no auto gain and only 3 connectors (it is almost the same, I'm currently using the same 3 connectors, the other 2 are left untouched for now). I've tested the microphone as per your instructions and the output is indeed between 170 and 430 when I print the values so that part of the diagram definitely works (hooked it up to some LEDs as well and works like a charm).
Ok where did you get the schematic from for the chip? Those values look wrong on the caps. Can you post a photo of your wiring, not more than 1000 pixels wide.
Grumpy_Mike:
Ok where did you get the schematic from for the chip? Those values look wrong on the caps. Can you post a photo of your wiring, not more than 1000 pixels wide.
OK so you are new, the first rule of electronics is that instructables are crap - they are very poor and most of them do not work despite what the lying ba****ds giving feedback say. Never use anything on that site.
Just go with the schematic on that other link.
Now what is the thing on the right, it looks like an LED? This is why we need a schematic to see what you are actually doing rather than what you started from.
I can't see any audio input on pin 5, is it there?
It could be the angle but are you sure you are powering it from 5V and not the 3V3 next to it?
I also can't see the power going to pin 1 of the chip, it looks to be one out.
The LED is not connected to anything, I intended to get the MSGEQ7 chip up and running first. Everything is wired up according to the diagram from the first post (I've made that diagram myself based on my own wiring). No mistakes there I think... There is audio input on pin 5, it is powered from the 5V Arduino pin and there is power going to pin 1 of the MSGEQ7 chip. I'm starting to think I just have 2 faulty MSGEQ7 chips over here and a ton of bad luck. I've checked all the documentation and tutorials I can find on the internet, only to be sure that I got it right the first time. Even replaced all the components I was using to make sure they were not faulty. Still in love with Arduino though ...
There is audio input on pin 5, it is powered from the 5V Arduino pin
Do you mean that? The audio input should be from an iPad or some other audio source. The ground of the audio must be connected to the ground on the arduino and chip.
Connect the mic out lead in series with a 0.01uF ceramic cap to MSGEQ7 pin 5.
Pin 8 needs a 33pF cap directly to ground.
*It's hard to tell from your pic whats what and where.
Try this sketch and see what the serial monitor reads.
/* David Wang
* Code that takes audio input from a 3.5mm cable
* and flashes an LED strip based on the frequency
* of the music.
*
* HUGE thanks to the arduino community
* If you see your code here, I owe you my gratitude
*
*/
int analogPin = 0; // MSGEQ7 OUT
int strobePin = 2; // MSGEQ7 STROBE
int resetPin = 4; // MSGEQ7 RESET
int spectrumValue[7];
// MSGEQ7 OUT pin produces values around 50-80
// when there is no input, so use this value to
// filter out a lot of the chaff.
int filterValue = 180;
// LED pins connected to the PWM pins on the Arduino
int ledPinR = 9;
int ledPinG = 10;
int ledPinB = 11;
void setup()
{
//Serial.begin(9600);
// Read from MSGEQ7 OUT
pinMode(analogPin, INPUT);
// Write to MSGEQ7 STROBE and RESET
pinMode(strobePin, OUTPUT);
pinMode(resetPin, OUTPUT);
// Set analogPin's reference voltage
analogReference(DEFAULT); // 5V
// Set startup values for pins
digitalWrite(resetPin, LOW);
digitalWrite(strobePin, HIGH);
}
void loop()
{
// Set reset pin low to enable strobe
digitalWrite(resetPin, HIGH);
digitalWrite(resetPin, LOW);
// Get all 7 spectrum values from the MSGEQ7
for (int i = 0; i < 7; i++)
{
digitalWrite(strobePin, LOW);
delayMicroseconds(30); // Allow output to settle
spectrumValue[i] = analogRead(analogPin);
// Constrain any value above 1023 or below filterValue
spectrumValue[i] = constrain(spectrumValue[i], filterValue, 1023);
// Remap the value to a number between 0 and 255 if needed
// spectrumValue[i] = map(spectrumValue[i], filterValue, 1023, 0, 255);
Serial.print(spectrumValue[i]);
Serial.print(" ");
digitalWrite(strobePin, HIGH);
}
Serial.println();
}
I've recently been messing around with the MSGEQ7 chip and set it up in the same way as many of these other posts. I have had the issue that the serial port is outputting the same value for each frequency. Attached is a picture of the serial port. The only major difference I have noticed is that my audio in is from a stripped audio cord. The cord has a red, white, and black wires. I assumed that the red and white correspond to the audio in and the black is the ground wire. Anyone have any ideas of what I could change or what might be wrong?
I am having this same issue. I had it running on the breadboard after quite a bit of fiddling around and redoing the breadboard. Once I soldered this problem started and now that I've moved back to the breadboard it only works when I physically touch one end of the 33pf capacitor. Quite confused