How to add more digital output pins to an Arduio?

I was thinkg about making a simple project using my Aarduino board which makes 20-30 LED's turn off and on in such a way it would create a spiral effect, but I am confused how I would do this since normally I would attach each LED to its own digital pin and give it a on or off command at the correct time in the programming. However there are not 20-30 output pins on the Arduino board, so how would I do this?

Sorry if this is a stupid question but i am a bit of a nobee ;D

Search this site for shift register.

Latching multiplex chips like 74hc259 might be another option.

um are you able to show me a diagram of any kind? since I do not know what latching multiplex means? :)


Google "74hc259 data sheet" to see the latching multiplex logic. From what I've seen LED effects are usually done with the shift registers. The latching multiplex chips would be handy where the focus is in individual pin control where one would "set and forget" the individual pin until the next time it is desired to change the pin state. A shift register probably could be used to control a lot of latching chips if needed.

Point taken TchnclFl :) And I like the cool little animation as well :)

Does anybody know where is best to get some of those black chips?? I like doing LED projects and working with motors so don't know if that makes a different to which ones I want. Thanks :)

use I2C bus to expand IO port. you can use PCA9555 chip for this function. each PCA9555 can expand 16 digital IO ports.

Sorry to be a pain, but where can you buy these, I have googled it and did not seem to get any where? Thanks :)

Hi Samuel,

For PCA9555, I think you may find it in any electronic parts shop.
For me, because I’m in China, I can easily buy this part from internet (taobao), and it’s very cheap, it cost me less than 1 USD for each chip.

so I think maybe you can buy it from ebay.

Following is the breadboard test for this chip.

My PCA9555 is PCA9555D, it’s a SOP 24 chip, I used a SOP->DIP PCB to transform it to DIP24.

Following is the test code:

#include <Wire.h>

//  Address            0 1 0 0   A2 A1 A0
#define LED_ADDRESS 0x27 // Address for this PCA9555, you can cascade 8 PCA9555 on one I2C bus, which has diffrent address

#define REGISTER_OUTPUT 0x02 //P0 output register 0
#define REGISTER_CONFIG 0x06 //register 6 set P0 status.  0xffff for input,  0x0000 for output

//if you use P1 for output, please use following configuration.
#define REGISTER_OUTPUT 0x03 //P1 output register 1
#define REGISTER_CONFIG 0x07 //register 7 set P1 status.  0xffff for input,  0x0000 for output.

void setup()
  gpio_dir(LED_ADDRESS, 0x0000);//set P0  IO output

int bits=0;
void loop()

  bits %=8;
  gpio_write(LED_ADDRESS,bits); //write data

void gpio_dir(int address,int dir) 
  //  send 2 bytes data
  Wire.send(0xff & dir);  //  write 8bits data to P0 register
  Wire.send(dir >> 8);    //   write 8bits data to P1 register


void gpio_write(int address,int data) 

  //  send 2 bytes data
  Wire.send(0xff & data);  //  write 8bits data to P0 register
  Wire.send(data >> 8);    //  write 8bits data to P1 register


For detailed information, you may check the datasheet of PCA9555.
please google it:)

wish you find the best solution for your project~


Brilliant thanks for all you help :)

Samuel: Where are you (in the world)?

If you want to buy from the US, you could probably get pretty much anything you can imagine from vendors like DigiKey.

I live in the UK, Cornwall which is why I find it so hard to get cheap components :-/


I know there are UK suppliers, but I can't think of their names offhand (as I've never ordered from them).

I'm sure someone will see this thread who lives in the UK and be able to give you some suggestions.

There's nothing wrong with ordering from HK/China sellers, but it will take a while for delivery.

Yea hopefully someone will know of somewhere. And yes delivery time is a problem, I just bought 100 LED's and 100 resistors but the shipping could take up to 5 WEEKS!! Is one place, although Farnell are everywhere and I think the goods could come from any of their wharehouses.

Thanks very much, will have a little looky at the site later ;D