Using CD74HC4067 one inputs turns 2 channels on?

I have a 8 home switchs, Teensy 4.1 and a CD74HC4067 Multiplexer.
image
image

I've connected my Teensy to my Mac using USB to be able to read the Serial prints.

I've connected a 5v PSU to a DC Step Down, taking the voltage down to 3.3v and then feeding it to all switches and multiplexer.
With that setup switching on one switch caused all inputs to go HIGH on the multiplexer SIG pin.
I understood I have "Floating Inputs" so when the switch is "open" there's no GND or V+ flowing in the cable so it is sensitive to noise from nearby Voltages.

So I've decided to connect all my switches to GND directly from the Step Down Converter and then use Arduino Internal Pullup Resistor.

Now the readings are way more stable but for some reason closing one switch, affects 2 channels on the multiplexer instead of one.

const int selectPins[] {2, 3, 4 ,5};
const int commonPin = 10;
 
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
 
  for (int i = 0; i < 4; i++) {
    pinMode(selectPins[i], OUTPUT);
  }
  pinMode(commonPin, INPUT_PULLUP);
}
 
void loop() {
  // put your main code here, to run repeatedly:
  for (int channel = 0; channel < 16; channel++) {
    selectChannel(channel);
    delayMicroseconds(250);
    int switchState = digitalRead(commonPin);
    Serial.print("Switch ");
    Serial.print(channel);
    Serial.print(": ");
    Serial.println(switchState ? "ON" : "OFF");
  }
  delay(1000);
}
 
void selectChannel(int channel) {
  digitalWrite(selectPins[0], (channel & 0x01) > 0);
  digitalWrite(selectPins[1], (channel & 0x02) > 0);
  digitalWrite(selectPins[2], (channel & 0x04) > 0);
  digitalWrite(selectPins[3], (channel & 0x08) > 0);
}

What am I doing wrong?

I don't know what you are doing wrong because the language of electronics is a schematic, please post one, hand drawn and photographed is fine.

What do you think this does?

1 Like

But have you connected a common ground between the Teensy and this PSU/step-down converter?

1 Like

It does not seem worthwhile to use the multiplexer. For 8 switches, you need 6 pins of the Teensy. For the multiplexer, you need 4 pins. You save only 2 pins. Teensy 4.1 has many pins!

I don't see what value the PSU and voltage converter are providing. Is this powering the Teensy when not connected to USB?

Why not save a lot of time by posting a schematic of how you have wired it?

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