12V LED Light Strip Project

I am creating a project with 2 sets of LED light strips. There is a sensor on either side. Whichever sensor reads a larger input the corresponding light strip will turn green the other red, and vice versa. While waiting for sensors to read something other than 0 the LED strips will be white.

My problem is when I try to turn the LED strip to white it turns a red/orange color. I have tested each color on each strip. They all work individually, but when I try to combine all 3 I get the red/orange color.

Any ideas or help would be much appreciated.

Hello Moqsss

Post your sketch, well formated, with comments and in so called code tags "</>" and a none-Fritzing schematic to see how we can help.

Have a nice day and enjoy programming in C++ and learning.

const int ledPinG1 = 2;
const int ledPinR1 = 5;
const int ledPinB1 = 7;

const int ledPinG2 = 9;
const int ledPinR2 = 11;
const int ledPinB2 = 13;

const int sensor1 = A2;
const int sensor2 = A5;

void blue(){
    digitalWrite(ledPinR1, LOW);
    digitalWrite(ledPinG1, LOW);
    digitalWrite(ledPinB1, HIGH);
    digitalWrite(ledPinR2, LOW);
    digitalWrite(ledPinG2, LOW);
    digitalWrite(ledPinB2, HIGH);
  }
void hit1(){
    digitalWrite(ledPinR1, LOW);
    digitalWrite(ledPinG1, HIGH);
    digitalWrite(ledPinB1, LOW);
    digitalWrite(ledPinR2, HIGH);
    digitalWrite(ledPinG2, LOW);
    digitalWrite(ledPinB2, LOW);
  }
void hit2(){
    digitalWrite(ledPinR1, HIGH);
    digitalWrite(ledPinG1, LOW);
    digitalWrite(ledPinB1, LOW);
    digitalWrite(ledPinR2, LOW);
    digitalWrite(ledPinG2, HIGH);
    digitalWrite(ledPinB2, LOW);
  }
void white(){
    digitalWrite(ledPinR1, HIGH);
    digitalWrite(ledPinG1, HIGH);
    digitalWrite(ledPinB1, HIGH);
    digitalWrite(ledPinR2, HIGH);
    digitalWrite(ledPinG2, HIGH);
    digitalWrite(ledPinB2, HIGH);
  }
  
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(ledPinR1, OUTPUT);
  pinMode(ledPinG1, OUTPUT);
  pinMode(ledPinB1, OUTPUT);
  pinMode(ledPinR2, OUTPUT);
  pinMode(ledPinG2, OUTPUT);
  pinMode(ledPinB2, OUTPUT);

  white();
  
}

void loop() {
  // put your main code here, to run repeatedly:
  int side1 = analogRead(sensor1);
  int side2 = analogRead(sensor2);

  Serial.println(side1);
  Serial.println(side2);
  
  if(side1 == side2 && side1 > 5 && side2 > 5){
    blue();
    delay(3000);
  }
  else if(side1>side2 && side1 > 5){
    hit1();
    delay(3000);
  }
  else if(side2>side1 && side2 > 5){
    hit2();
    delay(3000);
  }
  delay(100);
  white();
}

I'm pretty new to this stuff, the schematic software I used was not cooperating I was only able to place one of each element. In my project I used this setup, but doubled. I have another set of LED strips/mosfet and sensor connected as well. I am using a 12v Battery as my power source.

I would start with a simple sketch to light up each pin in turn for one second at a time, just to check the wiring.

const int ledPinG1 = 2;
const int ledPinR1 = 5;
const int ledPinB1 = 7;

const int ledPinG2 = 9;
const int ledPinR2 = 11;
const int ledPinB2 = 13;


void blink(int pin)
{
  digitalWrite(pin, HIGH);
  delay(1000);
  digitalWrite(pin, LOW);
}

void setup()
{
  pinMode(ledPinR1, OUTPUT);
  pinMode(ledPinG1, OUTPUT);
  pinMode(ledPinB1, OUTPUT);
  pinMode(ledPinR2, OUTPUT);
  pinMode(ledPinG2, OUTPUT);
  pinMode(ledPinB2, OUTPUT);
}

void loop()
{
  blink(ledPinR1);
  blink(ledPinG1);
  blink(ledPinB1);
  blink(ledPinR2);
  blink(ledPinG2);
  blink(ledPinB2);
}

I am not exactly sure what you want to do:
Let's assume you want to use your sensor to figure out which LED is on (which color).
You measure the voltage over the LEDs.

But LEDs have different voltages: red is the smallest, green LED is a bit higher, and I guess white (and blue) gives you the highest voltage.
So, the voltage over an LED varies with its color (1.8V (red) ... 3.xV blue or white).

If it comes just to the wrong color you see: potentially one color is missing (not switched on).

And:
When you do this "loop()" with letting blink all the LEDs - potentially it works fine:
Assume you toggle your LEDs so fast, as on and off, even all the colors - your eye is not capable to see the color change, happening too fast. Your eye will do the "integration" over all the color changes and your brain will tell you: "it is orange" (the other colors coming up are too short).

Put just a large delay, e.g. 1 seconds into all the steps: check if you see all the colors now.
If it is running full speed - your eyes might not catch the color change and your eyes get just the "average" of the color. Eyes can resolve just 10 Hz, but full speed color change gives your eyes just the average (even it works fine, potentially "you see it wrong").

The problem is well known and gets asked about frequently.

It is the lack of current capacity in your power supply, coupled with the resistance in the thin foil PCB traces in the strip.

How many LEDs are in each strip?
What is the current rating of the power supply?

Do not use solder-less bread board, this is only good for half an amp or so.

First off wire the power and ground to both ends of your strip using as thick a wire as you have.

Calculate the total current of your system allowing 60mA per LED, that gives you 20mA per colour. Make sure your power supply can deliver at least 20% more than this figure.

I know Fritzing is rubbish but it is not that bad. You are using it wrong look at some videos about how to use it. One of the reasons that Fritzing is considered utter crap here is that people use the wrong symbols and forget to mention it. That sensor is not a light sensor is it? You are much better drawing a schematic on paper and posting a picture of it.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.