Battery power and variable resistor causing LED flickering

Hi all!

I'm relatively new to electronics and am working on a WS2812B LED strip project. I've constructed a circuit that powers both the LED strip and an Arduino Nano from four AA batteries fed into a step-down converter that lowers the voltage to 5v (tested with a multimeter). That circuit worked great and I could run it at different brightness levels with no issue.

My problem arises now that I've tried to add a potentiometer to my circuit in order to control a variable in my code that adjusts the brightness of the LED strip. It works fine when I power the circuit from the Arduino board's USB port, but when I switch it over to battery power the whole led strip flickers randomly at low brightness levels. The flickering gets less noticeable as I adjust the potentiometer to higher brightness levels.

I have done all the troubleshooting methods I know (and have found from the internet) how to do and have not been able to fix the issue. The circuit works as intended with no flickering lights when I run it off battery power with no potentiometer, and when I run it off USB power with/without the potentiometer. I have tried different arrangements of resistors throughout the circuit in case it is an issue with the current, this has not changed anything.

Here is my code:

// FastLED - Version: 3.5.0
#include <FastLED.h>

#define NUM_LEDS 10
#define LED_PIN 2
#define potPin 0

int potValue = 0;

uint8_t max_bright = 255; 

CRGB leds[NUM_LEDS];
float currentH = 0;
float deltaH = 2;

void setup() {
  Serial.begin(9600);
  
  FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS); //Defines LED strip and makes it ready to program.
  FastLED.setBrightness(255);
}

void loop() {
  potValue = analogRead(potPin); // read the pot value
  Serial.println(potValue); //Print pot value to serial monitor
  int mappedPot = map(analogRead(potPin), 0, 1023, 0, 255); //Adjusts the pot reading to a value between 0 and 255 in order to control brightness.
  FastLED.setBrightness(mappedPot); //Sets brightness to mapped pot value
  
  fill_solid(leds, NUM_LEDS, CHSV(currentH,255,255)); //Fills the LED strip with a constantly changing color to create a rainbow effect.
  
  currentH += deltaH;
  if (currentH >= 255) {
    currentH -= 255;
  }
  FastLED.show();
  delay(10);
}

And here is my wiring schematic:

Again, I'm pretty new at this and am trying my best to accurately describe my situation. I am happy to answer any questions and appreciate any help :slight_smile:

Most probably that's a power issue. Low brightness indicates that the power supply can not supply enough current.

As analogRead() is depending on the supply voltage by default, you will get varying ADC values when the supply voltage varies due to varying LED current. Try to set the ADC reference voltage to the built-in voltage source of your controller.

And (wrong) Fritzing is not a replacement for a symbolic circuit diagram.

Drawing error on the LED strip +V power lead
:wink:

image

run your power wires from PS direct to LED strip, not through breadboard; the power fluctuations in the LED circuit might be confusing your potentiometer readings.

You have no capacitor on the power pins of your strip.

1 Like

I'm not sure I understand. How do I change the ADC reference voltage, or, what voltage is being referenced? I'm also confused as to how it could be an issue with a lack of current because without the potentiometer, the battery powers the LEDs just fine and theoretically I should have an excess of current. Could it be that the potentiometer is just a massive current sink?

I added a capacitor in series with the +5V lead that goes into the LEDs and there was no change, is this what you meant?

Normally the A/D use 5v.

If 5v is fluctuating, errors will show up.

The internal reference does not change.

In parallel with the strip 5v :nerd_face: .

i.e. 5v to GND (0V)

Ah ok I will try that. Thank you for the quick replies!

No.
You add the capacitor from the positive supply of the strip to the ground of the strip. That is not in series it is across the component.
What value are you using? You need at least 100uF. Even if you don't see a difference you still need it because it makes the whole setup more reliable.

I used a 100uF capacitor connected from the positive to the negative supplies. This seems to have somewhat reduced the flickering but has not removed it entirely, should I try one with more uF? And apologies for the miscommunication, I'm still new at this :upside_down_face:

Edit: I have tried a 470uF 10V capacitor (it is what I had on hand) and it has reduced the flickering even more. I think it is down to an acceptable level now. After further experimenting I've noticed that more capacitors there are (or the bigger they are) the better the flickering gets. I think I'm satisfied with how much the flickering has reduced so I'm going to close this topic now.

Thanks for the help everyone!

Default Arduino reference (Vcc) is correct for this task since the potentiometer output is ratiometric. Better layout should reduce the need for the huge decoupling capacitors.

Ok, how do I use this information to change the circuit layout? What change would you make to the circuit? These are new concepts to me.

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