Sunteți pe pagina 1din 8

[tutorial] MUX74HC4067 | codebender's blog http://blog.codebender.

cc/2014/01/30/mux74hc4067/
codebender (http://codebender.cc)

codebender's blog
(http://blog.codebender.cc/)
news and interesting stuff from the codebender
team

Recent [tutorial] MUX74HC4067


Posts
Posted on January 30, 2014 (http://blog.codebender.cc/2014/01
/30/mux74hc4067/) by Nick Lamprianidis (http://blog.codebender.cc/author
/paign10/) | 12 Replies (http://blog.codebender.cc/2014/01/30/mux74hc4067
[Developer says]
/#comments)
Automated testing
(http://blog.codebender.cc
/2016/08/05/developer-
says-automated-testing/)
Say Hello to Circuit
Playground!
(http://blog.codebender.cc
/2016/08/05/say-hello-
to-circuit-playground/)
[tutorial] How to use a
Magnetic Door Switch /
Sensor With Arduino
(http://blog.codebender.cc
/2016/08/04/tutorial-
how-to-use-a-magnetic-
door-switch-sensor-
with-arduino/)
[tutorial] How to Measure
LUX With Arduino
(http://blog.codebender.cc
/2016/08/03/tutorial-
how-to-measure-lux-with-
arduino/)
[Developer says] Creating
a slim page loader
(http://blog.codebender.cc
/2016/07/15/developer- MUX74HC4067 Tutorial (http://vimeo.com/85054916) from codebender
says-creating-a-slim- (http://vimeo.com/codebender) on Vimeo (https://vimeo.com).
page-loader/)
This is a tutorial on the MUX74HC4067 (https://github.com/pAIgn10
/MUX74HC4067) library.

Categories
Advanced Tutorials
(http://blog.codebender.cc
/category/advanced-
tutorials/)
Basic Tutorials
(http://blog.codebender.cc
/category/basic-tutorials/)
Developers say
(http://blog.codebender.cc
/category/developer-
says/)
Events
(http://blog.codebender.cc
/category/event-2/)
Features Recap (http://blog.codebender.cc/wp-content/uploads/2014/01
(http://blog.codebender.cc /project_zps8b2d4a42.png)
/category/features-
recap-2/) The name of the library refers to the IC that is on the
Analog/Digital MUX Breakout (https://www.sparkfun.com/products/9056)
Fun Times
(http://blog.codebender.cc from Sparkfun. This IC is a 16-channel analog multiplexer/demultiplexer.
/category/fun-times-2/) You can think of it as an SP16T (http://en.wikipedia.org
Tech Stuff /wiki/Switch#Contact_terminology) switch that is digitally controlled. You
(http://blog.codebender.cc position the switch by writing to the control pins and then you let the data
/category/news/) flow in either direction.

1 de 8 24/11/2016 0:48
[tutorial] MUX74HC4067 | codebender's blog http://blog.codebender.cc/2014/01/30/mux74hc4067/
codebender (http://codebender.cc)

(http://blog.codebender.cc/wp-content/uploads/2014/01
/sp16t_zps45e15bff.png)

You can use this module to increase the number of inputs and outputs on
your Arduino, since it only needs 6 or 5 pins to provide access to 16 data
lines. You could connect to these 16 lines sensors, buttons, transistors to
control relays, or even serial lines from other Arduinos.

(http://blog.codebender.cc/wp-content/uploads/2014/01
/mux_zpsb70bdc5d.png)

The SIG pin connects to any of the 16 channels, C0 C15 . S0 to S3 are


the control pins. You write to these pins a binary code, and the
corresponding channel is selected. For example, by writing 1010 to
S3 S2 S1 S0 , the C10 channel gets connected to the SIG pin.

(http://blog.codebender.cc/wp-content/uploads/2014/01
/table_zpsc1c7d742.png)

There is also the EN pin that if driven HIGH , it disables the connection of
the SIG pin with any of the 16 channels.

The maximum current that can go through a channel is 25 mA. If you need
to power things like relays, solenoids, or motors, you will need to use
transistors, and pass through the channels only the control signals.

readDigitalSignals

This example assumes there are push buttons with pullup 10 kOhm
resistors connected to the 16 channels like in the following figure.

2 de 8 24/11/2016 0:48
[tutorial] MUX74HC4067 | codebender's blog http://blog.codebender.cc/2014/01/30/mux74hc4067/
codebender (http://codebender.cc)

(http://blog.codebender.cc/wp-content/uploads/2014/01
/schematic_buttons_zpsb9d3f54f.png)

The code reads the input from all the channels, one after the other, and
prints on the serial monitor a statement about whether a push button is
pressed or not.

All you have to do is declare a MUX74HC4067 instance, configure as a


DIGITAL INPUT the Arduino pin to which the SIG pin connects, and you are
ready to read from the channels. Just call read with argument the channel
number and read will return either LOW or HIGH .

Edit Example
MUX74HC4067 readDigitalSignals Clone Download
(https://codebender.cc
& Edit
/sketch:28291?referrer=codebender_tutorials)
1 /** by codebender_tutorials
2 (/?referrer=codebender_tutorials)
(https://codebender.cc
* This example demonstrates how to read digital signals
(https://codebender.cc
3 * It assumes there are push buttons with pullup resistors
/user/codebender_tutorials?referrer=codebender_tutorials)
4 * connected to the 16 channels of the 74HC4067/utilities/download
mux/demux
5 *
6 * For more about the interface of the library go to
7 * https://github.com/pAIgn10/MUX74HC4067 /28291?referrer=codebender_tutorials
8 */
9
10 #include "MUX74HC4067.h"
11
12 // Creates a MUX74HC4067 instance
13 // 1st argument is the Arduino PIN to which the EN pin connects
14 // 2nd-5th arguments are the Arduino PINs to which the S0-S3 pins connect
15 MUX74HC4067 mux(7, 8, 9, 10, 11);
16
17 void setup()
18 {
19 Serial.begin(9600); // Initializes serial port
20 // Waits for serial port to connect. Needed for Leonardo only
21 while ( !Serial ) ;
22
23 // Configures how the SIG pin will be interfaced
24 // e.g. The SIG pin connects to PIN 3 on the Arduino,
25 // and PIN 3 is a digital input
26 mux.signalPin(3, INPUT, DIGITAL);
27 }
28 To program your Arduino from your browser, install the codebender
29 // Reads the 16 channels and reports on the serial monitor
30 plugin
// if or
theapp. Learn more push
corresponding (https://codebender.cc/static/plugin).
button is pressed
31 void loop()
Arduino BT w/ ATmega168

readAnalogSignals

This example assumes there are potentiometers connected to the 16


channels like in the following figure.

(http://blog.codebender.cc/wp-content/uploads/2014/01
/schematic_pots_zps18d61b5c.png)

The code takes measurements of the potentiometers values and prints on


the serial monitor a statement about that value.

By configuring the signal pin as an ANALOG INPUT and then calling read ,
you get back the value measured by the A/D converter. Its an integer from
0 to 1023.

3 de 8 24/11/2016 0:48
[tutorial] MUX74HC4067 | codebender's blog http://blog.codebender.cc/2014/01/30/mux74hc4067/
codebender (http://codebender.cc) Edit Example
MUX74HC4067 readAnalogSignals Clone Download
(https://codebender.cc
& Edit
/sketch:28292?referrer=codebender_tutorials)
1 /** by codebender_tutorials
2 (/?referrer=codebender_tutorials)
* This example demonstrates how
(https://codebender.cc to read analog(https://codebender.cc
signals
3 * It assumes there are potentiometers connected
/user/codebender_tutorials?referrer=codebender_tutorials)
4 * to the 16 channels of the 74HC4067 mux/demux/utilities/download
5 *
6 * For more about the interface of the library go to
7 * https://github.com/pAIgn10/MUX74HC4067 /28292?referrer=codebender_tutorials
8 */
9
10 #include "MUX74HC4067.h"
11
12 // Creates a MUX74HC4067 instance
13 // 1st argument is the Arduino PIN to which the EN pin connects
14 // 2nd-5th arguments are the Arduino PINs to which the S0-S3 pins connect
15 MUX74HC4067 mux(7, 8, 9, 10, 11);
16
17 void setup()
18 {
19 Serial.begin(9600); // Initializes serial port
20 // Waits for serial port to connect. Needed for Leonardo only
21 while ( !Serial ) ;
22
23 // Configures how the SIG pin will be interfaced
24 // e.g. The SIG pin connects to PIN A0 on the Arduino,
25 // and PIN A0 is a analog input
26 mux.signalPin(A0, INPUT, ANALOG);
27 }
28 To program your Arduino from your browser, install the codebender
29 // Reads the 16 channels and reports on the serial monitor
30 plugin
// theorcorresponding
app. Learn more (https://codebender.cc/static/plugin).
value read by the A/D converter
31 void loop()
Arduino BT w/ ATmega168

writeDigitalSignals

This example assumes there are 16 LEDs with current limiting 150 Ohm
resistors and the positive leads of the LEDs are connected to the 16
channels like in the following figure.

(http://blog.codebender.cc/wp-content/uploads/2014/01
/schematic_leds_zps5b08114f.png)

The code just lights up the LEDs, one after the other. You configure the
signal pin as a DIGITAL OUTPUT and then you write to a channel by calling
the write method and providing as arguments the channel number and a
LOW or HIGH value.

Edit Example
MUX74HC4067 writeDigitalSignals Clone Download
(https://codebender.cc
& Edit
/sketch:28293?referrer=codebender_tutorials)
1 /** by codebender_tutorials
2 (/?referrer=codebender_tutorials)
(https://codebender.cc
* This example demonstrates how to write digital signals
(https://codebender.cc
3 * It assumes there are LEDs+resistors with the positive lead of the LEDs
/user/codebender_tutorials?referrer=codebender_tutorials)
4 * connected to the 16 channels of the 74HC4067/utilities/download
mux/demux, respectively
5 *
6 * For more about the interface of the library go to
7 * https://github.com/pAIgn10/MUX74HC4067 /28293?referrer=codebender_tutorials
8 */
9
10 #include "MUX74HC4067.h"
11
12 // Creates a MUX74HC4067 instance
13 // 1st argument is the Arduino PIN to which the EN pin connects
14 // 2nd-5th arguments are the Arduino PINs to which the S0-S3 pins connect
15 MUX74HC4067 mux(7, 8, 9, 10, 11);
16
17 void setup()
18 {
19 // Configures how the SIG pin will be interfaced
20 // e.g. The SIG pin connects to PIN 3 on the Arduino,
21 // and PIN 3 is a Digital Output
22 mux.signalPin(3, OUTPUT, DIGITAL);
23 }
24
25 // Writes to the 16 channels a HIGH value, one after the other
26 void loop()
27 {
28 for (byte
To program youri Arduino
= 0; i < 16;your
from ++i)browser, install the codebender
29 {
30 plugin or //
app. Learn more
Connects (https://codebender.cc/static/plugin).
to channel i and writes HIGH
31 mux.write(i, HIGH);
Arduino BT w/ ATmega168

4 de 8 24/11/2016 0:48
[tutorial] MUX74HC4067 | codebender's blog http://blog.codebender.cc/2014/01/30/mux74hc4067/
codebender (http://codebender.cc)
writePWMSignals

The circuit for this example is identical to the previous one. The difference
here is that the output to the LEDs is a PWM signal.

You can output a PWM signal, by configuring the signal pin as an ANALOG
OUTPUT and then calling the write method and providing as arguments the
channel number and a value (0 to 255) for the duty cycle of the PWM signal.

MUX74HC4067 writePWMSignals EditExample


Clone Download
(https://codebender.cc
& Edit
/sketch:28294?referrer=codebender_tutorials)
1 /** by codebender_tutorials
2 (/?referrer=codebender_tutorials)
(https://codebender.cc
* This example demonstrates how to write PWM signals
(https://codebender.cc
3 * It assumes there are LEDs+resistors with the positive lead of the LEDs
/user/codebender_tutorials?referrer=codebender_tutorials)
4 * connected to the 16 channels of the 74HC4067/utilities/download
mux/demux, respectively
5 *
6 * For more about the interface of the library go to
7 * https://github.com/pAIgn10/MUX74HC4067 /28294?referrer=codebender_tutorials
8 */
9
10 #include "MUX74HC4067.h"
11
12 // Creates a MUX74HC4067 instance
13 // 1st argument is the Arduino PIN to which the EN pin connects
14 // 2nd-5th arguments are the Arduino PINs to which the S0-S3 pins connect
15 MUX74HC4067 mux(7, 8, 9, 10, 11);
16
17 void setup()
18 {
19 // Configures how the SIG pin will be interfaced
20 // e.g. The SIG pin connects to PIN 3 on the Arduino,
21 // and PIN 3 is a Analog (PWM) Output
22 mux.signalPin(3, OUTPUT, ANALOG);
23 }
24
25 // Writes to the 16 channels a PWM output, one after the other
26 // At each next channel, the duty cycle of the PWM increases
27 void loop()
28 { program your Arduino from your browser, install the codebender
To
29 for (byte i = 0; i < 16; ++i)
30 plugin
{ or app. Learn more (https://codebender.cc/static/plugin).
31 // Connects to channel i and outputs a PWM signal
Arduino BT w/ ATmega168

Thats all folks. We hope you enjoy this library, and if you have any
comments or suggestions you can contact us at
girder [at] codebender [dot] cc

Sounds are from freesound.org. Schematics were based on Fritzing.

(/#facebook) (/#twitter)
(/#google_plus)
(https://www.addtoany.com/share#url=http%3A%2F
%2Fblog.codebender.cc%2F2014%2F01%2F30%2Fmux
title=%5Btutorial%5D%20MUX74HC4067)
Posted in Advanced Tutorials (http://blog.codebender.cc/category/advanced-
tutorials/).
Tagged 74hc4067 (http://blog.codebender.cc/tag/74hc4067/), analog
(http://blog.codebender.cc/tag/analog/), demultiplexer
(http://blog.codebender.cc/tag/demultiplexer/), digital
(http://blog.codebender.cc/tag/digital/), input (http://blog.codebender.cc
/tag/input/), multiplexer (http://blog.codebender.cc/tag/multiplexer/), mux
(http://blog.codebender.cc/tag/mux/), output (http://blog.codebender.cc
/tag/output/), signal (http://blog.codebender.cc/tag/signal/), tutorial
(http://blog.codebender.cc/tag/tutorial/).

12 thoughts on [tutorial] MUX74HC4067

Ammirmohammad said on December 5, 2014 at 8:52 am


(http://blog.codebender.cc/2014/01/30/mux74hc4067/#comment-
3253):

Hi Nick,
Your article was very nice!. I simulated the multiplexer with 14
logicstates in proteus. I wrote a program in codevision avr that
checks the bits that comes from output pin and it shows the bits on
LCD 2*16.
I want to make a line follower with this multiplexer and command to
motors when start to spin. I took a screenshot out of my project.
as an example if 2 sensors in the middle are 1, then the motors
turn on and so on. I cant sync with multiplexer(4067).
I hope you can help me.
http://www.pixentral.com
/pics/1SqaagOA9Bg2v4B1X8GLbkKpwlheh2.png
(http://www.pixentral.com
/pics/1SqaagOA9Bg2v4B1X8GLbkKpwlheh2.png)
http://www.pixentral.com
/pics/11h0ebSedjxaR8BvVqPagMUWozGT1.png
(http://www.pixentral.com
/pics/11h0ebSedjxaR8BvVqPagMUWozGT1.png)

Reply (http://blog.codebender.cc/2014/01/30/mux74hc4067

5 de 8 24/11/2016 0:48
[tutorial] MUX74HC4067 | codebender's blog http://blog.codebender.cc/2014/01/30/mux74hc4067/
/?replytocom=3253#respond)
codebender (http://codebender.cc)
Nick Lamprianidis said on December 5, 2014 at 2:49 pm
(http://blog.codebender.cc/2014/01/30/mux74hc4067
/#comment-3254):

Hey Amir,

Sadly you are not giving me much with your problem


description (I cant sync with multiplexer(4067).).
Would you care to elaborate?

Regards,
Nick

Reply (http://blog.codebender.cc/2014/01
/30/mux74hc4067/?replytocom=3254#respond)

Ammirmohammad said on December 5, 2014


at 5:05 pm (http://blog.codebender.cc/2014/01
/30/mux74hc4067/#comment-3255):

Hi again,
My problem is that i cant make an if statement
in my codes.
i tried this code by giving it address:
if(D==1&&C==1&&B==1&&A==1) {
//do something
}
OR (out pin is set to PINA.0 and 15th sensor
named sensor15)
if(sensor15==1) {
//do something
}
OR
if(PINA.0=sensor15) { //even
PINA.0==sensor15 didnt work
//do something
}

PLZ help me

Reply (http://blog.codebender.cc/2014/01
/30/mux74hc4067
/?replytocom=3255#respond)

Nick Lamprianidis said on December


16, 2014 at 6:45 pm
(http://blog.codebender.cc/2014/01
/30/mux74hc4067/#comment-3257):

Hey Amir,

Sorry for the delay, I hadnt noticed


your reply.

From what youve mentioned, I


understand that you have problems
running your program. There could
be a few things that are going
wrong, Ill try to give some hints:
* If youd like know more about
if statements please read here
(http://arduino.cc/en/Reference/if).
* You cant have variables with dots
in their names, so PINA.0 is not
valid.
* Make sure that before you use any
variable, you have defined it.

And then, what are all those


variables? Have you assigned them
any values from the multiplexer? Are
you using my library,
MUX74HC4067? Please provide as
much information as possible, so I
can help you.

Regards,
Nick

Reply (http://blog.codebender.cc
/2014/01/30/mux74hc4067
/?replytocom=3257#respond)

Mayank Gulati said on March 17, 2015 at 10:08 pm


(http://blog.codebender.cc/2014/01/30/mux74hc4067/#comment-
6368):

Hi Nick, you say that the diagrams are based in Fritzing, but I am
unable to locate any frtizting file for the mux74hc4067 part would
you be able to share yours?

Reply (http://blog.codebender.cc/2014/01/30/mux74hc4067
/?replytocom=6368#respond)

Nick Lamprianidis said on March 17, 2015 at 11:01 pm


(http://blog.codebender.cc/2014/01/30/mux74hc4067
/#comment-6369):

Hello,

Only parts of my diagrams are borrowed from Fritzing. In


this case, the MUX74HC4067 is an actual photo

6 de 8 24/11/2016 0:48
[tutorial] MUX74HC4067 | codebender's blog http://blog.codebender.cc/2014/01/30/mux74hc4067/
(https://cdn.sparkfun.com//assets/parts/2/4/2
codebender (http://codebender.cc) /0/09056-04.jpg) of the module from Sparkfun.

Reply (http://blog.codebender.cc/2014/01
/30/mux74hc4067/?replytocom=6369#respond)

benjamin said on December 22, 2015 at 12:37 pm


(http://blog.codebender.cc/2014/01/30/mux74hc4067/#comment-
17670):

Hello, very nice post,


i got some question for you, on your readDigitalSignals example
did you manage cases of multiple impultion (i.e. if you press at the
same time on the button 1 and 2)?

thanks Nick.

Reply (http://blog.codebender.cc/2014/01/30/mux74hc4067
/?replytocom=17670#respond)

Nick Lamprianidis said on February 24, 2016 at 6:19 pm


(http://blog.codebender.cc/2014/01/30/mux74hc4067
/#comment-26418):

Hey Benjamin,

In order to read the value on a channel, you call the


read(<channel>) method (as in the example). So, as
long as you call this function fast enough (or your
presses are slow enough), you can sample all your
buttons at a specific moment. But, there is no real at the
same time capability here, since you poll only one
channel at a time.

Nick

Reply (http://blog.codebender.cc/2014/01
/30/mux74hc4067/?replytocom=26418#respond)

David said on February 23, 2016 at 4:37 am


(http://blog.codebender.cc/2014/01/30/mux74hc4067/#comment-
26139):

Hi Nick,

How could I use 3 of these boards together to read analog pots


with this library? I have the example working well for 1 board, but
what about using multiple boards?

David

Reply (http://blog.codebender.cc/2014/01/30/mux74hc4067
/?replytocom=26139#respond)

Nick Lamprianidis said on February 24, 2016 at 6:36 pm


(http://blog.codebender.cc/2014/01/30/mux74hc4067
/#comment-26420):

Hello David,

The easy way would be to just connect any additional


modules in parallel, the same way you connected the
first one. This means youll need 6 pins for each module.
So, as long as you have enough pins on your uC, you
connect as many as you want (although Im guessing it
wont be practical if youll want to do frequent sequential
accesses).
The other way would be to use similar mux/demux
modules to pick which MUX74HC4067 module to use
each time, and basically share the 6 pins required on the
arduino. But thats not trivial to implement (neither easy
for me to describe in a few sentences).

Nick

Reply (http://blog.codebender.cc/2014/01
/30/mux74hc4067/?replytocom=26420#respond)

Fynx said on March 20, 2016 at 11:59 pm


(http://blog.codebender.cc/2014/01/30/mux74hc4067/#comment-
29977):

Hi Nick,

Your Tutorial is very useful. Does your library support connecting


2-3 of this MUX chips? If so, do you also have a diagram that
supports this?

Thanks a lot.

Reply (http://blog.codebender.cc/2014/01/30/mux74hc4067
/?replytocom=29977#respond)

Fabiano said on June 5, 2016 at 8:31 pm


(http://blog.codebender.cc/2014/01/30/mux74hc4067
/#comment-36797):

You can see at : http://forum.bildr.org


/viewtopic.php?p=4786#p4786 (http://forum.bildr.org
/viewtopic.php?p=4786#p4786)

Reply (http://blog.codebender.cc/2014/01
/30/mux74hc4067/?replytocom=36797#respond)

7 de 8 24/11/2016 0:48
[tutorial] MUX74HC4067 | codebender's blog http://blog.codebender.cc/2014/01/30/mux74hc4067/
codebender (http://codebender.cc) Leave a reply

Comment

You may use these HTML


(HyperText Markup
Language) tags and
attributes:

Name
required

Email
required, will
not be
published

Website

Post Comment

Notify me of follow-up comments by


email.

Notify me of new posts by email.

Next Post (http://blog.codebender.cc/2014/02/01/codebender-v1-0/)


Previous Post (http://blog.codebender.cc/2014/01/23/sharpirlib/)

2016 codebender's blog (http://blog.codebender.cc/), all rights reserved.


Proudly powered by WordPress (http://wordpress.org/)

8 de 8 24/11/2016 0:48

S-ar putea să vă placă și