Arduino Playground is read-only starting December 31st, 2018. For more info please look at this Forum Post

74XX151

The 74XX151 is a digital multiplexer with 8 inputs addresses with a 3-bit-port and latched through a strobe channel. The following code will do an iterative polling of the different multiplexer's inputs and read the values through a digital input. (The base device is an SN74HC151 or even any available SN74LS151 or an original F74151A.)

// This patch reads a 74HC151 8 inputs digital mux
// Enrique Tomas, EMI project, Madrid, June 2006
// warholiano@yahoo.es
// www.ultranoise.es

//mux variables
int input = 6;   // digital input to arduino from mux
int strobe=5;   //digital outputs to control mux  
int c=4;
int b=3;
int a=2;



// to store the values from mux
int val[] = {
  0,0,0,0,0,0,0,0};  

// digital values to control 8 inputs
int c_bin[]={LOW,LOW,LOW,LOW,HIGH,HIGH,HIGH,HIGH};
int b_bin[]={LOW,LOW,HIGH,HIGH,LOW,LOW,HIGH,HIGH};
int a_bin[]={LOW,HIGH,LOW,HIGH,LOW,HIGH,LOW,HIGH};

//aux
int contador=0;
int entrada=0;
int a_val=0;
int b_val=0;
int c_val=0;

void setup() {

  Serial.begin(9600);
  pinMode(input, INPUT);    
  pinMode(strobe, OUTPUT);
  pinMode(c, OUTPUT);
  pinMode(b, OUTPUT);
  pinMode(a, OUTPUT);
}

void loop() {

  for(entrada=0;entrada<=7;entrada++) {

    //select mux input
    a_val=a_bin[entrada];
    b_val=b_bin[entrada];
    c_val=c_bin[entrada];

    digitalWrite(a,a_val);
    digitalWrite(b,b_val);
    digitalWrite(c,c_val);

    //strobe LOW to read
    digitalWrite(strobe,LOW);

    //read value
    val[entrada] = digitalRead(input);  // read input value

    //strobe HIGH to avoid jitters
    digitalWrite(strobe,HIGH);
  }

  //serial printing
  Serial.print('A');
  delay(100);
  for(contador=0;contador<=7;contador++) {
    Serial.print(val[contador]);
    delay(100);
  }
  Serial.println();

}