You are on page 1of 2

analog multiplexer/demultiplexer------------4051

A multiplexer or demultiplexer enable you to expand the in- and outputs on your Arduino board.
The 4051 is an 8 channel analog multiplexer / demultiplexer, thus:

*If you use the 4051 as a Multiplexer: You can choose between 8 different inputs and
select just one you wane read at the time.
*If you use the 4051 as a Demultiplexer you can choose between 8 different
outputs and select just one you wane write at the time.

Futher more is the 4051 able to work with analog values; in the case of Arduino you are able to
use analog Inputs with a voltage between o-5V and rout them to a AnalogIn Pin on your Arduino.

8 Analog Inputs 1 Analog Output

Selected
through 3 digital
Outpins from the arduino

To select the Pin we would like to read or write, we have to use the three Select Pins (S0, S1
and S2). Each of this pins have to be connected to one digitalOut Pin on the Arduino. Every pin
is representing a number (So = 1; S1 = 2; S2 = 4) and if we set one of this Select pins to HIGH
the curtained number the pin is representing will be transmitted to the 4051. For example:

*If S0 and S1 are HIGH and S2 is LOW pin y3 is selected (1+2+0 = 3).
*If S0 and S2 is HIGH and S1 LOW pin y5 is selected (1+0+4 = 5).

It is not possible to read or write more then one pin on the 4051 at the same time, because you
can just select one pin at the same time. But you can read and write this pins quit fast. There
is no delay needed between selecting and read or writing the pin.
4051
used as a
Multiplexer
4051
y0 s0
y4 1 16 Vcc
Select Inputs
y1 s1 3 DigitalOutPins
y6 2 15 y2 from the arduino
y2 s2
z 3 14 y1 Analog y3
y7 4 13 y0 Inputs
y4
y5 5 12 y3
y5
E 6 11 S0
y6
Vee 7 10 S1
y7 z Analog Output
gnd 8 9 S2 To a AnlogInPin
at the arduino
Pin configuration Logic symbol

Z ----- common input/output (connected to Arduino Input/Output)


E ----- enable input (active LOW) (connected to ground (gnd))
Vee --- negative supply voltage (connected to ground (gnd))
gnd --- ground (0 V)
S0-S2 - select inputs (connected to three arduino digitalOut Pins)
y0-y7 - independent inputs/outputs
Vcc --- positive supply voltage (5v) (edited) 2006 by tomek ness
for the arduino community <http://www.arduino.cc>

K3 - School of Arts and Communication <http://www.mah.se/k3>


fhp - University of Applied Scien <http://www.design.fh-potsdam.de>
4051
A1 y0 s0
A2 y1 s1
A3 y2 s2
A4 y3
A5 y4
A6 y5
A7 y6
A8 y7 z A

4 7
3 Digital-Out-Pin 6
4051
2 5
B1 y0 s0
B2 y1 s1
Vcc [5v]
B3 y2 s2

s0
s1
s2

z
B4 y3
Digital-In-Pin

4051
B5 y4

y0
y1
y2
y3
y4
y5
y6
y7
B6 y5
B7 y6
4051
B8 y7 z B A y0 s0 1 2 3 4 5 6 7 8

B y1 s1
C y2 s2
D y3
E y4
F y5
G y6
H y7 z AnalogInPin 4051
A y0 s0
B y1 s1
C y2 s2
4051 D y3
E y4
H1 y0 s0
F y5
H2 y1 s1
G y6
H3 y2 s2
H y7 z
H4 y3
H5 y4
GND
H6 y5
H7 y6
H8 y7 z H (c) björn wahlström and thomas ness for Re-Memorize - k3 / 2005

2 5
DigitalOutPin 3 DigitalOutPin 6
4 7

(c) björn wahlström and thomas ness for Re-Memorize - k3 / 2005

The left sketch above is an example how to use 9 multiplexer to read 64 analog Inputs just with
one Analog-In-Pin on the arduino. The right sketch above is an example how to use two 4051 (one
as demultiplexer and one as multiplexer) in a 8x8 Matrix to check 64 buttons or other digital
Inputs just with one digital-In-Pin on the arduino(in this setup you can just have two buttons
turned on at the same time).

/*
* codeexample for useing a 4051 * analog multiplexer / demultiplexer
* by david c. and tomek n.* for k3 / malmö högskola
*
*/

int led = 13; //just a led


int r0 = 0; //value select pin at the 4051 (s0)
int r1 = 0; //value select pin at the 4051 (s1)
int r2 = 0; //value select pin at the 4051 (s2)
int row = 0; // storeing the bin code
int count = 0; // just a count
int bin [] = {000, 1, 10, 11, 100, 101, 110, 111};//bin = binär, some times it is so easy

void setup(){

pinMode(2, OUTPUT); // s0
pinMode(3, OUTPUT); // s1
pinMode(4, OUTPUT); // s2
digitalWrite(led, HIGH);
beginSerial(9600);
}

void loop () {

for (count=0; count<=7; count++) {


row = bin[count];
r0 = row & 0x01;
r1 = (row>>1) & 0x01;
r2 = (row>>2) & 0x01;
digitalWrite(2, r0);
digitalWrite(3, r1);
digitalWrite(4, r2);
//Serial.println(bin[count]);
delay (1000); (edited) 2006 by tomek ness
} for the arduino community <http://www.arduino.cc>
}
K3 - School of Arts and Communication <http://www.mah.se/k3>
fhp - University of Applied Scien <http://www.design.fh-potsdam.de>