Saturday, May 19, 2012

High Sleeper cabin bed lights - Driving the LED chain

In previous posts (part one and part two), I've been talking about running 5m of LED strip light under a child's cabin bed to illuminate the play area. Here we are going to talk about how we are driving the full LED chain from our little microprocessor.

For testing purposes, in the previous circuit, we only included a single LED. This single LED was setup to only draw around 1.5 mA, as this was all it needed. The output pins of the microprocessor are rated to around 20mA - anymore than this and you are going to destroy the chip and have to throw it away. The 5m LED string draws around 2A - about 100x the pin rating - so we need to find another way to connect it to the microprocessor.

The way to do this is very straight forward - you use a transistor. In this case I have chosen a "metal oxide semiconductor field effect transistor" or MOSFET. These are a good choice for this circuit for a couple of reasons. Firstly, they have a nice high current rating (often into the 10's if not 100's of amperes) and, secondly, they can be driven from the logic level output of the microprocessor without the need for an interface circuit.

So, here's our plan

MOSFET LED Switch

The rest of the circuit from previous has not changed apart from replacing the LED and resistor.

The three pins of the MOSFET are called the Gate (the one on the left), the Source at the bottom, and the Drain at the top.

In our case, we are using the MOSFET as a switch, so it can be in one of two states. When the OC0A pin is low it is open, it does not allow current to flow between Drain and Source. Conversely, when the OC0A is high the switch is closed and it allows all of the current to flow between Drain and Source.

The resistance from the gate to either the drain or the source is so high (to the order of 10MOhms) that it needs a pull down resistor to the source, otherwise we would get unpredictable results when the output pin is not driven. Here I've chosen a 1k resistor, but any value between that and 10k is fine. Without this you might see the LEDs flash on at power up while the microprocessor starts up before it pulls the output pin low.

 While the gate to source resistance is very high, it can also be thought of as a small capacitor somewhere in the 1000's of picofarads. The upshot of this is that, when the OC0A pin is set high, it would effectively be shorted to ground while the capacitor charged up. Therefore we add the 10R resistor to limit the inrush current this would cause. This also has the effect of creating an RC damper circuit, so it will slightly reduce the switching speed, but not by an amount that will affect us.

I could probably leave out the 10R resistor, as not having it will not detrimentally affect the action of the circuit.

No comments:

Post a Comment