Here is my code for my Arduino Color Organ:
int analogPin = 0; // MSGEQ7 OUT
int strobePin = 4; // MSGEQ7 STROBE
int resetPin = 7; // MSGEQ7 RESET
int spectrumValue[7];
int EQvalue[7] = {70, 70, -50, 20, 20, 0, 0};
// 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 = 110;
// LED pins. I used 2 common cathode RGB LEDs.
// They're connected to the PWM pins on the Arduino
int BlueLED = 3;
int GreenLowLED = 5;
int GreenHighLED = 6;
int YellowLowLED = 9;
int YellowHighLED = 10;
int RedLED = 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(40); // Allow output to settle
spectrumValue[i] = analogRead(analogPin);
if (spectrumValue[i] > filterValue)
spectrumValue[i] += EQvalue[i];
// 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
spectrumValue[i] = map(spectrumValue[i], filterValue, 1023, 0, 255);
digitalWrite(strobePin, HIGH);
}
// Write the PWM values to the LEDs
analogWrite(BlueLED, spectrumValue[0]); // 63Hz
analogWrite(GreenLowLED, spectrumValue[1]); // 160Hz
analogWrite(GreenHighLED, spectrumValue[2]); // 400Hz
analogWrite(YellowLowLED, spectrumValue[3]); // 1000Hz
analogWrite(YellowHighLED, spectrumValue[4]); // 2500Hz
analogWrite(RedLED, spectrumValue[5]); // 6250Hz
}
In conclusion, this has been a fun project. Add the fact that it is in a local coffee shop that allows local bands come in and play shows, allows a lot of people to enjoy the color organ. If you are ever in Mansfield Ohio and hear about a show playing at Relax Its Just Coffee, be sure to go. Not only will you hear good bands from the Mansfield area, but you will most likely be able to see the Color Organ in action.
This article was originally posted on www.mikestechblog.com Any reproduction on any other site is prohibited and a violation of copyright laws.
Rainier says
Thanks!!
Mike says
Welcome!