Unreliable digital inputs from CD74HC4067 mux to Due

Hi there - I'm building a flight-sim button box that will need several rotary switches (not encoders) and other buttons and am trying to use the CD74HC4067 (no-name boards from Amazon UK at the moment) to reduce the input count on to the Due.

I have been using the often-quoted basic sketch (as reproduced here) to test the basics - but it is apparent that the inputs are erratic and cannot be trusted. So far I've tried two of the five 4067s I have to hand.

Searching this forum suggested possibly that all of the C0-15 inputs on the 4067 might need a grounding capacitor? Is that where I'm going wrong?

int s0 = 3;
int s1 = 4;
int s2 = 5;
int s3 = 6;

//Mux in "SIG" pin
int SIG_pin = 2;


void setup() {
  pinMode(s0, OUTPUT);
  pinMode(s1, OUTPUT);
  pinMode(s2, OUTPUT);
  pinMode(s3, OUTPUT);
  pinMode(SIG_pin, INPUT);

  digitalWrite(s0, LOW);
  digitalWrite(s1, LOW);
  digitalWrite(s2, LOW);
  digitalWrite(s3, LOW);

  Serial.begin(9600);
}


void loop() {

  //Loop through and read all 16 values
  for (int i = 0; i < 16; i++) {
    Serial.print("Value at channel ");
    Serial.print(i);
    Serial.print("is : ");
    Serial.println(readMux(i));
    delay(1000);
  }
}


int readMux(int channel) {
  int controlPin[] = { s0, s1, s2, s3 };

  int muxChannel[16][4] = {
    { 0, 0, 0, 0 },  //channel 0
    { 1, 0, 0, 0 },  //channel 1
    { 0, 1, 0, 0 },  //channel 2
    { 1, 1, 0, 0 },  //channel 3
    { 0, 0, 1, 0 },  //channel 4
    { 1, 0, 1, 0 },  //channel 5
    { 0, 1, 1, 0 },  //channel 6
    { 1, 1, 1, 0 },  //channel 7
    { 0, 0, 0, 1 },  //channel 8
    { 1, 0, 0, 1 },  //channel 9
    { 0, 1, 0, 1 },  //channel 10
    { 1, 1, 0, 1 },  //channel 11
    { 0, 0, 1, 1 },  //channel 12
    { 1, 0, 1, 1 },  //channel 13
    { 0, 1, 1, 1 },  //channel 14
    { 1, 1, 1, 1 }   //channel 15
  };

  //loop through the 4 sig
  for (int i = 0; i < 4; i++) {
    digitalWrite(controlPin[i], muxChannel[channel][i]);
  }

  //read the value at the SIG pin
  int val = digitalRead(SIG_pin);

  //return the value
  return val;
}

TIA!

ps - I have tried both grounding the EN pin on the 4067 as well as taking it HIGH with no success.

pps - I also found a suggestion that the 4067 input current should be limited to 250mA - in which case would I also need a resistor between the rotary switch and +Vcc?

They need pull up or down resistors.

1 Like

Thanks @DrDiettrich.

While you were replying, I'd made a slight advance myself by grounding all unused Cx inputs, removing the rotary switch and substituting ground jumpers and a single 200 Ohm resistor to simulate positions on the switch.

The inputs are now reliable - it is clear the unselected positions on the rotary switch were floating.

I'll try pull-down resistors and the switch, thanks.

OK - this is my updated Fritz - I've added 10k pull-down resistors to the four Cx inputs I'm currently using and a 200 Ohm current-limiting resistor to the +Vcc input of the rotary switch.

The 4067 and switch now appear to be working as I'd expect - but does my schematic and values sound/look suitable? TIA, again! :smiling_face_with_three_hearts:

Remove the resistor from the common pin of the rotary switch. It will form a voltage divider with the pulldown resistors and prevent proper logic signal levels

1 Like

Great, thanks. The 4067 will still be happy with the input current, I assume?

which input current? Controller inputs don't draw currents.

Remove it, there is no current to be limited.

Brilliant - thanks for your help and advice.

Just an afterthought - I stumbled across a similar thread and the suggested solution was to use a single pull-up on SIG on the 4067 and to take all the switch/button inputs to ground.

This seems to work - and would save a ton of resistors if every input previously needed one each - any obvious benefits/negatives to either approach?

Then add the pullup to the Arduino input.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.