How to get a constant color from RGB LED?

Hello there, I'm trying to get a constant orange color (or ANY color other than the basic red, green or blue) out of the RGB LED. When I enter different values for the red, green and blue, the LED cycles through the three colors instead of showing just one color based on the mix of those values. My code is:

const int RED_PIN = 5;
const int GREEN_PIN = 6;
const int BLUE_PIN = 9;

void setup()
{
  pinMode(RED_PIN, OUTPUT);
  pinMode(GREEN_PIN, OUTPUT);
  pinMode(BLUE_PIN, OUTPUT);
}


void loop()
{
  analogWrite(RED_PIN, 200);
  analogWrite(BLUE_PIN, 50);
  analogWrite(GREEN_PIN, 150);
}

I understand that Arduino executes a sketch line-by-line and can't execute multiple lines at the same time, but is that the problem here?

I moved your topic to an appropriate forum category @ansh4real.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

Because you are in the loop()
Put your analogWrites in setup()
Which Arduino are you using?
Do you have current limiting resistors for the LED?

Even though those three instructions are executed continually, being in loop(), it will be the same color - there's no delay() between them.

void loop() {
  analogWrite(RED_PIN, 200);
  analogWrite(BLUE_PIN, 0);
  analogWrite(GREEN_PIN, 150);
  delay(2000);
  
  analogWrite(RED_PIN, 0);
  analogWrite(BLUE_PIN, 50);
  analogWrite(GREEN_PIN, 150);
  delay(2000);

  analogWrite(RED_PIN, 200);
  analogWrite(BLUE_PIN, 50);
  analogWrite(GREEN_PIN, 0);
  delay(2000);

}

I tried putting it setup(), but the result is the same. It blinks through the colors individually, instead of showing just one color.
I'm using Arduino Uno.
I've connected one 330 resistor to the ground of the RGB led.

I have tried this too, but it still blinks through the red green and blue.

It should not blink. Are you sure that you did upload the sketch successfully and did the upload to the correct board (e.g. you have two Unos connected and picked the wrong one :wink:)

How fast is the blink that you see ?

Each LED needs its own resistor. The above connection won't work as you expect.

Please post a hand drawn wiring diagram, with pins and parts clearly labeled.

No good.
Each color needs it's own resistor

Experimented with the code to figure it out, but I’m still having trouble getting the LED to show a constant orange color.

@rajendra3 are you the same person as @ansh4real ?