For the LED stairs, I need to control 14 LED lamps and 2 sensors. From the beginning, I had in mind an Arduino as the microcontroller for this project. Although it is possible to do a primitive version of these stairs without a microcontroller, having a brain at the center gives many more options. And a basic Arduino is (relatively) inexpensive. The Arduino Pro Mini, which I am planning to use, is only $19.
The Pro Mini has 14 digital input/ouput pins. Each output pin can produce 5V and up to 40mA. This is more than enough for a single LED. But I will be using LED lamps that require 12V. We don’t have enough power.
Antoher issue: these pins need to control all the LED lamps plus the sensors. And if you want to do any debugging, 2 of them need to be reserved for serial communication. We don’t have enough pins.
I was able to come up with solutions to these problems. It occurred to me that the need for “more pins, more power” must be a pretty common one for micrcontroller projects in general and this might be useful for other people to know.
How to add output pins
The simplest way to increase the number of ouput pins is just to buy a bigger board. The Arduino Mega provides a whopping 54 output pins. But it will cost you: the Mega is $50. And unlike the basic Arduino, you are limited in your choices regarding form factor and input power. It’s big with lots of deluxe options and that’s what you get.
The way around this is to use the Arduino to talk to another chip, called a shift register. An example of this is the 74HC595. The Arduino takes a few pins to talk to the shift register, which has 8 output pins of its own. The Arduino tells it which ones to turn on and off. Even better, the shift registers can be daisy chained so that one Arduino can talk to multiple shift registers without using any more Arduino pins.
This does increase programming complexity because the Arduino must talk to the shift register in a specified protocol. Fortunately, there is code out there that other people have written (this is the nice thing about using a popular platform). There is an excellent tutorial on the Arduino site called ShiftOut. There is a lot of stuff on the the site but it can be very hard to find, and that was true here.
As for cost, a 74HC595 will cost $0.35 or less…much cheaper than upgrading to a Mega!
How to increase output power
I already knew the answer here: add a transistor. The output pin switches a transistor which can be used to carry much greater current and voltage. The question is, the best way to implement this. I already had a painful experience in building my Speed Vest. In order to drive the electrolumincescent wire, it was necessary to switch high voltage, AC power. For that project I blindly followed the authors’ design and soldered 13 triacs in point-to-point wiring on an Arduino shield. That was not an experience I wanted to repeat.
Integrated circuits are all about packaging transistors together, right? I should at least be able to find a chip where they shared a common input voltage and ground, which would reduce the number of connections required by a factor of 3. And if it includes the protective diodes, even better. There is a famous chip that does this, called the ULN2803A. It has eight Darlington array transistors and is designed to be controlled by the 5V logic the Arduino uses. Since there is one pin for each transistor, no programming is required.
For a nice overview of this topic, see this article on using microcontrollers with switching transistors.
Cost of the ULN2803A? I got it at Arrow for $0.51.
Doing both at once
So far so good. We could take care of everything by adding 2 shift registers and 2 Darlington arrays. Pretty good but more components than I’d like. Is it possible to find a chip to do both tasks at once? Yes.
More knowledgable readers may already be wondering about LED matrix drivers. Using an Arduino to talk to sets of LEDs is a very common task and there are no shortage of articles on this. There are some nice libraries that have been developed too. In general they were not suitable for this project because despite the word “LED” I am seeking to drive higher power devices — LED lamps. Also, the matrix paradigm imposes certain requirements as far as connections and addressing that weren’t relevant here and that I preferred to avoid.
Eventually though I found the right kind of LED driver: the M5451. It can handle 12V power and can control 35 devices with a unified brightness control. Although the brightness control isn’t required here, it is a nice feature; the right type of signal — pulse-width modulated – can extend the life of the LEDs.
Next step, find code that allows the Arduino to talk to the M5451. (I am not that interested in writing device drivers.) Fortunately this chip is used by the Lightuino, which is an open-source project that (with some modification) has the code I need.
Cost of the M5451 (also listed as MM5451 at some suppliers): $3.15.
Although the M5451 should do everything I need, I’ve ordered the other two chips as well just to see how each option works. I suspect they will be useful for future projects too. Can’t wait until everything shows up and I can start breadboarding!