Introduction: Arduino Interfacing With CD74HC4067 16-channel MUX

About: During my BE days, I worked on many big projects. As a result of these projects, I have been able to contribute about 5 open-source libraries - 3 in Arduino, 1 in Python and 1 in Javascript.

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.

Supplies


Step 1: Make Circuit Connections

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!