# Coding 74HC4051 Multiplexing

Goal: to just light up a bunch of LEDs using push buttons. I have 8 push buttons and 8 leds. (I'm using the 74HC595 to drive the leds) So if I push PB1, I'd only like the first LED to light up and the other 7 off. If i push PB2, only LED2 is on, rest is off..etc.

So I'm using the 74HC4051 to help me control my inputs (multiplexing). I just have some questions about the chip and how to approach the code.

Pin 3 on the 4051 (Z common output or input),, what do I have to use that for? I was reading other articles and they say to put it on A0 on the Arduino. But then I don't know how to utilize it in my code. I'd like to use IF statements, just a fyi

I understand that if s0 = HIGH, s1 = LOW, s2 = LOW, it will activate Y1 on my push button.
so how do i like write that in my code?

should i be making like different functions? or idk?

Thanks!

I don't understand how Z works?

The link Nick posted has all the info you'll need. See the diagram under 'Suggested Wiring'. Looking at the diagram, Z, I/O common, or pin 3, is at the state that pins A/B/C address. If A/B/C were at 0,0,0, then pin 13 is being addressed, and that data is on the Z pin. If A/B/C were 0,1,0, then pin 15 would be addressed and that data is on the Z pin. Since the device is bi-directional, Z will show up on whatever pin you're addressing as well - as I understand it. Hope that helps.

Don't know how familiar you are with reading datasheets, but sometimes different manufacturers have different names for the same pins/functions. Makes it difficult sometimes.

m0ntah:
I don't understand how Z works?

From my diagram (did you look at it?):

Depending on the voltages on A/B/C (pins 11/10/9) the chip provides a low-resistance path between the selected I/O pin and the "Z" pin (labelled O/I above).

Thanks guys! that helps a lot!

just one more question, what about daisy chaining them? and as far as the addresses goes? if i daisy chained two together?

or how would i control the second chip?

thanks!

The implementation and design follows directly from the function. It's an analog switch, so you can interconnect them. But they are not one in, one out devices. So I'm not sure what you mean by daisy chaining. If you connect one devices common input to one of the other one's outputs, you'd get 7+8 = 15 I/O's.

m0ntah:

Since one chips has one "output" you could connect that to A0, and have a second chip connected to A1, and so on. You would also need to connect the A/B/C pins but I don't see any reason why (if you only sampled one at a time) that they could not be connected in parallel.

I guess what I'm trying to say is how am i able to control the second set of push buttons with the second 4051?

I get that I can connect A/B/C of the 2nd 4051 chip to the A/B/C lines of the 1st 4051 chip.

I already have Z of the 1st chip to a digitalPin on my arduino so where would I connect the Z of the 2nd chip so that basically it can be reading all 16 lines?

But Nick i think I'll try and do what you suggested!

-sam

m0ntah:
I already have Z of the 1st chip to a digitalPin on my arduino so where would I connect the Z of the 2nd chip so that basically it can be reading all 16 lines?

To another digital pin on your Arduino.