How to Use the CD74HC4067 Multiplexer with Arduino

How to Use the CD74HC4067 Multiplexer with Arduino

The CD74HC4067 is a 16-channel analog/digital multiplexer/demultiplexer that allows you to expand the number of input or output pins on your Arduino. It is particularly useful in projects requiring multiple sensors, buttons, or LEDs while minimizing pin usage. This tutorial will guide you through connecting and using the CD74HC4067 with Arduino.


What You Will Need

  1. CD74HC4067 Multiplexer Module or IC
  2. Arduino Board (e.g., Uno, Mega, Nano)
  3. Sensors, buttons, or LEDs for testing
  4. Breadboard and Jumper Wires
  5. A computer with the Arduino IDE installed

Step 1: Understanding the CD74HC4067

The CD74HC4067 acts as a switch that connects one of its 16 input/output pins to a single common pin. You can control which channel is active using 4 control pins (S0 to S3).

Pinout

Pin Function
VCC Power Supply (3.3V or 5V)
GND Ground
S0, S1, S2, S3 Control Pins (to select the active channel)
EN Enable Pin (active LOW; connect to GND to enable)
COM Common I/O Pin (connect to Arduino)
CH0-CH15 Channels 0 to 15 (connect to sensors, buttons, or LEDs)

Step 2: Wiring the CD74HC4067 to Arduino

Here’s how to connect the CD74HC4067 to an Arduino Uno:

CD74HC4067 Pin Arduino Pin
VCC 5V
GND GND
S0 Pin 8
S1 Pin 9
S2 Pin 10
S3 Pin 11
EN GND
COM A0 (for reading analog signals)
CH0-CH15 Sensors, LEDs, or buttons

Step 3: Upload the Code

The following example demonstrates how to read analog values from sensors connected to the CD74HC4067:

Example Code

const int s0 = 8; // Control pin S0
const int s1 = 9; // Control pin S1
const int s2 = 10; // Control pin S2
const int s3 = 11; // Control pin S3
const int comPin = A0; // Common pin connected to A0

void setup() {
  pinMode(s0, OUTPUT);
  pinMode(s1, OUTPUT);
  pinMode(s2, OUTPUT);
  pinMode(s3, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  for (int i = 0; i < 16; i++) {
    selectChannel(i); // Select the active channel
    int sensorValue = analogRead(comPin); // Read the value from the sensor
    Serial.print("Channel ");
    Serial.print(i);
    Serial.print(": ");
    Serial.println(sensorValue);
    delay(500); // Small delay for readability
  }
}

void selectChannel(int channel) {
  digitalWrite(s0, channel & 0x01); // Set S0
  digitalWrite(s1, (channel >> 1) & 0x01); // Set S1
  digitalWrite(s2, (channel >> 2) & 0x01); // Set S2
  digitalWrite(s3, (channel >> 3) & 0x01); // Set S3
}

Step 4: Test the Setup

  1. Connect the Arduino to your computer via USB.
  2. Open the Arduino IDE and select the correct Board and Port under the Tools menu.
  3. Upload the code by clicking Upload.
  4. Open the Serial Monitor (Tools > Serial Monitor) and set the baud rate to 9600.
  5. Observe the analog values for each channel being displayed in the Serial Monitor.

Optional: Controlling LEDs

To control LEDs connected to the channels, modify the code to output digital signals instead of reading analog inputs. For example:

Example Code for LEDs

void loop() {
  for (int i = 0; i < 16; i++) {
    selectChannel(i);
    digitalWrite(comPin, HIGH); // Turn on LED on the active channel
    delay(500);
    digitalWrite(comPin, LOW); // Turn off LED
  }
}

Applications of the CD74HC4067

  1. Expanding analog and digital inputs/outputs
  2. Reading multiple sensors with limited pins
  3. Building large button matrices
  4. Controlling multiple LEDs or relays

Troubleshooting

  • No response from channels: Verify the control pin connections and ensure the EN pin is connected to GND.
  • Incorrect channel selection: Check the selectChannel() logic for setting S0-S3 pins.
  • Unstable readings: Ensure proper grounding and stable power supply for sensors.

Conclusion

You’ve successfully interfaced the CD74HC4067 multiplexer with Arduino. This versatile module allows you to expand your Arduino’s input and output capabilities significantly, making it ideal for projects involving multiple sensors, buttons, or LEDs. Experiment with different configurations and explore its full potential!

Leave a comment

Notice an Issue? Have a Suggestion?
If you encounter a problem or have an idea for a new feature, let us know! Report a problem or request a feature here.