Multiplexer Programming

Hi,

Im trying to program my 8:1 mux with the Arduino. However, Im not really sure how to do the coding to select one switch at one time. Im using 6 input pins and 1 output pin which connected to the instrumentation amplifier. The circuit design can be seen in the attachment. Can anyone help me?

final_draft_circuit.PDF (128 KB)

We know what a mux is. We don't know which mux.

ieee488: We know what a mux is. We don't know which mux.

The drawing says it's a 4051 8-channel analog multiplexer/demultiplexer

Drive A-B-C pins with one of these combinations: 000 001 010 011 100 101 110 111 - no input from this pin, I would connect it to Gnd. and the Inhibit pin Low to let the selected input show up at the output. http://www.ti.com/lit/ds/symlink/cd74hc4051.pdf

I know about the 8-bit binary digits, however, im not really sure how to program it. Thank you. :)

Riva: The drawing says it's a 4051 8-channel analog multiplexer/demultiplexer

For something so simple, you'd think a Google search 'Arduino 4051' would have landed more than enough results.

tyra:
I know about the 8-bit binary digits, however, im not really sure how to program it. Thank you. :slight_smile:

Untested but something like this.

#define pinA 3
#define pinB 4
#define pinC 9

void setup(){
  Serial.begin(9600);
  pinMode(pinA,OUTPUT);
  pinMode(pinB,OUTPUT);
  pinMode(pinC,OUTPUT);
}

void loop(){
  for (byte x = 0; x < 8; x++){
    digitalWrite(pinA,bitRead(x,0));
    digitalWrite(pinB,bitRead(x,1));
    digitalWrite(pinC,bitRead(x,2));
    Serial.println(x);
    delay(1000);
  }
}

what is this line means? is the ‘x’ belong to pinA and 0 belong to bitRead?

digitalWrite(pinA,bitRead(x,0));

No, "x" is the channel number (0 to 7). "0" is the is the bit of the channel number that needs to be written to pinA.

tyra: what is this line means? is the 'x' belong to pinA and 0 belong to bitRead?

Paul has already explained the meaning but for further reference check out the description here and digitalWrite here. The reference says HIGH/LOW but basically LOW = 0 and HIGH = number anything other than zero.

A more detailed explanation is to be found here http://www.thebox.myzen.co.uk/Tutorial/Arrays.html