I have an Arduino UNO and I am attempting to turn ON and OFF a color (red, green, or blue) light of the strip. Here is my code, but All the lights remain lit. The issue is that for example I might want to only show the color RED, but I can't seem to get any of the colors to turn off. I have the pins as follows:
Relevant Code:
int ledPinR = 5;
int ledPinG = 6;
int ledPinB = 3;
void setup() {
pinMode(ledPinR, OUTPUT);
pinMode(ledPinG, OUTPUT);
pinMode(ledPinB, OUTPUT);
}
void loop() {
analogWrite(ledPinR, 0);
analogWrite(ledPinG, 0);
analogWrite(ledPinB, 0);
}
I think you misunderstood my last comment under @Secko's answer, so here is what I meant:
int r = 5;
int g = 6;
int b = 3;
void setup() {
pinMode(r, OUTPUT);
pinMode(g, OUTPUT);
pinMode(b, OUTPUT);
}
void loop() {
analogWrite(r, 128);
delay(50);
analogWrite(r, 0);
analogWrite(g, 128);
delay(50);
analogWrite(g, 0);
analogWrite(b, 128);
delay(50);
analogWrite(b, 0);
delay(50);
}
You need to turn off the last color you turned on in order to get a red, green and blue blink light. Otherwise if you turn on green after red, the strip will be yellow for a short time. If you then turn on blue it will be white and stay white, since no colors are ever turned off.
The second parameter is the voltage applied to your pins. It ranges from 0 - 255, where 0 is 0V and 255 is 5V. 128 is right in the middle with 2.5V.
If your strip is large (=>3 LEDs with power efficient LEDs. Otherwise >1), I hope you use transistors to offload the current draw from the arduino to the transistor. Otherwise you will blow the arduino very soon.
EDIT: You probably blew the arduino already by pulling too much current (too much LEDs) from it's pins.
You will need a PNP transistor in between each color and the arduino that can handle a large current (since you drive a lot of LEDs), which means a darlington transistor array integrated circuit.
Something like the TIP125 comes to mind. (https://www.fairchildsemi.com/datasheets/TI/TIP125.pdf)
It has a maximum collector current of 5A. Put this right in the middle of your VCC and the strip (VCC to collector, the strip to emitter) and connect the arduino to the base of the transistor. You will need 3, one for each color.
EDIT2: Here is a very quickly made schematic to show you the basics. It should be fully functional for a 12V LED strip with an individual color current draw of up to 5A (so 15A total).
You may want to add resistors on the transistor base to sink current though.
EDIT3:
Since you are probably new to electronics: A PNP transistor will enable the connection between collector and emitter if the base is low. Meaning: analogWrite(r, 0)
will turn the color on the strip on and analogWrite(r, 255)
will turn it off. It is inverted with the transistor in between.
Also, and I hope this is obvious, DO NOT ROUTE 5A PER COLOR THROUGH A BREADBOARD OR THROUGH TINY WIRES. THEY WILL GO UP IN SMOKE.