Powering up RGB LED strips using arduino uno via 12V power supply

Hi,

I have managed to get the LED strips to communicate with the arduino via 12V power supply. I have used a connection which i got through various forums. The connections I used for the breadboard is found on this link Adafruit Learning System.
The code is written below:

#define REDPIN 5
#define GREENPIN 6
#define BLUEPIN 3

#define FADESPEED 5 // make this higher to slow down

void setup() {
pinMode(REDPIN, OUTPUT);
pinMode(GREENPIN, OUTPUT);
pinMode(BLUEPIN, OUTPUT);
}

void loop() {
int r, g, b;

// fade from blue to violet
for (r = 0; r < 256; r++) {
analogWrite(REDPIN, r);
delay(FADESPEED);
}
// fade from violet to red
for (b = 255; b > 0; b--) {
analogWrite(BLUEPIN, b);
delay(FADESPEED);
}
// fade from red to yellow
for (g = 0; g < 256; g++) {
analogWrite(GREENPIN, g);
delay(FADESPEED);
}
// fade from yellow to green
for (r = 255; r > 0; r--) {
analogWrite(REDPIN, r);
delay(FADESPEED);
}
// fade from green to teal
for (b = 0; b < 256; b++) {
analogWrite(BLUEPIN, b);
delay(FADESPEED);
}
// fade from teal to blue
for (g = 255; g > 0; g--) {
analogWrite(GREENPIN, g);
delay(FADESPEED);
}
}

However there are things that I need to reconsider and alter in regards to the lighting system:

  1. write a routine that does the "soft" transition from on to off. So it will do the PWM of the LED strip lights,while transitioning from OFF to ON and ON to OFF, say, over 1-2 seconds.

  2. implementing a timer delay lets say between 5-10secs.

I am stuck on this part and keep getting errors when compiling :frowning: Hope you can help.
Thank you.

Regards,
Michael

I just compiled your code with no problems

delay is in milliseconds, so you need 5000-10000 for 5-10 secs

I have tryed putting on a delay for 5-110 seconds, the code is written below:

#define REDPIN 5
#define GREENPIN 6
#define BLUEPIN 3

#define FADESPEED 5 // make this higher to slow down

#define timer 5000

void setup() {
pinMode(REDPIN, OUTPUT);
pinMode(GREENPIN, OUTPUT);
pinMode(BLUEPIN, OUTPUT);

}

void loop() {
int r, g, b;

// fade from blue to violet
for (r = 0; r < 256; r++) {
analogWrite(REDPIN, r);
delay(FADESPEED);
delay(5000);

}
// fade from violet to red
for (b = 255; b > 0; b--) {
analogWrite(BLUEPIN, b);
delay(FADESPEED);
delay(5000);
}
// fade from red to yellow
for (g = 0; g < 256; g++) {
analogWrite(GREENPIN, g);
delay(FADESPEED);
delay(5000);
}
// fade from yellow to green
for (r = 255; r > 0; r--) {
analogWrite(REDPIN, r);
delay(FADESPEED);
delay(5000);
}
// fade from green to teal
for (b = 0; b < 256; b++) {
analogWrite(BLUEPIN, b);
delay(FADESPEED);
delay(5000);
}
// fade from teal to blue
for (g = 255; g > 0; g--) {
analogWrite(GREENPIN, g);
delay(FADESPEED);
delay(5000);
}
}

I compiled it and it all seems to be doing is staying on one colour, which is red :s and it doesnt seem to want to fade the colours anymore. How would you alter this code?

Put your 5 second delays OUTSIDE the loops, not inside. Otherwise it's pausing for 5 seconds for 255 times, which means it will take 1,275 seconds, or 21.25 minutes before a single color to fade from 0 to full brightness, or the reverse.

Thanks for that, it is delaying for 5 seconds as i would like it to. The other part that im kinda stuck on is the soft transition from ON to OFF, so it will do the pwm of the lights while transitioning from OFF to ON and OFF to ON, over 1-2 second intervals. How would i come about in doing this? I am very new to coding and as much help as possible would be great.

Right now you simply have it fading between colors. You start by going from blue to violet. Since nothing else is already turned on, it will fade from dark to blue, giving the impression of an OFF -> ON fade. But since you're continuously looping it, you never get to an OFF state. So you need to figure out when you want to turn it OFF or ON. And if you want to do that arbitrarily with, say using a button, then you need to write code to a) read that button state, and b) react to it. The way it's written doesn't leave you with many options to do anything.

Also, please post your (current) code between [ code ] tags by clicking on the # in the icon menu above your next reply.