Go Down

Topic: RGB LED displaying the wrong colours (Read 69 times) previous topic - next topic

jibbs96

From the following code, my colours are displaying as red, purple, violet and blue.

I am looking for red, orange, yellow and green - which is how my RGB code reads.

Could anyone advise on this please? Thank you



int red_light_pin= 11;
int green_light_pin = 10;
int blue_light_pin = 9;
void setup() {
  pinMode(red_light_pin, OUTPUT);
  pinMode(green_light_pin, OUTPUT);
  pinMode(blue_light_pin, OUTPUT);
}
void loop() {
  RGB_color(255, 0, 0); // Red
  delay(3000);
  RGB_color(255, 125, 0); // Orange
  delay(3000);
  RGB_color(255, 255, 0); // Yellow
  delay(3000);
  RGB_color(125, 255, 0); // Green
  delay(3000);
}
void RGB_color(int red_light_value, int green_light_value, int blue_light_value)
 {
  analogWrite(red_light_pin, red_light_value);
  analogWrite(green_light_pin, green_light_value);
  analogWrite(blue_light_pin, blue_light_value);
}

david_2018

#1
Mar 26, 2020, 05:05 pm Last Edit: Mar 26, 2020, 05:07 pm by david_2018
Sounds like you have the green and blue leads of the LED wired to the wrong pins.

As a quick test, try changing
Code: [Select]

int green_light_pin = 10;
int blue_light_pin = 9;

to this:
Code: [Select]

int green_light_pin = 9;
int blue_light_pin = 10;

ieee488

Either wiring is wrong or the LEDs themselves are reversed. I had the latter with one 5m strand I bought on eBay.

.

hammy

Alter the code do that each single colour is displayed on its own  red, green,  blue - that will tell you if they are wired correctly .

Go Up