Problem With LED Strips and Arduino Mega

Hello, I am trying to program a simple light show for christmas, and i am running into a series of problem. I have 12 12V LED strips being controlled by an arduino mega, and some strips have one color on no matter what i do short of unplugging it. I have narrowed down the problem to something with the arduino, and i have confirmed that it is not wiring. I have posted the code and diagrams below. Thank you for all and any help.

Code:

#define cr1 4
#define cg1 3
#define cb1 2
#define cr2 5
#define cg2 6
#define cb2 7
#define cr3 8
#define cg3 9
#define cb3 10
#define cr4 11
#define cg4 22
#define cb4 23
#define cr5 24
#define cg5 25
#define cb5 26
#define cr6 27
#define cg6 28
#define cb6 29

int state;
void setup() {
  Serial.begin(115200);
  pinMode(cr2, OUTPUT);
  pinMode(cr3, OUTPUT);
  pinMode(cr1, OUTPUT);
  pinMode(cb2, OUTPUT);
  pinMode(cb3, OUTPUT);
  pinMode(cb1, OUTPUT);
  pinMode(cg2, OUTPUT);
  pinMode(cg3, OUTPUT);
  pinMode(cg1, OUTPUT);
  Serial.println("Outputs Set");
}
void ledstrip(int strng, int cr, int cg, int cb) {
  if (strng == 1) {
    if (cr == 1) {
      digitalWrite(cr1, HIGH);
    } else if (cr == 0) {
      digitalWrite(cr1, LOW);
    }
    if (cg == 1) {
      digitalWrite(cg1, HIGH);
    } else if (cg == 0) {
      digitalWrite(cg1, LOW);
    }
    if (cb == 1) {
      digitalWrite(cb1, HIGH);
    } else if (cb == 0) {
      digitalWrite(cb1, LOW);
    }
  } else if (strng == 2) {
    if (cr == 1) {
      digitalWrite(cr2, HIGH);
    } else if (cr == 0) {
      digitalWrite(cr2, LOW);
    }
    if (cg == 1) {
      digitalWrite(cg2, HIGH);
    } else if (cg == 0) {
      digitalWrite(cg2, LOW);
    }
    if (cb == 1) {
      digitalWrite(cb2, HIGH);
    } else if (cb == 0) {
      digitalWrite(cb2, LOW);
    }
  } else if (strng == 3) {
    if (cr == 1) {
      digitalWrite(cr3, HIGH);
    } else if (cr == 0) {
      digitalWrite(cr3, LOW);
    }
    if (cg == 1) {
      digitalWrite(cg3, HIGH);
    } else if (cg == 0) {
      digitalWrite(cg3, LOW);
    }
    if (cb == 1) {
      digitalWrite(cb3, HIGH);
    } else if (cb == 0) {
      digitalWrite(cb3, LOW);
    }
  } else if (strng == 4) {
    if (cr == 1) {
      digitalWrite(cr4, HIGH);
    } else if (cr == 0) {
      digitalWrite(cr4, LOW);
    }
    if (cg == 1) {
      digitalWrite(cg4, HIGH);
    } else if (cg == 0) {
      digitalWrite(cg4, LOW);
    }
    if (cb == 1) {
      digitalWrite(cb4, HIGH);
    } else if (cb == 0) {
      digitalWrite(cb4, LOW);
    }
  } if (strng == 5) {
    if (cr == 1) {
      digitalWrite(cr5, HIGH);
    } else if (cr == 0) {
      digitalWrite(cr5, LOW);
    }
    if (cg == 1) {
      digitalWrite(cg5, HIGH);
    } else if (cg == 0) {
      digitalWrite(cg5, LOW);
    }
    if (cb == 1) {
      digitalWrite(cb5, HIGH);
    } else if (cb == 0) {
      digitalWrite(cb5, LOW);
    }
  } if (strng == 6) {
    if (cr == 1) {
      digitalWrite(cr6, HIGH);
    } else if (cr == 0) {
      digitalWrite(cr6, LOW);
    }
    if (cg == 1) {
      digitalWrite(cg6, HIGH);
    } else if (cg == 0) {
      digitalWrite(cg6, LOW);
    }
    if (cb == 1) {
      digitalWrite(cb6, HIGH);
    } else if (cb == 0) {
      digitalWrite(cb6, LOW);
    }
  } else Serial.println("Error, Uknown Strip Number");
}
void ledclear() {
  ledstrip(1, 0, 0, 0);
  ledstrip(2, 0, 0, 0);
  ledstrip(3, 0, 0, 0);
  ledstrip(4, 0, 0, 0);
  ledstrip(5, 0, 0, 0);
  ledstrip(6, 0, 0, 0);
}

void loop() {
}

Diagram.


Note the led strips are represented by the LED, and the battery represents 12 V.

picture with wiring is not clear. make some schematic. enough to draw one color of one channel.

    digitalWrite(cr1, cr);
    digitalWrite(cg1, cg);
    digitalWrite(cb1, cb);

Hi, @dronemaster278
Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

There are different kinds of LED strips. What exactly are you using? Do you have good specs or datasheet?

const byte c_pin[6][3] = {
  {4, 3, 2},
  {5, 6, 7},
  {8, 9, 10},
  {11, 22, 23},
  {24, 25, 26},
  {27, 28, 29}
};

void setup() {
  Serial.begin(115200);
  for (byte i = 0; i < 6; i++)
    for (byte j = 0; i < 3; i++)
      pinMode(c_pin[i][j], OUTPUT);
  Serial.println("Outputs Set");
  ledstrip(1, 1, 0, 0);
  ledstrip(2, 0, 1, 0);
  ledstrip(3, 0, 0, 1);
  ledstrip(4, 1, 1, 0);
  ledstrip(5, 0, 1, 1);
  ledstrip(6, 1, 0, 1);
  delay(5000);
  allClear();
}

void ledstrip(byte strng, bool r, bool g, bool b) {
  digitalWrite(c_pin[strng][0], r);
  digitalWrite(c_pin[strng][1], g);
  digitalWrite(c_pin[strng][2], b);
}

void allClear() {
  ledstrip(1, 0, 0, 0);
  ledstrip(2, 0, 0, 0);
  ledstrip(3, 0, 0, 0);
  ledstrip(4, 0, 0, 0);
  ledstrip(5, 0, 0, 0);
  ledstrip(6, 0, 0, 0);
}

void loop() {
}

I tried this code, and for some reason it does not work. I went back to the old code and i have the same results as last time. I did rewire it, but the code seems to be the problem.

Sorry, I have no experience using diagrams, but i tried to remake the first diagram. If this does not work, i can try another way.

this diagram is useless, more then old in post#1. +9V is nowhere connected.

apologies. 9V is actually 12V in real life, and the RGB LED is the led strip.
Updated Photo

Is there a program i can use to make one?

paper and pen. or show picture where you learn how to wire a NMOS.

well, i see, 12V supply is only for Arduino.
how led strip is powered? Do you already have such a strip, do you have a photo of it?

compare

Hi, @dronemaster278

If you are after a basic CAD try;

Very basic, does not use masses of HD or memory and produces nice results.

Tom.. :grinning: :+1: :coffee: :australia:

What is the part number of the transistors you are using?

How are they connected? The image is too blurry

the resistors are 100 km i think.

the 12V powers both the Arduino and the light strips. I found a youtube video that has the wiring for the whole set up.
Screenshot 2023-11-09 8.45.50 AM

is your project working now?

no.

write simple sketch that toggles pins 5,6,9.

1 Like

modified the code, same result.