LEDS displaying wrong color

In the script when I set the color to for example indigo its yellow on the leds,and not matter what color I set or change the inputs its always the wrong color,btw this is happening to all of my led strips which are from different brands and everything. I use an arduino uno btw

Much more detail needed

  • What strips ?
  • Wiring diagram ?
  • Code being executed ?
  • How is the project powered ?

no specific brand strip,it has 4 outputs r ,g,b and 12v
I have the r g b going from the strip to the arduino inputs,the 12v goes to the 9v battery +,and the - on the battery is connected to ground on arduino. This isnt my code btw:
The code works but a)the colors go in the wrong order and like I said setting up a specific color results in the wrong color on the strip

// Rainbow color changing RGB leds example
// I am using common cathode RGB leds
int PIN_RED = 11;
int PIN_GREEN = 10;
int PIN_BLUE = 9;
int counter = 0;

// Number of colors used for animating, higher = smoother and slower animation)
int numColors = 255;

  // The combination of numColors and animationDelay determines the
  // animation speed, I recommend a higher number of colors if you want
  // to slow down the animation. Higher number of colors = smoother color changing.
int animationDelay = 10; // number milliseconds before RGB LED changes to next color

void setup() {
  pinMode(PIN_RED, OUTPUT);
  pinMode(PIN_BLUE, OUTPUT);

void loop() {
  // This part takes care of displaying the
  // color changing in reverse by counting backwards if counter
  // is above the number of available colors  
  float colorNumber = counter > numColors ? counter - numColors: counter;
  // Play with the saturation and brightness values
  // to see what they do
  float saturation = 1; // Between 0 and 1 (0 = gray, 1 = full color)
  float brightness = 1; // Between 0 and 1 (0 = dark, 1 is full brightness)
  float hue = (colorNumber / float(numColors)) * 360; // Number between 0 and 360
  long color = HSBtoRGB(hue, saturation, brightness); 
  // Get the red, blue and green parts from generated color
  int red = color >> 16 & 255;
  int green = color >> 8 & 255;
  int blue = color & 255;

  setColor(red, green, blue);
  // Counter can never be greater then 2 times the number of available colors
  // the colorNumber = line above takes care of counting backwards (nicely looping animation)
  // when counter is larger then the number of available colors
  counter = (counter + 1) % (numColors * 2);
  // If you uncomment this line the color changing starts from the
  // beginning when it reaches the end (animation only plays forward)
  // counter = (counter + 1) % (numColors);


void setColor (unsigned char red, unsigned char green, unsigned char blue) 
    analogWrite(PIN_RED, red);
    analogWrite(PIN_GREEN, green);
    analogWrite(PIN_BLUE, blue);

long HSBtoRGB(float _hue, float _sat, float _brightness) {
    float red = 0.0;
    float green = 0.0;
    float blue = 0.0;
    if (_sat == 0.0) {
        red = _brightness;
        green = _brightness;
        blue = _brightness;
    } else {
        if (_hue == 360.0) {
            _hue = 0;

        int slice = _hue / 60.0;
        float hue_frac = (_hue / 60.0) - slice;

        float aa = _brightness * (1.0 - _sat);
        float bb = _brightness * (1.0 - _sat * hue_frac);
        float cc = _brightness * (1.0 - _sat * (1.0 - hue_frac));
        switch(slice) {
            case 0:
                red = _brightness;
                green = cc;
                blue = aa;
            case 1:
                red = bb;
                green = _brightness;
                blue = aa;
            case 2:
                red = aa;
                green = _brightness;
                blue = cc;
            case 3:
                red = aa;
                green = bb;
                blue = _brightness;
            case 4:
                red = cc;
                green = aa;
                blue = _brightness;
            case 5:
                red = _brightness;
                green = aa;
                blue = bb;
                red = 0.0;
                green = 0.0;
                blue = 0.0;

    long ired = red * 255.0;
    long igreen = green * 255.0;
    long iblue = blue * 255.0;
    return long((ired << 16) | (igreen << 8) | (iblue));

Like I said powered by a 9v battery

also there are other codes I found same problem everytime

This is not about the code, this is about taking one step at the time :wink:

Those are PWM pins for a Arduino Uno. That's okay.
We would like to know what ledstrip it is. The Arduino can only drive one led, and sometimes resistors are required.

Can you make a small test-sketch ?
Set pin 11 high and check if that is red, then check if 10 is green and 9 is blue.

Then do for example a analogWrite() to the pins and check if you can dim them.

Sorry, but I don't understand how your circuit is connected. Please post a diagram. A 'photo of a hand drawn circuit is good enough

If that is not causing a problem already then it soon will if the battery is a PP9 as it cannot supply sufficient current at the required voltage for very long. Can you measure the battery voltage when it is powering the project ?

Can you please post a copy of your circuit?

What Arduino controller are you using?
If you are using a 9V smoke detector battery then it will not last long.

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

I dont have anything to measure the voltage,but the leds glow really bright,and here is the diagram
Sorry if it looks bad I dont know what I am doing

I posted the circuit "sketch" ,and I know I need to buy a 12V power supply which connects to my socket but for now I am using the 9V battery

Its an led strip I bought in my local store,I dont have the box anymore and there are no markings.
now setting the red to high does give red,and same for the other colors

What are the LEDs rated voltage?
That is not how you control LEDS from a UNO with a 9V LED supply.
Please disconnect the 9V battery.

Can you please tell us your electronics, programming, arduino, hardware experience?

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

1 Like

That will damage the Arduino Uno.

I think each section had three RGB leds and three resistors. The resistors are probably in the range of 150-500 Ω. Those ledstrips are used with a controller device and with a IR remote control. The controller can deal with 12V, and outputs a PWM signal that can drive a large current (for a long ledstrip).

They can not be used with an Arduino Uno (unless you build a mosfet driver with PWM as shown below).

You need to build this to control that 12V strip.

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


Nice schematic except that the even-numbered resistors are on the wrong side of the odd numbered.

What did you use to draw it?

1 Like

ExpressPCB, I use the schematic part, good for quick diags here.
Use EasyEda for schematics that go to PCB.

Happy.. :grinning: :smiley: :grinning_face_with_smiling_eyes: :grin:

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

That looks much nicer. :+1:

The pull-down resistors are to compensate for the Arduino pins floating during reset (or code malfunction?). There is otherwise no need to "pull down" the FET gate and while with suitably sized resistors, their effect as a voltage divider is not significant, it is just poor practice to have them on the gate side. :grinning:

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