0
\$\begingroup\$

I wanted to control a RGB-LED with my RaspberryPi. The Problem is that my LED is a bit strange. The long lead is positive and the shorter leads are as usual for red, green and blue but have to be connected to ground (with a resistor in series). Therefore I can't just control every single color with a PWM-signal.

I thought about connecting the three negative leads to a transistor which I then could control with my RaspberryPi. If this could work, what transistor should I use?

Edit: My LED only needs 3V for blue, 2.2V for green and 2V for red at a current of 20mA.

\$\endgroup\$
9
  • 1
    \$\begingroup\$ I can't just control every single color with a PWM-signal ... why not? \$\endgroup\$ – jsotola Nov 24 '19 at 17:54
  • 1
    \$\begingroup\$ You have a common anode LED. If you want to control every color at once, apply a positive voltage to the long lead, and a resistor GND to each of the smaller leads. When you turn on or off the positive supply, all three of the colors will turn on/off at the same time. \$\endgroup\$ – Michael Nov 24 '19 at 17:57
  • 1
    \$\begingroup\$ learningaboutelectronics.com/Articles/… Yes, the other three pins need to be GND to turn on the LED. If a shorter lead is hooked up to 3V, there will be no voltage difference, therefore no current, and no light emitted. With this you can control each color individually. \$\endgroup\$ – Michael Nov 24 '19 at 17:59
  • 1
    \$\begingroup\$ Just use PWM on the negative side. You'll have to invert the PWM signal (100% PWM would be 0% on, etc). \$\endgroup\$ – Hearth Nov 24 '19 at 18:03
  • 1
    \$\begingroup\$ @IgliGerdon "output mode" doesn't mean "can only source current"; in fact, many microcontrollers can sink current better than they can source it anyway. Read the relevant specs, though. \$\endgroup\$ – Hearth Nov 24 '19 at 18:05
1
\$\begingroup\$

You need to provide MUCH more information to get any definitive direction or solutions.

As already in the comments you have a Common Anode RGB LED. Here is the datasheet for an example RGB leaded LED. Notice in this datasheet that both the Blue and Green LED have a minimum Vf of 3.3V so are unlikley to work on a 3.3V I/O pin at all.

Consider the following:

  1. You CANNOT drive this LED directly from an R'Pi. The Blue LED is likely at least 3.4V Vf so will be very dim driven from 3.3V I/O. Green can also have a high Vf and be unsuitable for 3.3V drive.

  2. The LED current becomes a critical factor. The R'Pi I/O should not be used to source or sink high current. It's likely that your LED is at least 20mA per color and it is inadvisable to source or sink this level of current from your MCU.

  3. To control the three colors independently you need THREE PWM pins, one for each color.

To drive this LED you can use the 5V supply, but you CANNOT drive this directly from the I/O pins. You will need a buffered circuit such as this:

schematic

simulate this circuit – Schematic created using CircuitLab

The values of R1,2,3 will depend on the required current for your LEDs and the on resistance of the FETs. You may be able to get away without these resistors if the FET on resistance is high enough (though you'd have to measure these parameters to do this). You could of course use a very similar circuit based on BJTs, but would need to provide base resistors to limit the base current.

\$\endgroup\$
0
\$\begingroup\$

I finally have a solution now. As Hearth already mentioned in the comments, I just had to connect the long lead of my anode LED to 3.3V. The other leads had to be connected to three RaspberryPi pins, with a resistor in series, which were set to output with a PWM signal. But you have to invert the PWM signal.

Below you can see my final circuit.

Circuit

I tested it with my Raspberry and it worked.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ It certainly works, but be careful about that. Although I couldn't find any official doc about it, the RPi apparently has an output source/sink current rating of 16mA, and it seems you have calculated your resistors for limiting the current at about ~10-20mA (depending on the LEDs Vf). This will put a lot of stress on the hardware. Doing it this way is fine if you plan for just a few mA of current through the LEDs, but at your levels, I would use a transistor just as Jack shown in his answer. \$\endgroup\$ – dim Nov 25 '19 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.