PL9823 showing unwanted color at startup of arduino

So I have PL9823 LED’s that are showing up blue at the start of sketch, but then continue to function as wanted. I would like to get rid of that two seconds of blue light when I switch on the power supply.

The fairly simple setup uses a potentiometer, a 9V Block battery and an Ardunio Mini Pro to regulate two PL9823 LED (in series).

The LED’s respond to the usage of the potentiometer as wanted. I can use the potentiometer to switch between green and red and the colors are right-

But always when I “power up” (connect the battery) the setup shows blue for about 2 seconds, after that green and red show up as I wanted them to.

I tried a lot of changes in the sketch, but to no avail.

This is my sketch, cobbled together from various arduino examples. I need the LED to show green in the pots middle range and a pulsating red in the pots exterior ranges.

#include <FastLED.h>


#define NUM_LEDS 2              
#define DATA_PIN 3             
CRGB leds[NUM_LEDS];          
int fadeAmount = 12;            
int brightness = 0;            
int wait = 10;               
int green_helligkeit = 10;     

int pot1 = A0;        
int pot1_wert = 0;    
int pot1_int1 = 20;     
int pot1_int2 = 80; 


void setup() {
  Serial.begin(9600);
  FastLED.addLeds<PL9823, DATA_PIN, RGB>(leds, NUM_LEDS);
  for (int i = 0; i <NUM_LEDS; i++) {
     leds[i] = CRGB(15,20,3);
}
FastLED.show();
}

void fadeall() { for(int i = 0; i < NUM_LEDS; i++) {
  leds[i] = CRGB::Green;
  FastLED.show();
 } }


void loop() {
  pot1_wert = analogRead(pot1);                 
  pot1_wert = map(pot1_wert, 0, 1023, 0, 100); 
  Serial.print("P1 = ");                        
  Serial.print(pot1_wert);                      

  for (int i = 0; i < NUM_LEDS; i++ )
  {
    if (pot1_wert <= pot1_int1 || pot1_wert >= pot1_int2) {  
      Serial.println("  --> Rot");                            
      leds[i] = CRGB::Red;                                    
    }
    else {                                                   
      Serial.println("  --> Grün");                           
      leds[i] = CRGB::Green;                                
      brightness = green_helligkeit;                         
    }
    leds[i].fadeLightBy(brightness);                          
  }
  FastLED.show();
  brightness = brightness + fadeAmount;
  if (brightness == 0 || brightness == 255)                   
    fadeAmount = -fadeAmount ;
  }
  delay(wait);                                              
}

I doubt it is the code.

The fairly simple setup uses a potentiometer, a 9V Block battery and an Ardunio Mini Pro to regulate two PL9823 LED (in series).

Exactly what does that mean? Can you post a schematic of what you have wired up showing all the parts. Not a Fritzing thing but just a one and paper sketch.

Does your strip have only 2 LEDs or is it a longer strip?
You are not trying to use a 9V smoke detector battery are you?

Hi!

I just have the time for a shot of the breadboard right now. Will do a sketch later...

To the bottom you see the 9V battery, probably it's what you would put into a fire alarm?
To the upper left you see the 2 PL9823 inside their "enclosure".
The model should later be switched on by the switch in the middle left. This supplies power to the "RAW" port of the arduino.

I too believe this could be an electrical problem, changes in the sketch did nothing to the real world performance of this model.

On the other hand: I had the exact same wiring with two WS2812b before and they did not have that blue phase before functioning. I just switched the LED because of their form factor and the described behaviour showed up.

Thanks for thinking about this!

Hi!

So I tried to reproduce the breadboard. I did not find any PL9823 LED's so used similar ones to show the routing:

So your photo doesn’t match the drawing. I did say

Not a Fritzing thing but just a one and paper sketch.

They only tend to obscure things.

Do you know that the break in the power lines on your board is indicated by the break in the line.

You don’t seem to have a capacitor across the LEDs, nor a resistor in the data line. And using a battery like that is not advised because it has so little current capacity and discharges quickly. Try it with a proper power supply. Using the internal voltage regulator is not recommended either because it is prone to overheating.

Try a pull-down resistor (10k?) on the LED data line.

EDIT: your problem is due to random value in the LEDs' control registers. In theory of could have any colour until Arduino powers up and sets the desired one. The 2 s wait time is probably due to the bootloader waiting of done programming command comes.
I don't think the pull-down will be able to fix this but it is a fast option to try and it could help.

As the normal state of a Neopixel data line is high, I would suggest if the pull down doesn’t work then try it as a pull up.

Grumpy_Mike:
Do you know that the break in the power lines on your board is indicated by the break in the line.

I think he does as he is using that break to put the pushbutton in series with the 9 V supply. :grinning:

Hi!

Yeah I am not really electronics smart - or any smart at all if you'd ask my wife. I did however know about that break in the power rails of the breadboard.

I used a 10K Ohm resistor to
a) pull the LED Din down to GROUND
b) pull the LED Din up to VCC.

Sadly no change at all, same blue startup.

I will have to try about the different volatage supply - will write tomorrow.

Thanks so far - any other ideas?

Here is what I tried just now - no change yet:

  1. Connect LED Data line to GROUND via 10k resistor
  2. Connect LED Data line to VCC via 10k resistor
  3. Run the setup from a benchtop power supply at 9V input power
  4. Pressed the Mini Pro's reset switch: LED's freeze in their current colour/brightness, after 2 seconds program runs normally.
  5. Switched the same setup to 2 WS2812b LED: no more blue at startup, everything works.

