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]




