Pages: [1]   Go Down
Author Topic: Automatic Gain Control for LED VU meter for Bass and treble  (Read 932 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Guys,

I have been trying to get a VU meter up and running that is fed with analog inputs from low and high pass filters to make it respond to bass and treble. So far, I have this code:

int bassPins[] = { 3, 4, 5}; // Assign the pins for the leds
int treblePins[] = {6, 7, 8};
int bassInput = A1;  // left channel input
int trebleInput = A2;
int bass, treble, i;
 
void setup() {
  for (i = 0; i < 3; i++) { // Tell the arduino that the leds are digital outputs
    pinMode(bassPins, OUTPUT);
      pinMode(treblePins, OUTPUT);
    }
  Serial.begin(9600); // Uncomment to enable troubleshooting over serial.
  }
 
void loop() {
  //read in voltages
  bass = analogRead(bassInput);
  treble = analogRead(trebleInput);
  String b = "bass: ";
  String bout = "";
  bout = b + bass;
  String tout = "";
  String t = "treble: ";
  tout = t + treble;
   
  Serial.print(bout);
  Serial.print("\t");
  Serial.println(tout);
 
  bass = bass / 80;    // adjusts the sensitivity
  treble = treble/200;
 
  //bass
  if (bass == 0) { // if the volume is 0 then turn off all leds
    for(i = 0; i < 3; i++) {
      digitalWrite(bassPins, LOW);
      }
  }
  else {
    for (i = 0; i < bass; i++) { // turn on the leds up to the volume level
       digitalWrite(bassPins, HIGH);
      }
     
      for(i = i; i < 3; i++) {  // turn off the leds above the voltage level
        digitalWrite(bassPins, LOW);
       }
    }
   
  //treble
  if (treble == 0) { // if the volume is 0 then turn off all leds
    for(i = 0; i < 3; i++) {
      digitalWrite(treblePins, LOW);
    }
  }
  else {
    for (i = 0; i < treble; i++) {// turn on the leds up to the volume level
       digitalWrite(treblePins, HIGH);
      }
      for(i = i; i < 3; i++)  {// turn off the leds above the voltage level
        digitalWrite(treblePins, LOW);
       }
    }
  }


However, I am running into some problems:
1) whenever the song ends or if I stop the song, all the LEDs are HIGH. I could not figure our why this will be the case. My code contains a part which is supposed to turn them off. Any suggestions

2) The erratic nature of the bargraph is unpleasant. Some people have recommended to go for a Automatic Gain Control, which I have searched in the internet but found ALL hardware stuff. Can anyone help me with that?

I want the calibration to be dynamic, instead of hardcoding the sensitivity.

Also, the bargraph should respond smoothly (some kind of running average).

And if someone can kindly explain what the AGC does --to the best of my limited understanding, it will help me to calibrate the sensitivity dynamically, but will it also help me get a smooth bargraph?

Thanks everyone, a quick response will really help. Kinda running against the clock.

EP
Logged

Pages: [1]   Go Up
Jump to: