You are on page 1of 14

Tutorial 74HC4067 16-Channel Analog Multiplexer Demultiplexer http://tronixstuff.com/2013/08/05/part-review-74hc4067-16-channel-an...

tronixstuff fun and learning with electronics

Home
Tronixlabs
Kit Reviews
Reviews
About
Contact Us

Categorized | 74HC4067, arduino, Demultiplexer, Multiplexer, part review, review,


tronixstuff, tutorial

Tutorial 74HC4067 16-Channel Analog Multiplexer


Demultiplexer
Posted on 05 August 2013. Tags: 4067, 74HC4067, arduino, demultiplexing, multiplexing, part, review,
tronixstuff, tutorial

Introduction

Now and again theres a need to expand the I/O capabilities of your chosen micorocontroller, and instead
of upgrading you can often use external parts to help solve the problem. One example of this is the
74HC4067 16-channel analog multiplexer demultiplexer. Thats a mouthful however in simple form its
an IC that can direct a flow of current in either direction from one pin to any one of sixteen pins. Another
way to think abou it is that you can consider the 74HC4067 to be a digital replacement to those rotary
switches that allow you to select one of sixteen positions.

Heres an example of the SMD version:

Dont let that put you off, its just what we had in stock at the time. The part itself is available in

1 de 14 24/11/2016 0:53
Tutorial 74HC4067 16-Channel Analog Multiplexer Demultiplexer http://tronixstuff.com/2013/08/05/part-review-74hc4067-16-channel-an...

through-hole and surface mount versions.

Using the 74HC4067

At this point you should download the data sheet, as we refer to it through the course of the article. The
first thing to note is that the 74HC4067 can operate on voltages between 2 and 6V DC, which allows use
with 3.3V and 5V microcontrollers and boards such as Arduino and Raspberry Pi. If for some reason you
have the 74HCT4067 it can only work on 4.5~5.5V DC. Next consider the pinout diagram from the
data sheet:

The power supply for the part is


applied to pin 24, and GND to pin 12. Pin 15 is used to turn the control the current flow through the
inputs/outputs if this is connected to Vcc the IC stops flow, and when connected to GND it allows flow.
You can always control this with a digital output pin if required, or just tie it to GND if this doesnt matter.

Next pin one. This is where the current either flows in to be sent to one of the sixteen outputs or where
the current flows out from one of the sixteen inputs. The sixteen inputs/outputs are labelled I0~I15. Finally
there are the four control pins labelled S0~S3. By setting these HIGH or LOW (Vcc or GND) you can
control which I/O pins the current flow is directed through. So how does that work? Once again reach for
the the data sheet and review the following table:

2 de 14 24/11/2016 0:53
Tutorial 74HC4067 16-Channel Analog Multiplexer Demultiplexer http://tronixstuff.com/2013/08/05/part-review-74hc4067-16-channel-an...

Not only does it show what happens


when pin 15 is set to HIGH (i.e. nothing) it shows what combination of HIGH and LOW for the control
pins are required to select which I/O pin the current will flow through. If you scroll down a bit hopefully
you noticed that the combination of S0~S3 is in fact the binary equivalent of the pin number with the
least significant bit first. For example, to select pin 9 (9 in binary is 1001) you set the IC pins S0 and S3 to
HIGH, and S1 and S2 to LOW. How you control those control pins is of course up to you either with
some digital logic circuit for your application or as mentioned earlier with a microcontroller.

Limitations

Apart from the power supply requirements, there are a few limitations to keep in mind. Open you data
sheet and consider the DC Electrical Specifications table. The first two parameters show what the
minimum voltage that can be considered as a HIGH and the maximum for a LOW depending on your
supply voltage. The next item of interest is the ON resistance that is the resistance in Ohms ()
between one of the sixteen inputs/outputs and the common pin. When a channel is active, and a 5V supply
voltage, we measured a resistance of 56 without a load through that channel and the data sheet shows
other values depending on the current load and supply voltage. Finally, dont try and run more than 25 mA
of current through a pin.

Examples

Now to show an example of both multiplexing and demultiplexing. For demonstration purposes were
using an Arduino Uno-compatible board with the 74HC4067 running from a 5V supply voltage. Pin 15 of
the 4067 is set to GND, and control pins S0~S3 are connected to Arduino digital output pins D7~D4

3 de 14 24/11/2016 0:53
Tutorial 74HC4067 16-Channel Analog Multiplexer Demultiplexer http://tronixstuff.com/2013/08/05/part-review-74hc4067-16-channel-an...

respectively.

Multiplexing

This is where we select one input pin of sixteen and allow current to flow through to the common pin (1).
In this example we connect the common pin to the boards analog input pin so this can be used as a
method of reading sixteen analog signals (one at a time) using only one ADC. When doing so take note
of the limitations mentioned earlier take some resistance measurements in your situation to determine
what the maximum value will be from your ADC and calibrate code accordingly.

With both of the examples well use port manipulation to control the digital pins which are connected to
the 74HC4067s control pins. We do this as it reduces the code required and conceptually I feel its easier.
For example to select I/O 15 you need to turn on all the control pins so you just have to set Arduino
PORTD to B11110000 (which is binary 15 LSB first) and much neater than using four digitalWrite()
functions.

In the following example sketch, you can see how weve put the binary values for each control possibility
in the array byte controlPins[] which is then used to set the pins easily in void loop().

This simply sets each input pin in turn, then reads the ADC value into an array whose values are then
sent to the serial monitor:

1 // 74HC4067 multiplexer demonstration (16 to 1)


2
3 // control pins output table in array form
4 // see truth table on page 2 of TI 74HC4067 data sheet
5 // connect 74HC4067 S0~S3 to Arduino D7~D4 respectively
6 // connect 74HC4067 pin 1 to Arduino A0
7 byte controlPins[] = {B00000000,
8 B10000000,
9 B01000000,
10 B11000000,
11 B00100000,
12 B10100000,
13 B01100000,
14 B11100000,
15 B00010000,
16 B10010000,
17 B01010000,
18 B11010000,
19 B00110000,
20 B10110000,
21 B01110000,
22 B11110000 };
23
24 // holds incoming values from 74HC4067
25 byte muxValues[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,};
26
27 void setup()
28 {
29 Serial.begin(9600);
30 DDRD = B11111111; // set PORTD (digital 7~0) to outputs
31 }
32
33 void setPin(int outputPin)
34 // function to select pin on 74HC4067
35 {
36 PORTD = controlPins[outputPin];
37 }
38
39 void displayData()
40 // dumps captured data from array to serial monitor
41 {
42 Serial.println();

4 de 14 24/11/2016 0:53
Tutorial 74HC4067 16-Channel Analog Multiplexer Demultiplexer http://tronixstuff.com/2013/08/05/part-review-74hc4067-16-channel-an...

43 Serial.println("Values from multiplexer:");


44 Serial.println("========================");
45 for (int i = 0; i < 16; i++)
46 {
47 Serial.print("input I");
48 Serial.print(i);
49 Serial.print(" = ");
50 Serial.println(muxValues[i]);
51 }
52 Serial.println("========================");
53 }
54
55 void loop()
56 {
57 for (int i = 0; i < 16; i++)
58 {
59 setPin(i); // choose an input pin on the 74HC4067
60 muxValues[i]=analogRead(0); // read the vlaue on that pin and store in array
61 }
62
63 // display captured data
64 displayData();
65 delay(2000);
66 }

and a quick video of the results:

Demultiplexing

Now for the opposite function sending current from the common pin to one of sixteen outputs. A fast
example of this is by controlling one of sixteen LEDs each connected to an output pin, and with 5V on the
74HC4067 common pin. We dont need current-limiting resistors for the LEDs due to the internal
resistance in the 74HC4067. Heres the sketch:

1 // 74HC4067 demultiplexer demonstration (1 to 16)


2
3 // control pins output table in array form
4 // see truth table on page 2 of TI 74HC4067 data sheet
5 // connect 74HC4067 S0~S3 to Arduino D7~D4 respectively
6 // 5V to 74HC4067 pin 1 to power the LEDs :)
7 byte controlPins[] = {B00000000,
8 B10000000,
9 B01000000,
10 B11000000,

5 de 14 24/11/2016 0:53
Tutorial 74HC4067 16-Channel Analog Multiplexer Demultiplexer http://tronixstuff.com/2013/08/05/part-review-74hc4067-16-channel-an...

11 B00100000,
12 B10100000,
13 B01100000,
14 B11100000,
15 B00010000,
16 B10010000,
17 B01010000,
18 B11010000,
19 B00110000,
20 B10110000,
21 B01110000,
22 B11110000 };
23
24 void setup()
25 {
26 DDRD = B11111111; // set PORTD (digital 7~0) to outputs
27 }
28
29 void setPin(int outputPin)
30 // function to select pin on 74HC4067
31 {
32 PORTD = controlPins[outputPin];
33 }
34
35 void loop()
36 {
37 for (int i = 0; i < 16; i++)
38 {
39 setPin(i);
40 delay(250);
41 }
42 }

and the LEDs in action:

Conclusion

If youre considering the 74HC4067 or hadnt known about it previously, we hope you found this of
interest. If you have any questions please leave them below or privately via the contact page. And if you
made it this far check out my new book Arduino Workshop from No Starch Press.

6 de 14 24/11/2016 0:53
Tutorial 74HC4067 16-Channel Analog Multiplexer Demultiplexer http://tronixstuff.com/2013/08/05/part-review-74hc4067-16-channel-an...

In the meanwhile have fun and keep checking into tronixstuff.com. Why not follow things
on twitter, Google+, subscribe for email updates or RSS using the links on the right-hand column? And
join our friendly Google Group dedicated to the projects and related items on this website. Sign up its
free, helpful to each other and we can all learn something.

Bio

John Boxall
Founder, owner and managing editor of tronixstuff.com.

Like this:

2 bloggers like this.

Review adafruit industries Mini 88 LED Matrix with I2C backpack


Visualise microcontroller data with Megunolink Pro

13 Responses to Tutorial 74HC4067 16-Channel Analog Multiplexer


Demultiplexer

1. Bill Cahill says:


August 6, 2013 at 12:44 pm

Would an IC such as this be able to switch audio signals? If not this, is there an IC you would
recommend that would perform that function well?

Thanks!

Reply

John Boxall says:


August 6, 2013 at 1:40 pm

Not this one the internal resistance will affect the amplitude. Nothing springs to mind right
now but if youre only wanting A-B switching perhaps DPDT relays would do.

Reply

2. gunndo says:
August 7, 2013 at 9:24 am

Try in Analog or Maxim, video crosspoint switch or audio crosspoint.

7 de 14 24/11/2016 0:53
Tutorial 74HC4067 16-Channel Analog Multiplexer Demultiplexer http://tronixstuff.com/2013/08/05/part-review-74hc4067-16-channel-an...

They have nice ICs for switching audio and video.

Reply

3. kyr says:
August 9, 2013 at 8:13 pm

This CAN be used to switch audio.


You just have to respect the min max voltages and other characteristics of the device. Its not for
high power or hi-fi but it works.
Most CRT TVs use variants of the same device family (fewer channels: 4051/4052/4053) to switch
audio channels to scart/speakers, etc

Reply

4. Eimi says:
August 17, 2013 at 4:47 am

Hi, John.
Im trying to test Demux with an ARDUINO UNO and 74HC4067N but I cant.
Please, would you mind to check if the wiring I do is correct?

VCC Arduino to Pin 24 and


