I would like to manage many LEDs from my Arduino - 12 or so - but I do not have the available digital pins to do this. Only one LED needs to be on at one time. Instead, I was hoping to control these with an analog pin. I was wondering if there is some sort of switch out there which can take an analog signal and, based on the value, direct a 5V current to a certain LED.
I realize that I could use a second Arduino for this, but I am trying to avoid that.
Thanks in advance for any help!
-
2Please check out this question: arduino.stackexchange.com/questions/117/… it contains many answers enumerating several different solutions to the problem.jfpoilpret– jfpoilpret2014年06月18日 05:08:46 +00:00Commented Jun 18, 2014 at 5:08
-
1It should be noted that analog input pins still only output digital signals; only the PWM capable pins can emulate analog signals and they are dispersed among the digital pins.BrettFolkins– BrettFolkins2014年06月19日 23:43:29 +00:00Commented Jun 19, 2014 at 23:43
3 Answers 3
You can accomplish this digitally with a device called a decoder. For example, the 74154 takes 4 inputs and maps those to one of 16 outputs (depending on the binary coding of the inputs). From the data sheet:
The 74HC154; 74HCT154 decoders accept four active HIGH binary address inputs and provide 16 mutually-exclusive active LOW outputs.
-
Great! I found even better results by searching for "demuliplexer". For instance, this page on the arduino site: playground.arduino.cc/Learning/4051 Thanks!Rip Leeb– Rip Leeb2014年06月18日 02:48:21 +00:00Commented Jun 18, 2014 at 2:48
If you have 4 pins available, you could use charlieplexing to selectively light up 12 led. charlieplexing
Alternatively you could use some IC. You could use the one Greg suggested.
Or you could use a shift-register. This requires only 2 or 3 pins, an will enable you to light up any one or more leds at the same time. Most have 8 outputs, but you can connect one to the other (daisychain), so with 2 shift-registers you can individually turn on/off 16 leds. You can easily control these using arduino's shiftOut
command.
You could also use a port-expander using I2C to talk to it. More complicated, and a bit more expansive. But also more powerful. It will require only 2 pins (A4, and A5).
You can use some of the analog pins to clock a shift register by defining them as a digital output. Also two of the analog pins are also defined as I2C depending on your code. You could use 2 PCF8574s or an PCF8575 expansion board and control it that way. They can be used as inputs and outputs any order you want. There are a lot of other chips you can use to do this. The reason I am suggesting this approach is later you will probably want to expand into other peripherals such as LCDs etc.