Arduino Interfacing With CD74HC4067 16-channel MUX
Intro: Arduino Interfacing With CD74HC4067 16-channel MUX
The CD74HC4067 is a 16-channel multiplexer. This module is used when you need to monitor multiple sensors or input devices on a single port. This is helpful in devices where there are only 1 or few analog pins. The Arduino has 6 analog pins, which means we can monitor a maximum of 6 sensors. With the help of CD74HC4067, we can monitor 16 sensors on a single Analog pin. In this tutorial, we will see a fast and efficient method of interfacing Arduino with CD74HC4067.
STEP 1: Make Circuit Connections
Follow this tutorial for circuit connection: https://electropeak.com/learn/interfacing-cd74hc4067-16-channel-analog-digital-multiplexer-with-arduino/
STEP 2: Install Required Library in Arduino IDE
Install the light_CD74HC4067 library in Arduino IDE
Go to Sketch > Include Library > Manage Libraries
Search "light_CD74HC4067" and install.
STEP 3: Upload Code to Arduino
Upload the below code to your Arduino:
/*
* Connect the four control pins to any Arduino pins.
* This example uses digital pins 4, 5, 6, and 7.
* You will get analog output at the Analog pin that you connect to Sig pin of CD74HC4067
* This examples loops through all channels and prints the analog input at all 16 channels
*/
#include <light_CD74HC4067.h>
// s0 s1 s2 s3: select pins
CD74HC4067 mux(8, 9, 10, 11); // create a new CD74HC4067 object with its four select lines - 8,9,10,11
const int signal_pin = A0; // Pin A0 - Connected to Sig pin of CD74HC4067
void setup()
{
Serial.begin(9600);
pinMode(signal_pin, INPUT); // Set as input for reading through signal pin
}
void loop()
{
// loop through channels 0 - 15
for (byte i = 0; i < 16; i++) {
mux.channel(i);
int val = analogRead(signal_pin); // Read analog value
Serial.println("Channel "+String(i)+": "+String(val)); // Print value
delay(500);
}
delay(2000);
}
STEP 4: Power Up Your Arduino and Check Results!
Now power up your Arduino, open the COM port and check the results!
2 Comments
tomasgonzalezlombardo 1 year ago
I'm running the code on an Arduino Leonardo.
Thank you very much!
tomasgonzalezlombardo 1 year ago
"The problem is the multiplexer has resistance, this resistance can vary from device to device (I wouldn't expect that) and it does change with temperature and the amount of current through the device. You will also have common mode issues as you get near 0V. "
https://electronics.stackexchange.com/questions/220443/analog-multiplexer-cd4051be