GDN Arduino to Pin 12
D7 Arduino to Pin 10 (S0)
D6 Arduino to Pin 11 (S1)
D5 Arduino to Pin 14 (S2)
D4 Arduino to Pin 13 (S3)
(-)leg of each LED to Pin 15 (E)
(+)leg of each LED to output pins (I0 I15)

Load the sketch but nothing happend.


Please, what is wrong?
Im copying the wiring schema from the video but I dont know if is right.
Thanks in advance.

Reply

John Boxall says:


August 17, 2013 at 10:13 pm

Dont connect the LED cathodes (-) pin to the 74HC4067, they should go to GND instead.
Also connect 5V for the LEDs to pin 1. Connect pin 15 to GND.

Reply

Eimi says:
August 17, 2013 at 10:33 pm

It works!!!, it works!!!
Great.
Thanks a lot for your attention and quickest help.

8 de 14 24/11/2016 0:53
Tutorial 74HC4067 16-Channel Analog Multiplexer Demultiplexer http://tronixstuff.com/2013/08/05/part-review-74hc4067-16-channel-an...

5. Eimi says:
August 22, 2013 at 5:40 am

Hi again, John.

Just a pair of doubts.

How must I do to turn off just one of the outputs?


(i.e. with SetPin(5), turn ON pin 5 but how to do to turn it OFF?)

Do you know if is possible to manage a 4-relay shield with this demux? (Arduino Uno -> demux ->
2 relay shields -> 8 solenoids)
If so, would you mind to tell me how must I do?

Thanks in advance.
Regards.

Reply

John Boxall says:


August 22, 2013 at 8:29 am

Only one output is selected at a time, you can turn it on/off using enable (pin 15). This
wouldnt be the part to control your relay shield. Try the MCP23017 or even a shift register.

Reply

6. Eimi says:
August 23, 2013 at 5:00 pm

OK, already understood


Will try to do with the MCP23017.

Thanks again.

Reply

7. Marcwolf says:
December 1, 2014 at 3:18 pm

Great idea, and just what I am needing. I have 16 very small resistive sensors, and have been
grappling with a way to read them without also needing to clog up space with a resistor to V+ for
each one to get a reading.
With this chip I need only to put the one side of the sensor to ground, and then read the output pin
(pulled to V+ via a 10k) for each sensor..
The project is a way to put sensors in the mouth that can be activated with a tongue.. so space is
CRITICAL!!!
Many thanks
Marcwolf

Reply

9 de 14 24/11/2016 0:53
Tutorial 74HC4067 16-Channel Analog Multiplexer Demultiplexer http://tronixstuff.com/2013/08/05/part-review-74hc4067-16-channel-an...

John Boxall says:


December 1, 2014 at 4:07 pm

Thank you for your feedback, its nice to hear someone is doing something useful.
Tongue sensor? Have fun

Reply

marcwolf says:
December 1, 2014 at 4:14 pm

Yep.. Tongue Sensor. For example many people wear false teeth that have a palette
shield that sits in the roof of the mouth. So why not use the same idea to mount a simple
shield up there and control things with your tongue when your hands are busy. You can
talk as well.
Even put a small joystick up there so you can control a wheel chair.. or animatronics in
a costume, or change a channel on a radio when you are climbing somewhere and
cannot use your hands.
Lots of possibilities but first find ways of very low profile sensors and I am using the
Force Sensor Resistors 0.2 diam.
Thanks for the reply
Marcwolf

Trackbacks/Pingbacks

Leave a Reply

Name (required)

Mail (will not be published) (required)

Website

Notify me of follow-up comments by email.

Notify me of new posts by email.

Visit tronixlabs.com

10 de 14 24/11/2016 0:53
Tutorial 74HC4067 16-Channel Analog Multiplexer Demultiplexer http://tronixstuff.com/2013/08/05/part-review-74hc4067-16-channel-an...

Helping you make it with Australia's best value for supported hobbyist electronics from adafruit, Altronics,
DFRobot, Freetronics, Pololu and more!

Subscribe via email

Receive notifications of new posts by email.

Search the site

tronixstuff forum

