Show Posts
Pages: [1] 2
1  Using Arduino / LEDs and Multiplexing / Re: DC bias issues with LED cube ANALOG INPUT on: April 07, 2012, 04:10:36 pm
P.S. I also tried subtracting the CONSTANT amount from the readings, but the problem is: it is a NEW constant value every time!!! So that doesn't work
2  Using Arduino / LEDs and Multiplexing / DC bias issues with LM386 and LED cube ANALOG INPUT on: April 07, 2012, 04:09:05 pm
Hi Guys,

I am trying to make a LED cube that responds to bass, mid, and treble freqs. I am using 3 filters for my audio and feed them into 3 analog inputs of the arduino. As an amplifier, I am using a LM386 http://www.ti.com/lit/ds/symlink/lm386.pdf

The problem is (see schematic attached):

If there is no signal present, even then my analog input reads a steady value of around 512-1023 (seen in the serial monitor). It turns out that the value corresponds to the V+ supply to the LM386 and is half of V+, ie, just like the LM386 outputs a signal in the middle of the range 0-V+, it even does it for if there is no AC signal present. As a result of this, ALL my LEDs are on at all times, for the A0 reads off the value and it is well over the threshold for just the signals.

To avoid the problem, I introduced a capacitor ( C_ac_coup ) of around 100uF to act as a AC coupling device, but sadly it does not work. I could not figure out why.

Moreover, whenever I try to connect the GND of the arduino to the GND of my function generator (connected to wall outlet), my computer disconnects the arduino from the USB port. Does anyone know why?

I tried to correct the problem using mods in the code, but failed to.

Here is the code (it just does it for the bass at the moment):

int led[6] = { 3, 4, 5}; // Assign the pins for the leds
int leftChannel = A0;  // left channel input
int left, i,left1;

void setup()
{
for (i = 0; i < 3; i++)  // Tell the arduino that the leds are digital outputs
  pinMode(led, OUTPUT);
Serial.begin(9600); // Uncomment to enable troubleshooting over serial.
}

void loop()
{
left= analogRead(leftChannel)-200;

Serial.println(left);
Serial.print("\t");// uncomment to check the raw input.
left = left / 200;    // adjusts the sensitivity  
Serial.println(left);
Serial.print("\t");// uncomment to check the modified input.
// left = 1500;  // uncomment to test all leds light.
// left = 0;    // uncomment to check the leds are not lit when the input is 0.

  if (left == 0)  // if the volume is 0 then turn off all leds
   {
   for(i = 0; i < 3; i++)
     {
     digitalWrite(led, LOW);
     }
  }
  
  else
  {
   for (i = 0; i < left; i++) // turn on the leds up to the volume level
    {
     digitalWrite(led, HIGH);
    }
    
    for(i = left; i < 3; i++)  // turn off the leds above the voltage level
     {
      digitalWrite(led, LOW);
     }
  }
}


All I am trying to do with the code is to turn of a series of 3 columns of led depending on the strength of the signal (think of it as a volume meter of bass, etc. for each column).

Can anyone make it modifications to this code and/ or the HARDWARE to

a) take care of the DC bias

b) use a better calibration technique whereby I don't have to cardcode a calibration factor into it.

Really messed up now, guys. So any help will be appreciated.
3  Using Arduino / LEDs and Multiplexing / Automatic Gain Control for LED VU meter for Bass and treble on: April 06, 2012, 10:00:52 am
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
4  Using Arduino / LEDs and Multiplexing / Re: Calibrating a VU meter using a pot/ dynamic calibration on: April 05, 2012, 11:49:47 pm
any help guys??? smiley-sad
5  Using Arduino / LEDs and Multiplexing / Re: Calibrating a VU meter using a pot/ dynamic calibration on: April 04, 2012, 10:39:50 pm
Hey Guys,

So When I am running the following program:

 
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);
       }
    }
  }

