I have a LED Strip that has 12V, R, G, B connections and I want to switch purely between those colors based on a pin that I connect to a 3.3V power source. (Ex: I bring pin 2 high with 3.3V, and then the red lights turn on) I am only getting odd colors though and am having a large delay. Please see my code below:
const int in = 2; // the number of the input pin
const int in1 = 4; // the number of the input pin
const int in2= 6; // the number of the input pin
const int ledPin = 8; // the number of the LED pin
const int ledPin1 = 10; // the number of the LED pin
const int ledPin2 = 12; // the number of the LED pin
// variables will change:
int inState = 0; // variable for reading the status
int inState1 = 0;
int inState2 = 0;
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
// initialize input:
pinMode(in, INPUT);
pinMode(in1, INPUT);
pinMode(in2, INPUT);
}
void loop() {
// read the state of the pushbutton value:
inState = digitalRead(in);
inState1 = digitalRead(in1);
inState2 = digitalRead(in2);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (inState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
}
else if (inState1 == HIGH) {
// turn LED on:
digitalWrite(ledPin, LOW);
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, LOW);
}
else if (inState2 == HIGH) {
// turn LED on:
digitalWrite(ledPin, LOW);
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, HIGH);
}
}
I can't tell what type of LED strip you're using. It appears to have a +12V line and lines for R, G, and B. Without knowing exactly what you've got, we can't help.
I don't think supplying 3V3 to any of those pins will do what you think they should do.
This is a link to the lights I have configured. I am wanting to bring a digital pin high using the 3.3V and as a result of that pin being brought high, a certain color will be lit up. Ex: If Pin 2 is high, then turn the color to red, etc. I am using an Arduino Uno R3.
The 12V power is available to all LEDs and ground the pins associated with the colors you want to light. To light the red LEDs, ground the R pin. The other colors work the same way. To control the intensity of the individual colors, you can dim them using PWM.
** WARNING ** You may destroy your Arduino if you connect it directly to any of these pins as you were planning.
Suggestion - connect a good 12V power supply to the 12V input (the LED strip can draw up to 1.2 Amps). Then connect the R, G, and B lines to ground via an NPN transistor or an N-Channel MOSFET. You can control the transistor / MOSFET via a PWM signal from your Arduino.