Led rgb multi lights on

Hi all!

Im surfacing a weird problem with RGB 5 mm led.

This is the code im using.

Int red = 2
Int green = 3
Int blue = 4

And on the setup void...

digitalWrite(red, HIGH);
digitalWrite(blue, LOW);
digitalWrite(green, LOW);

So....

This basic example turns a mix of lights and not the red one that i need/want/desire. The led lights up with a mix of colours.

Im using wemos d1 mini and this was also tested with a D1 wemos board with the same results.

Im connected the pins to D2, D3, D4 according to the matching colors and the anode to the 5v pin. Is a regular RGB Led.

Any clue about that mixed colours?

Regards!
Martin.

Im connected the pins to D2, D3, D4 according to the matching colors and the anode to the 5v pin. Is a regular RGB Led.

I hope you have resistors on each cathode.

With this wiring, anode to 5V cathode to Arduino output through a resistor, you get the LED to light up by writing a LOW, and to turn off by writing a HIGH.

Im connected the pins to D2, D3, D4 according to the matching colors and the anode to the 5v pin.

This could damage the wemos. There has been some discussion about this online, and Expressif, who designed the esp chip, have not been clear on the question. So we should assume it's pins are not tolerant of 5V. It would be safer to connect the anode to the 3.3V, but then there is a chance that the blue led will not light at all.

Your series resistors should be calculated to ensure the current for each pin does not exceed 12mA (a much lower limit than for an Uno, fir example).

With the led anode connected to 5V, even when a pin is set HIGH, it will only output 3.3V, so there will still be a 1.7V across the led+resistor. This could cause leds to glow, but perhaps not very brightly.

Only the red LED really.

Put a 1N914 in series with the red and green LEDs. (It can be common to both!)

Hi all!

Thanks for your replies.

Ok...i know that 5v could damage the led and the wemos board. So i should connect it to a 3v pin. Ok with that.

I have two doubts right now:

  1. I have a RGB led that works with a + anode because i must connect the longest leg to a 3v output. Does it work like this?. My PCB goes to the GND, anyway i could change that but what about if i buy a cathode led in the future?. How can i change the anode or cathode thing?.

  2. The RGB colours behave a little weird like i say before. The lights mix them up and i cant have the exact color that i need/want.

This two problems are code related?

Regards to everyone!.

The RGB colours behave a little weird like i say before. The lights mix them up and i cant have the exact color that i need/want.

You can only have primary or secondary colours with digital outputs. To get proportions of colours you need to use PWM capable outputs and use the analogWrite commands to set the intensity of the colours.

But your big problem is that your code turns the LEDs off when writing high. So

 digitalWrite(red, HIGH);
digitalWrite(blue, LOW);
digitalWrite(green, LOW);

Will turn the red off and the blue and green on. This is called sinking the current.
Connecting the cathode to ground and the output to the anode is called sourcing the current and high turns it on.

I have a RGB led that works with a + anode because i must connect the longest leg to a 3v output. Does it work like this?

Yes. But you don’t say a + anode because anode means positive and cathode means negative. On a lot of RGB LEDs you can buy either common anode or common cathode devices.

Marty1982:
Ok...i know that 5v could damage the led and the wemos board. So i should connect it to a 3v pin. Ok with that.

NOt necessarily. You will likely need to use the 5 V to properly drive the blue LED. So pit teh 1N914 in series with the red - or red and green, and if you are using a common-anode RGB LED, just put the 1N914 in series with the common anode, thus reducing your drive voltage to 4.3.

Uhmmm ok...

I'm likely confused by now.

So, what should i do now?. Should i connect the whole RGB LED to 3v or not?.

Beside of the code should i need to modify something?.

Thks!

You can try connecting the anode to 3.3V, but as I said, there is a danger that the blue led will not light, or light only dimly. That's because the blue led will have a forward voltage of 3~3.2V, leaving almost no voltage drop for its series resistor, which in turn requires a very low value of resistor. Such a resistor does not provide much protection for the led when it's forward voltage changes due to temperature changes etc.

Basically, by using a 3.3V board, you are attempting to use an rgb led in marginal conditions.

One suggestion would be to continue to connect the anode to 5V and connect the cathodes to 3 transistors, such as bc337 npn. The npn will drop around 0.7V, so take that into account when calculating your series resistors. This will invert the signals from the esp pins, so that a HIGH output from the pin switches the led on, as you originally expected. It should also allow the maximum (probably 20mA) current to light each of the led colours. 1K resistors between the esp pins and the npn bases should be OK.

Or you could just do what I suggested in #6. :roll_eyes:

Or you could just get a 5V processor like a Uno or Nano.

Hi all!

I managed to figure it out.

I've changed the pins because one of them D4 was crashing with the onboard led.

Thanks to all!