Even when there is nothing connected to A1 and A2, the serial monitor reads 1021 or 1023. Why? Is there a way to stop it?

Moreover, 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.
6  Using Arduino / LEDs and Multiplexing / Re: Calibrating a VU meter using a pot/ dynamic calibration on: March 31, 2012, 02:39:02 pm
Awesome. Fixed that part. Now I am facing a power issue. I have a few op amps that amplify my signal; however, I am just running of a +12V DC supply! How can I get the -V that is need for my opamp to work? Any ideas apart from going through a virtual ground, which is too complicated for me to understand atm?
7  Using Arduino / LEDs and Multiplexing / Re: Calibrating a VU meter using a pot/ dynamic calibration on: March 29, 2012, 11:24:00 pm
I have a quick question:

When I am sampling the audio, does it need to come from a MONO audio jack, or can I get it from a stereo? If I am to get it from a stereo do I need 2 audio inputs, aka 2 analog inputs? I don't want to go for that. However, I have a female audio jack that is stereo. Will it matter if I put in a mono male jack in it?

I am really confused.
8  Using Arduino / LEDs and Multiplexing / Re: Calibrating a VU meter using a pot/ dynamic calibration on: March 28, 2012, 12:38:24 am
you rock magician! thanks a ton. will do it tomorrow. too sleepy now!
9  Using Arduino / LEDs and Multiplexing / Re: Calibrating a VU meter using a pot/ dynamic calibration on: March 27, 2012, 11:06:42 pm
Also, when you guys are talking about the bargraph, which portion of the code are you referring to: the one where the LEDs are toggled?
10  Using Arduino / LEDs and Multiplexing / Re: Calibrating a VU meter using a pot/ dynamic calibration on: March 27, 2012, 11:05:07 pm
You should average you levels.
Because if you sample sound you have a wave and you never know where you sampled the wave.
If you want a good responsive bargraph use something like this:

