Arduino Interfacing With CD74HC4067 16-channel MUX

5.1K24

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

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

I'm absolutely thankful for this code and its results. It seems that I have a small issue, as when I run it, it shows values around 200, and when I apply the values shown in Mehran's code (*5.0/1024.0), it shows values around 1.0 volts. Do you know why this could happen?
I'm running the code on an Arduino Leonardo.
Thank you very much!