trying to get common anode 5v RGB light strip to flash different colors to music

Hello...

I know there are many examples on youtube and elseware getting RGB light strips to react to music but I haven't found an example that fits the hardware that I am using and I have been unsuccessful at modifying the code to get the result I want to acheive. Overall, my end goal is to create a small lamp with only 10 to 15 RGB LEDs using a light strip, power supply, sound detector, and arduino uno or nano that changes color to the sound of music.

My hardware - Arduino nano, sound detector, +5v RGB LED light strip (4pin: +5v, R, G, B).

Attached is the schematic. The temp sensor is a stand-in for the RobotDyn sound detector (5v to VCC, GND to GND, and Pin7 to Digital Out)

The code I am trying to modify and use is below. I have tried this code and it does make the LED strip beat to the music and changes colors but the LED strip stays on rather than the default state being off. Can the code be modified to work with a common anode analog RGB LED strip? or does it require transistors? or Both? or something else?

I appreciate any and all advice.

//Van der Stappen ©
 
#define REDPIN 11  
#define GREENPIN 10
#define BLUEPIN 9
 
int redNow;
int blueNow;
int greenNow;
int redNew;
int blueNew;
int greenNew;
 
void setup()
{
  pinMode(7,INPUT); //Signal from Sound Detector to Digital Pin 7
  pinMode(REDPIN, OUTPUT);
  pinMode(GREENPIN, OUTPUT);
  pinMode(BLUEPIN, OUTPUT);
  redNow = random(255);
  blueNow = random(255);
  greenNow = random(255);
  redNew = redNow;
  blueNew = blueNow;
  greenNew = greenNow;
 
}
 
#define fade(x,y) if (x>y) x--; else if (x<y) x++;
 
void loop()
{
  boolean soundstate = digitalRead(7);
  if (soundstate == 1) {
    analogWrite(BLUEPIN, blueNow);
    analogWrite(REDPIN, redNow);
    analogWrite(GREENPIN, greenNow);
    redNew = random(255);
    blueNew = random(255);
    greenNew = random(255);
    // fade to new colors
    while ((redNow != redNew) ||
      (blueNow != blueNew) ||
      (greenNow != greenNew))
    {
      fade(redNow,redNew)
        fade(blueNow,blueNew)
          fade(greenNow,greenNew)
            analogWrite(BLUEPIN, blueNow);
      analogWrite(REDPIN, redNow);
      analogWrite(GREENPIN, greenNow);
      delay(1);
    }
  }
  else{
    digitalWrite(REDPIN,0);
    digitalWrite(GREENPIN,0);
    digitalWrite(BLUEPIN,0);
  }
}/code]

Would you have a link or image of the sensor to show?
Maybe if you force the initial condition to true you will have "oscillating" in your RGB. For a test, you could do the following:

boolean soundstate = true; // digitalRead (7);

Below is the sensor I am using. If I comment out digitalRead(7) then it doesn't pick up the sound sensor and doesn't react to music. It will oscillate led.

One possibility, for your strip to work, but not the tape, is the way you made the links from it.
The Arduino would not be able to provide (mA or A) needed for your tape, if so, you will need
include tape drive driver. The tapes (large tapes) are powered at 12V and pull good current.

If you can, also play an image of how everything is connected to it, that would help in the thoughts.

Jeff thanks. I will post a picture tonight of the actual board/led strip/sound detector all hooked up. But the Led strip I am using is only a 5v version and not a 12v version. I did this b/c I wanted the arduino to run the Leds.

Here is a link to the led strip lights I am using but I am only using about a foot of the strip.

Right now it all works except for the fact that lights stay on as default (bright white). When sound/music is detected through the microphone they do beat to the music and shift colors. I would just like the default state of the led to be "off" until sound is detected. I am hoping the code can be changed rather than more components added. The only solution I have is using a transistor between pins 9, 10, and 11 but I am not sure if that will work. I would try but I don't have any transistors or know which ones to get.

Wouldn't it be more fun to use the analog output of the mic module? There is a lot more audio information there.

Oh...I think it definitely would. Like map a specific color to a range of detected values. But I think I would still be in the same situation with the default state of the LED strip being on. But I will try to find some code to use to try this thought. Sorry...new to all of this and learning slowly.

khashurst:
But I will try to find some code to use to try this thought

Find? Why not write it?

I am not a programmer....but I am trying to learn little by little...this LED reactive lamp just a small part of something else I am doing....it is the cherry on top sort of speak.

Having very limited knowledge of both arduino and programming is why I was asking if the issue with the LEDs original state not being "off" due to the code or the hardware (in this case using common anode RGB LED light strip and trying to sink 5 volts instead of source 5 volts through the digital pins. If I am even understanding any of this correctly. I do need to run through many many more tutorials to get a handle on the syntax and how a micro controller works.

Please post a schematic.

aarg....please see attached. I couldn't find a breakout for the actual sound detector I am using but mine has both the Digital Out and Analog Out. I also couldn't find a breakout for the RGB light strip I am using either so I substituted a common anode RGB LED. Thanks for your advice.

Try:

  else {
    digitalWrite(REDPIN, 255);
    digitalWrite(GREENPIN, 255);
    digitalWrite(BLUEPIN, 255);
  }

gfvalvo...Bingo

Thank you...does the reason have something to do with LED being common anode rather than common cathode? 255 is 0 and 0 is 255.

It's not a good idea to connect the LED anode to Vin. That can expose the data pins to voltage in excess of the allowed specification (a little over Vcc). Also does your LED have built in current limiting resistors? I doubt it. That can also lead to damage to the Arduino data pins.

gfvalvo:
Try:

  else {

digitalWrite(REDPIN, 255);
   digitalWrite(GREENPIN, 255);
   digitalWrite(BLUEPIN, 255);
 }

In other words,

    digitalWrite(REDPIN, HIGH);
    digitalWrite(GREENPIN, HIGH);
    digitalWrite(BLUEPIN, HIGH);

aarg:
Also does your LED have built in current limiting resistors?

I had assumed OP's "schematic" was just a cartoon depicting more appropriate device containing series current-limiting resistors. Being of the Old School (college in the 80's), I ALWAYS connect LEDs with this polarity (with series resistors).

gfvalvo:
I had assumed OP's "schematic" was just a cartoon depicting more appropriate device containing series current-limiting resistors. Being of the Old School (college in the 80's), I ALWAYS connect LEDs with this polarity (with series resistors).

OP stated otherwise in reply #10. Or, to be generous, didn't provide enough information.

The led light strip I am using is in post #4 as a link. Attached is an image of the strip. It does have 111 and 181 resistors for each LED. I only want to use about a foot of the strip which is only 15 of the LEDs. I definitely don't want to fry the data pins. I will figure another method to wire. Thank you all.

You should use driver transistors for that load.

aarg:
OP stated otherwise in reply #10. Or, to be generous, didn't provide enough information.

I do apologize that my schematics were crude and made some assumptions.