Why not join our moderated discussion forum?


CH340G USB 2.0 a RS232
COM del Puerto Serie de $
...
1,04
Buy Now

Nueva Caliente 1/24


Velocidad de Deriva
telediri...
4,68
Buy Now

1/24 Drift velocidad Radio


Remote control RC RTR
ca...
5,04
Buy Now

es.aliexpress.com

Arduino Tutorials

Click for Detailed Chapter Index

Chapters 0 1 2 3 4

11 de 14 24/11/2016 0:53
Tutorial 74HC4067 16-Channel Analog Multiplexer Demultiplexer http://tronixstuff.com/2013/08/05/part-review-74hc4067-16-channel-an...

Chapters 5 6 6a 7 8
Chapters 9 10 11 12 13
Ch. 14 - XBee
Ch. 15 - RFID - RDM-630
Ch. 16 - Ethernet
Ch. 17 - GPS - EM406A
Ch. 18 - RGB matrix - awaiting update
Ch. 19 - GPS - MediaTek 3329
Ch. 20 - I2C bus part I
Ch. 21 - I2C bus part II
Ch. 22 - AREF pin
Ch. 23 - Touch screen
Ch. 24 - Monochrome LCD
Ch. 25 - Analog buttons
Ch. 28 - Colour LCD
Ch. 29 - TFT LCD - coming soon...
Ch. 30 - Arduino + twitter
Ch. 31 - Inbuilt EEPROM
Ch. 32 - Infra-red control
Ch. 33 - Control AC via SMS
Ch. 34 - SPI bus part I
Ch. 35 - Video-out
Ch. 36 - SPI bus part II
Ch. 37 - Timing with millis()
Ch. 38 - Thermal Printer
Ch. 39 - NXP SAA1064
Ch. 40 - Push wheel switches
Ch. 40a - Wheel switches II
Ch. 41 - More digital I/O
Ch. 42 - Numeric keypads
Ch. 43 - Port Manipulation - Uno
Ch. 44 - ATtiny+Arduino
Ch. 45 - Ultrasonic Sensor
Ch. 46 - Analog + buttons II
Ch. 47 - Internet-controlled relays
Ch. 48 - MSGEQ7 Spectrum Analyzer
First look - Arduino Due
Ch. 49 - KTM-S1201 LCD modules
Ch. 50 - ILI9325 colour TFT LCD modules
Ch. 51 - MC14489 LED display driver IC
Ch. 52 - NXP PCF8591 ADC/DAC IC
Ch. 53 - TI ADS1110 16-bit ADC IC
Ch. 54 - NXP PCF8563 RTC
Ch. 56 - MAX7219 LED driver IC
Ch. 57 - TI TLC5940 LED driver IC
Ch. 58 - Serial PCF8574 LCD Backpacks
Ch. 59 - L298 Motor Control
Ch. 60 - DS1307 and DS3231 RTC part I

The Arduino Book

12 de 14 24/11/2016 0:53
Tutorial 74HC4067 16-Channel Analog Multiplexer Demultiplexer http://tronixstuff.com/2013/08/05/part-review-74hc4067-16-channel-an...

Fr unsere deutschen Freunde

Dla naszych polskich przyjaci ...

13 de 14 24/11/2016 0:53
Tutorial 74HC4067 16-Channel Analog Multiplexer Demultiplexer http://tronixstuff.com/2013/08/05/part-review-74hc4067-16-channel-an...

Australian Electronics!
Buy and support Silicon Chip - Australia's only Electronics Magazine.

Interesting Sites

Amazing Arduino Shield Directory


David L. Jones' eev blog
Silicon Chip magazine Always a great read!
Talking Electronics
Dangerous Prototypes
The Amp Hour podcast
Superhouse.tv High-tech home renovation

Use of our content

tronixstuff.com by John Boxall is licensed under a Creative Commons Attribution-NonCommercial-


ShareAlike 4.0 International License.

14 de 14 24/11/2016 0:53

You might also like