Code:
for (int num=0; num < 4; num++) {
sound[num]= analogRead (inputPIN);
if(num==3) {
soundav=(sound[0]+sound[1]+sound[2]+sound[3])/4; // average sound levels

So this part averaging every 4 samples it takes. Am I right? Moreover, will it quick enough to response to the music? Extremely sorry for not being able to understand. Providing a little more context will help me.

For you pot controle, use a lineaire pot meter a logarithmic will work to but won't give you a fine control.
You have to determine a max and minimum value. I choose between 15 and 25 because of your 20.
Code:
potControl = analogRead(potPIN);   // connect a linear potmeter on potPIN
levelControl = map(potControl, 0, 255,15,25); // you map the values of your pot to a more desired level between 15 and 25
left = left / levelControl;     // youre code

Use Magician his bargraph code, which is much better and more efficient.

If I do NOT go for a pot control, can you help me devise the code such that the calibration is logarithmic, instead of linear?
11  Using Arduino / LEDs and Multiplexing / Re: Calibrating a VU meter using a pot/ dynamic calibration on: March 27, 2012, 11:02:04 pm
Code:
for (i = 0; i < left; i++) // turn on the leds up to the volume level
    {
     digitalWrite(led, HIGH);  <<<< Do you mean digitalWrite( i, HIGH)?>>>>>> Yes, extremely sorry for this. Somehow, the original code has digitalWrite (led[i], HIGH).
    }
    
What you are looking, is "automatic gain control"  loop, or AGC. To make it works, you need a low pass filter in software, look on this web site, should be running average or similar   example somewhere in playground / library section. Arduino IDE has smoothing in analog examples code, should be o'k.
Next, change your bargraph to :
Code:
   int ledLevelKr = map( left_input , 0, PeakHold_smoothedValue, 0, ledCountKr);

  for (int thisLed = 0; thisLed < ledCountKr; thisLed++) {
    if (thisLed < ledLevelKr)
      digitalWrite(ledPinsKr[thisLed], HIGH);
    else
      digitalWrite(ledPinsKr[thisLed], LOW);
  }
 


Thank you so much for putting this in. I was wondering whether you can elaborate / comment on the code. I get the overall picture, but am having a hard time reading what this does:

 int ledLevelKr = map( left_input , 0, PeakHold_smoothedValue, 0, ledCountKr);

where did you get the variables? So I am looking for a AGC? Is the code that you put in part of it, or something attached to it. When you are talking about AGC, are you talking about smoothing as described here: http://arduino.cc/en/Tutorial/Smoothing

Thanks and looking forward to your reply.
12  Using Arduino / LEDs and Multiplexing / Re: How to drive 3 or more LEDs from 1 digital output on: March 27, 2012, 10:55:47 pm
I will try to take a small video and upload it. May be then you can tell me if and what I am doing wrong.
13  Using Arduino / LEDs and Multiplexing / Re: Calibrating a VU meter using a pot/ dynamic calibration on: March 26, 2012, 06:08:42 pm
Also, one other problem is: I could not drive my VU meter with my laptop!! Any reason?
14  Using Arduino / LEDs and Multiplexing / Re: Calibrating a VU meter using a pot/ dynamic calibration on: March 26, 2012, 05:59:29 pm
This code uses a linear mapping of the analog value to the number of active LEDs. A logarithmic mapping is more common.

Can you please direct me to a source or improvise on the code to do a logarithmic mapping? It will be great if you could kindly show me how that is done. Complete newb here; hence, no idea how that can be done.

What exactly do you want? Usually a VU meter is intended as an indicator of the absolute levels. Thus adopting it to specific songs is somewhat pointless. Unless you want to have it as a kind of mini light show. But then this is pretty hard to do. You would need to know in advance the peak level of the song. Unless the time machine gets invented this is somewhat tricky.

Thanks for asking that question. I guess I was not able to make it as clear as I wanted it to.

The problem I am envision is: let's say that the highest value of the signal I get is around 500ish, and I scale the program to react as much. I am using an Ipod to drive the VU meter at FULL volume. However, should I decrease the ipod volume, the signal strength goes down and so does the number of LEDs that light up. All I want is the user to have control over the sensitivity of the lighting. Does that make sense? Or put it the other way: is there a way to ensure that the VU meter behaves independently of the volume of the ipod?
15  Using Arduino / LEDs and Multiplexing / Calibrating a VU meter using a pot/ dynamic calibration on: March 26, 2012, 02:58:27 pm
Hi Folks,
The following is some code I adopted from a website for my LED VU meter. However, one of the issues is that the Sensitivity is sort of HARD-CODED. Is there a way to incorporate a more dynamic calibration going on from the audio signal depending on the song. Imagine a variable standing for 20 (the calibration factor) and changing depending on the signal strength of the cube.

You can view the "signal" strength coming through from A0 from the serial print screen and values usually are around 200 ish for me when driven by an Ipod.

int led[6] = { 3, 4, 5, 6, 7, 8}; // Assign the pins for the leds
int leftChannel = A0;  // left channel input
int left, i;

void setup()
{
for (i = 0; i < 6; i++)  // Tell the arduino that the leds are digital outputs
  pinMode(led, OUTPUT);
Serial.begin(9600);
}

void loop()
{
left = analogRead(leftChannel);  // read the left channel
Serial.println(left);
Serial.print("\t");
left = left / 20;    // adjusts the sensitivity
Serial.println(left);
Serial.print("\t");


  if (left == 0)  // if the volume is 0 then turn off all leds
   {
   for(i = 0; i < 6; i++)
     {
     digitalWrite(led, LOW);
     }
  }
 
  else
  {
   for (i = 0; i < left; i++) // turn on the leds up to the volume level
    {
     digitalWrite(led, HIGH);
    }
   
    for(i = i; i < 6; i++)  // turn off the leds above the voltage level
     {
      digitalWrite(led, LOW);
     }
  }
}
Pages: [1] 2