port expander 4051 question

Hi guys,

due to the lack of hardware I have a question regarding the expanding of i/o ports of the Arduino with a 4051.

Requirements:
6x output pins for driving 6 relays (there's a uln2803 between the 4051 and the relays)
6x input pins for reading a dip switch with 6 toggles in one enclusure
1x LCD

I managed to get the relays working using the example code here. Right now I have no second 4051 but is it possible to use two 4051 (one for output one for input) with only 3 select lines? I still dont understand why the example in playground uses 6 select lines.

I thought of using

  • 3 pins on arduino as select lines connected to both 4051
  • 1 pin on arduino to connect to z of chip "b" for reading the dip switch
  • 2 pins on arduino as enable line for choosing either chip "a" or "b" (either write "a" or read "b")

To drive the relays I enable chip "a" and select the proper output.
To read the dip switch I enable chip "b" and cycle through the pins always reading z.
Is this possible or is there an easier way to get around this with as few arduino pins as possible?

Cheers ~mrfop

In the example code, the 4051 devices are multiplexing their way through KEY-PRESS combinations. Sequentially enabling COLUMN 1,2,3,4..8 while reading ROW 1, and then doing the same sequence again with columns while reading with ROW 2... etc. This means that the pair of 4051 must be selected by a difference pin set as they are controlled differently

This device can only enable 1 of the 8 pins for read/write mode at any given time... so it really does not make a good choice as a port expander. It is quite useful though as a keyboard matrix decoder which is why you see it in the playground example.

So, in your case... you would only be able to turn 1 relay on at a time. Is that your goal?

Thank you for the explanation. I want to turn more than one relay on at a time. I didn't thought about it...
What other parts can be used as a port expander? I have a few 74hc57381 around maybe they will work for that.

Normally, shift registers are used for this... like the common 74HC595, though other serial in/parallel out shift registers can be used.

I'm, sorry. I don't know what a 74hc57381 is.

Ok I'm going to tinker around with shift registers.
It's a 74hc573b1 I mistyped it.

The 74hc573 is an octal latch, you can't use it as a shift register. Look for 74xx595, of if you want to drive relays directly try the TPIC6B595.


Rob