MUX74HC4067 - Codebender
MUX74HC4067 - Codebender
MUX74HC4067 - 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
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)
(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.
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
(http://blog.codebender.cc/wp-content/uploads/2014/01
/schematic_pots_zps18d61b5c.png)
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.
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
(/#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/).
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,
Regards,
Nick
Reply (http://blog.codebender.cc/2014/01
/30/mux74hc4067/?replytocom=3254#respond)
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)
Hey Amir,
Regards,
Nick
Reply (http://blog.codebender.cc
/2014/01/30/mux74hc4067
/?replytocom=3257#respond)
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)
Hello,
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)
thanks Nick.
Reply (http://blog.codebender.cc/2014/01/30/mux74hc4067
/?replytocom=17670#respond)
Hey Benjamin,
Nick
Reply (http://blog.codebender.cc/2014/01
/30/mux74hc4067/?replytocom=26418#respond)
Hi Nick,
David
Reply (http://blog.codebender.cc/2014/01/30/mux74hc4067
/?replytocom=26139#respond)
Hello David,
Nick
Reply (http://blog.codebender.cc/2014/01
/30/mux74hc4067/?replytocom=26420#respond)
Hi Nick,
Thanks a lot.
Reply (http://blog.codebender.cc/2014/01/30/mux74hc4067
/?replytocom=29977#respond)
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
Name
required
Email
required, will
not be
published
Website
Post Comment
8 de 8 24/11/2016 0:48