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


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.

Electrify your mind

A few weeks ago a colleague sent me this link, partly as a joke. So, in return - again, partly as a joke - I thought I'd make him one.

Transcerebral Direct Current Stimulation is one of those scary phrases that conjures up images of white tiled Victorian hospitals with an overpowering smell of bleach, but apparently it's all the rage. In the last few months there has been an article in New Scientist and a couple of posts to Boing Boing so it's not going to be instantly fatal.

tDCS Stripboard Photo

The circuit itself is simply a LM317 configured as a constant current source set to 1mA, with a LED battery test function. By choosing a 1k ohm current limiting resistor for the test LED I was hoping that it would be a helpful feature, but, unfortunately, it still lights reasonably brightly even when Vbatt is down at 3v. This means that it's not very useful as a battery test, meh.

tDCS Circuit Diagram
(Order of SW1, R1 and D1 may vary, but it doesn't matter)

A more useful battery test feature would be to turn on the LED when Vout approaches (Vbatt - Vdo), as this would be the point that the battery is no longer providing enough voltage to maintain 1mA through the probes.

Measuring the output current using the internal resistance (tiny) of my multimeter it was reading 1.02mA - and a very low resistance load is a worst case for compliance, so I'm happy that it is to specification.

So, Mr S. if you do actually try using this, please don't turn yourself into either a superhero or a vegetable, I'll never hear the end of it.

High Sleeper cabin bed lights - The LEDs

So when we got a high sleeper cabin bed in our house a few months ago, it turned out to be a bit dark underneath. So what does a good honest electronics geek of a dad do? Install LEDs of course.

I found, on the delightful treasure trove that is ebay, whole strings of surface mount LEDs on self-adhesive strips. Like these

At five metres long, this is good enough to go around the two long sides and one short side of a standard bed frame, underneath the highbed lighting up the play area underneath. Included on the strip with the LEDs are the right resistors to act as the current limiting element. This means that you can wire this up directly with a standard 12v PSU. To run the whole 5 metre length you need 24W PSU (capable of delivering 2A @12v ... P=VI, remember?)

If you don't want to use the whole length of the strip, or can't fit it into the space you need, it has marked cut points every 40mm (or 3 LEDs) along the whole length. Below you can see two sections with the cut mark in the middle.

Because we now have 300 individual LEDs spread out evenly, the light underneath is beautifully flat and shadow free. It's almost like florescent light, without the annoying flicker and breakable tubes.

Now, the next obvious step is to hook this up to an arduino and build a dimming control.