Adafruit NeoPixel RGB LED flickering

Hey guys,

I'm currently doing a simple project where I want to change the color of an RGB LED using a potentiometer.

The problem is that the LED often changes its color without any programmatical interference, even when its hardcoded. For example, from dark blue to orange and on to light blue then back to dark blue. There sometimes seems to exist a pattern, but other times it seems random.

This is the sketch:

And this is my code:

#include <Adafruit_NeoPixel.h>

#define PIN            3
#define NUMPIXELS      1

int potPin = 3; // Potentiometer output connected to analog pin 3
int potVal = 0; // Variable to store the input from the potentiometer

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRBW + NEO_KHZ800);

int pause = 1000;

void setup() {
  Serial.begin(9600);
  pixels.begin();
}

void loop() {
  potVal = analogRead(potPin);
  
  //There's more code which calculates the RGB values from the potentiometer readings
  pixels.setPixelColor(0, pixels.Color(1, 1, 200));  //hardcoded RGB value
  pixels.show(); 

  Serial.println(pixels.getPixelColor(0));  //The color value it prints doesn't change but the color of LED itself changes

  delay (pause);
}

If something is unclear, please ask. Thanks for any help!

Just to verify, you are using a neopixel/ws281x type LED, and not an actual RGB LED?

The resistor is not in the correct location, for a neopixel/ws281x it should be inline with the data line.

This indeed fixes my problem. But why is it necessary? Do I still need the other resistor?

I'm not exactly sure, but it is recommended. This discussion seems to show it provides a cleaner data signal to the LED:

Neopixel Resistor Question