So I am out of ideas. Because of the form factor I need to use the PL9832 and not the WS2812 led. I am with
Smajdalf thinking that there is something untoward happening during the bootloader interval.

Could I maybe:

  • Shorten this interval by any means?
  • Could I "write the green or red colour" to the led register so that this will show up instead of blue next time?
  • Is my setup electrically sound?
  • Grumpy_Mike asked about a "capacitor across the LED's". I did not know this to be necessary but would try of course. Can you tell me how to do that? I have no clue about placing that capacitor.

You should control power to the LEDs using a transistor. At power up keep them off until Arduino starts. When ready turn on the power and immediately shift out the new value. This will reduce unwanted color to minimum.

verthh:
Grumpy_Mike asked about a "capacitor across the LED's". I did not know this to be necessary but would try of course. Can you tell me how to do that? I have no clue about placing that capacitor.

This large capacitor and the resistor are really only necessary when you have more than your two LEDs or they are at some distance from the Pro Mini; if you have only two LEDs then a 0.1 µF capacitor between 5 V and ground of each LED will be sufficient. For a LED strip which already has those capacitors across each LED, the capacitor and resistor should each be connected as close as possible to the strip itself.

It is worth trying what Smajdalf suggested in reply #10. But make sure you have that 470R resistor fitted, otherwise you could be supplying a logic level signal to an unpowerd strip and that will do some damage to either the strip or the Arduino.

Yep.

I will try the route to switch the supply voltage via transistor. This will take some time, I need to research the transistor type and get my hands on them.

If it's of any interest: While switching my on and off repeatedly I do get different startup colors. The longer the switch off time the more blue will show up. If I switch of really short I might get green or yellow. With the WS2812: nothing! They light up only when FastLED asks them too.

Thanks for all your replies!

Another option to consider is to never remove the power to the LEDs and Arduino. The Arduino monitors the button and if it is not pressed it tells the LEDs to turn off. This way you get the glitch only the first time the power is applied.
The power consumption in standby may be an issue. Properly modified Arduino in deep sleep waiting for a button press consumes <1 uA of current. I don’t know how much current the LEDs will consume when “off”.

Thanks for all the input, it is starting to look good!

I used an NPN transistor (“2N2222”) to connect VCC to the LED’s Vin through collector and emitter. I then connected PIN 9 to the tranistors base via a 1kOhm resistor. I adjusted the code to what you can see below.

It immedeatly worked. No more blue glitching at startup, straight to the programs lightshow! Yeah!

But I introduced a high frequency flickering to the LEDs thats probably some kind of bad coding. How would you code the transistor so my fade loop does not make it flicker?

As the model will be battery operated I would like the power supply to be switched by button.

Thanks in advance!

#include <FastLED.h>

#define NUM_LEDS 2              // Anzahl der Neopixel
#define DATA_PIN 3              // Datenpin für die Neopixel
CRGB leds[NUM_LEDS];            // define the array of leds
int fadeAmount = 12;            // Set the amount to fade I usually do 5, 10, 15, 20, 25 etc even up to 255.
int brightness = 0;             // Anfangshelligkeit (0= hoch!)
int wait = 10;                  // Speed of Fade (0=schnell, 100=langsam)
int green_helligkeit = 10;    

int transistor = 9;       // Pin for transistor

int pot1 = A0;         
int pot1_wert = 0;     
int pot1_int1 = 20;     
int pot1_int2 = 80;     


void setup() {
  FastLED.addLeds<PL9823, DATA_PIN, RGB>(leds, NUM_LEDS);
  pinMode (transistor, OUTPUT);
  digitalWrite (transistor, HIGH);
}

void loop() {

  pot1_wert = analogRead(pot1);                 
  pot1_wert = map(pot1_wert, 0, 1023, 0, 100); 

  for (int i = 0; i < NUM_LEDS; i++ )
  {
    if (pot1_wert <= pot1_int1 || pot1_wert >= pot1_int2) {  
      leds[i] = CRGB::Red;                                    // Turn the LEDs on red
    }
    else {                                                    
      leds[i] = CRGB::Green;                                  // Turn the LEDs on green
      brightness = green_helligkeit;                          // no pulsating in green loop
    }
    leds[i].fadeLightBy(brightness);                          
  }
  FastLED.show();
  
  brightness = brightness + fadeAmount;
  if (brightness == 0 || brightness == 255)                   // reverse the direction of the fading at the ends of the fade:
  {
    fadeAmount = -fadeAmount ;
  }
  delay(wait);                                               // This delay sets speed of the fade. I usually do from 5-75
}
 brightness = brightness + fadeAmount;
  if (brightness == 0 || brightness == 255)

is bad: fadeAmount is 12 and so brightness will never equal 255.

Guys I don't know why but: Flickering is gone after removing that resistor in front of the transistors base. Happend by accident. :o

I cleaned up the code, Now everything seems to be ready for assembly. Thanks so much.

If you get color glitches on your PL9823 LEDs during arduino bootloader switch them on using a transistor at the beginning of the sketch.

Thanks!

Removing the transistor is bad! Try lower value instead. 220R if you have.

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