Home Code Arduino and 4067

Arduino and 4067

by shedboy71

The 4067 was one of the IC's that I wanted to connect up to various microcontrollers as it looke dextremely useful, here is a quick description from one of the datasheets with an overview of the functionality

The HEF4067B is a 16-channel analog multiplexer/demultiplexer with four address inputs (A0 to A3), an active LOW enable input (E), sixteen independent inputs/outputs (Y0 to Y15) and a common input/output (Z). The device contains sixteen bidirectional analog switches, each with one side connected to an independent input/output (Y0 to Y15) and the other side connected to the common input/output (Z). With E LOW, one of the sixteen switches is selected (low-impedance ON-state) by A0 to A3. All unselected switches are in the high-impedance OFF-state. With E HIGH all switches are in the high-impedance OFF-state, independent of A0 to A3. The analog inputs/outputs (Y0 to Y15 and Z) can swing between VDD as a positive limit and VSS as a negative limit. VDD to VSS may not exceed 15 V.

Here is the pinout of the 4067

cd4067 _pinout

cd4067 _pinout

You can see depending on the state of pins S0 – S3 determines the output channel pin that is used. So if S0 to S3 are 0 then Channel 0 which is Pin 9 is selected

4067 truthtable

4067 truthtable

Schematic

Here is a schematic, in this example we only connected 8 sets of LEDs and resistors but its easy to add another 8 from X8 to X15

Arduino and 4067

Arduino and 4067

Code

The code example only uses 8 LEDs

If you want to use more than 8 change the for loop – arduinoPin < 7

for (int arduinoPin = 2; arduinoPin < 7; arduinoPin++)

[codesyntax lang=”cpp”]

const int channel[] = {2, 3, 4, 5};

//the output pin - mux input
const int outputPin = 6;

void setup() 
{
  // set up all pins as output:
  for (int arduinoPin = 2; arduinoPin < 7; arduinoPin++) 
  {
    pinMode(arduinoPin, OUTPUT);
  }
}

void loop() 
{
  //iterate through the first 8 channels of the multiplexer (change to 16 if you 
  //have 16 LEDs or outputs connected)
  for (int muxChannel = 0; muxChannel < 8; muxChannel++) 
  {
    //set the channel pins based on the channel you want
    //LED on - high - 100 milliseconds delay
    muxWrite(muxChannel);
    digitalWrite(outputPin,HIGH);
    delay(100);
  }
}

void muxWrite(int whichChannel) 
{
  for (int inputPin = 0; inputPin < 4; inputPin++) 
  {
    int pinState = bitRead(whichChannel, inputPin);
    // turn the pin on or off:
    digitalWrite(channel[inputPin],pinState);
  }
}

[/codesyntax]

Share

You may also like