I built a simple clock using a 4 digits 7 segments LCD display. I display one digit at a time, switching on and off very quicky and cycling through digits.

Everything is ok, but I used 8 + 4 = 12 arduino pins. I need 2 more pins for other features and I don't want to use 0 and 1 as I need onboard programming features of Arduino Mini.

I used I2C for RTC clock, I could add some interface here (like a PCF8574) and get some pins from here. But I'd like a different (and more educational, for me) approach.

Is there an IC that sends an HIGH output on one of four output pins driven by 2 input pins? I need this:

IN     OUT
P0 P1  D0 D1 D2 D3
0  0   1  0  0  0
0  1   0  1  0  0
1  0   0  0  1  0
1  1   0  0  0  1

This way I can connect OUT to digit selection and spare 2 pins.

Thanks for your hints.


A 2-to-4 line decoder should do what you need. I've used a 74HC139 with Arduino before, which contains two decoders in a 16-pin DIP.

There are lots of other options though. In the past, I've used an 8 bit serial-to-parallel shift register (74HC595) to control a 7 segment display. It effectively lets you control 8 (or more) outputs using only 3 pins on your microcontroller. You have to be careful of power requirements though. Most shift registers aren't able to drive such a display directly, but I was able to incorporate transistors quite easily to get around that.

  • I already have transistors for driving digits as there could be up to 8 segments lit (7 segments + dot). I guess I need to add 74HC139 before transistors and let it operate with low current. Thanks for your precious hint! – Ghigo Mar 31 '14 at 13:09
  • With 74HC595 solution I would need a transistor per segment, right? This could become complex with 32 transistors. I'd go for 74HC139 solution. – Ghigo Mar 31 '14 at 13:13
  • @Ghigo - Since you're only displaying one digit at a time, you should only need 8 transistors for the segments. – Peter Bloomfield Mar 31 '14 at 13:23
  • In this case I need to put 74HC595 after transistors. Some current will flow there. From datasheet I see 20mA is the limit when switching. Is this correct? – Ghigo Mar 31 '14 at 13:28
  • 1
    @Ghigo - You can connect the Arduino directly to the 595 without any difficulty. The transistors should go between that and the display. Each output on the 595 can usually only manage around 6mA on its own at 5V. – Peter Bloomfield Mar 31 '14 at 13:38

Are you using your analog pins? Did you know they can be used as digital pins?

The analog pins can be used identically to the digital pins, using the aliases A0 (for analog input 0), A1, etc. For example, the code would look like this to set analog pin 0 to an output, and to set it HIGH:

pinMode(A0, OUTPUT);
digitalWrite(A0, HIGH);

This is your best bet if you aren't using all your analog pins.

  • Inreresting. I have 2 unused analog pins I can try to use them for display as I require a pwm pin. Never tried this – Ghigo Apr 1 '14 at 10:55
  • +1 for referencing them by their analog assignment (A0) instead of digital (14) et al which isn't always correct. – Madivad Apr 4 '14 at 6:11

I know it's not what you asked, but you're using a lot of pins, why not try streamlining them and go to an I2C backpack? This one from adafruit includes a single 4x7 segment display.

given your comment, another option would be an I2C/SPI 7 Segment driver. (datasheet).

new edit: Actually, when I posted the above 7 segment driver, this is the one I was thinking of. I don't know why I didn't find this the first time.

max7219/7221 datasheet and digikey source:

  • Thanks for the hint. My display is bigger than this and I wanted a more educational approach. I would like to keep display driver part directly on Arduino as I already have implemented automatic brightness control with a photoresistor and some lines of code. – Ghigo Mar 31 '14 at 13:53
  • @Ghigo I just posted an update for a 7 segment driver that may be of use as well. – Madivad Mar 31 '14 at 14:17
  • It says no longer manufactured, but there are clones. Interesting approach. – Ghigo Mar 31 '14 at 14:24
  • I don't know why I posted that first driver, that's not the one I have here. I have one of these on a breakout board with 8 x 7 segment displays. Works a treat! – Madivad Apr 4 '14 at 5:56

An I2C IO expander might be your best bet. If your existing I2C device uses a different address, you may be able to put both devices on the same I2C bus. You would then use 0 additional pins compared to your current design.

  • Just noticed you've already considered this approach - I'm gonna leave this here anyway for other folks reading too speedily. – John Walthour Mar 31 '14 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.