Driving RGB cc LEDs from 5V battery using FETs

Hey guys,

Trying to drive 50 color cycling RGB LED's at once. Obviously an arduino can't supply this much current so I thought I'd use a common 5V battery pack and do the color cycling using some FET's.

Components:

FET - FQP27P06 P-channel MOSFET
LED - RGB LED common cathode

The code I'm using: https://gist.github.com/jamesotron/766994

And just connecting the LED pins to the gate of the FET

Sketch attached. Couldn't find a battery pack in fritzing so just mentally replace the 2X AA's with a 5V li-ion pack.

For starters I'm just trying to nail this down with one color and one FET, will add the others once I figure this out.

Okay, now what's happening: When battery is connected and arduino is not powered (gate has no voltage) the light turns on, if I ground the base tab the light turns off. The FET also gets fairly warm to the touch. If I ground the base, then power the arduino and then remove the ground to the base, the LED performs as expected - slowly cycles in intensity.

Feels like I'm floating, but since the LED is common cathode I need the FET's to be on the positive side of the LED and they lose their reference to ground...

Thoughts?

Thanks for your help!

For context - I'm building a totem for a music festival which will be friggin epic.

Hi, this is how you post code on this forum:

const int redPin = 11;
const int greenPin = 10;
const int bluePin = 9;

void setup() {
  // Start off with the LED off.
  setColourRgb(0,0,0);
}

void loop() {
  unsigned int rgbColour[3];

  // Start off with red.
  rgbColour[0] = 255;
  rgbColour[1] = 0;
  rgbColour[2] = 0;  

  // Choose the colours to increment and decrement.
  for (int decColour = 0; decColour < 3; decColour += 1) {
    int incColour = decColour == 2 ? 0 : decColour + 1;

    // cross-fade the two colours.
    for(int i = 0; i < 255; i += 1) {
      rgbColour[decColour] -= 1;
      rgbColour[incColour] += 1;
      
      setColourRgb(rgbColour[0], rgbColour[1], rgbColour[2]);
      delay(5);
    }
  }
}

void setColourRgb(unsigned int red, unsigned int green, unsigned int blue) {
  analogWrite(redPin, red);
  analogWrite(greenPin, green);
  analogWrite(bluePin, blue);
 }

And images are better posted like this:

Can I just check something. When you say "base" or "base tab" you really mean the gate pin of the MOSFET? And when you say "connecting the LED pins to the gate of the FET" you mean the Arduino pins referred to as "redPin" etc. in the code?

When the Arduino is not switched on, and before you code starts running, the output pins are floating, so the mosfet gate is also floating. This can cause it to switch on or off or, more likely, part way between the two states at random. Attach a 10K between the MOSFET gate and either 5V or ground to stop it floating. Once the code is executing, the Arduino pin will be either high or low and the 10K will have no significant effect and can be left in place permanently. The 10K value is not critical and anything between 1K and 100K will do.

I am surprised that the MOSFET got warm, given that only a few mA could have been flowing. If it continues to get warm, it could be faulty/damaged, so try replacing it. Also check you have correctly identified the gate, source & drain pins for that model of MOSFET.

Hey Paul- thanks for the response and posting tips.

To clarify - when I say "base" I mean the metal tab with a hole through it on the top of the FET. And when I say connected the LED pins to the gate of the FET I mean, as you said, connecting the arduino pins - pin 9 in this case - to the gate of the FET.

Update: I added a 10K resistor between gate and ground - the LED still turns on when the arduino is not powered.

The pinout of the FET is G,D,S from left to right as shown.

Ok. I don't know what that tab is connected to and the data sheet does not say, so it may not be connected to any of the MOSFET pins, electrically, just thermally to the mosfet's chip. So connecting it to anything else is not intended by the manufacturers. Given the gate is floating, touching it with a finger could cause a random change, so the effects you saw don't mean anything important. Try that 10K resistor between the gate and 5V.

Okay, I tried doing the 10k between gate and 5V and same result. LED turns on without arduino power.

Interesting find, reversing the D and S gives proper performance when arduino is powered. Without arduino power it remains on.

Updated diagram

How do you mean "proper performance"? I thought you said that it was working before, once the Arduino started. What's different?

By "proper performance" I mean that the LED cycles in intensity. But the LED is still always ON even when the arduino is not powered, and you're correct this was happening before.

Taking a step back, maybe I should ask if what I'm expecting is what I'm designing for.

I'm expecting that with power from the battery connected and the arduino not powered, the LED should be off. When the arduino is then powered on, the LED should cycle in intensity until the arduino is powered off.

I'm a bit stumped. Connecting that 10K, either to 5V or ground, either one or the other, should have kept the LEDs off until the Arduino started. Your diagram shows a common ground between the Arduino and the mosfet. That's definitely true, isn't it? Also I think it's still worth trying another MOSFET, in case that one is faulty/damaged.

Yeah I've double checked the common ground...

I ordered some new MOSFET's we'll give those a try.

Thanks again I'll keep you updated.