Arduino Tutorial: Analog Mux/Demux and Arduino

How to use the MC14051 8 to 1 Analog Multiplexer/Demultiplexer to select or control 1 of 8 analog inputs or outputs with Arduino

Schematic

To be added

Sketch:

const int A=11;
const int B=10;
const int C=9;

const int X = 3;

int pause = 0;

void setup()
{
  pinMode(A, OUTPUT);
  pinMode(B, OUTPUT);
  pinMode(C, OUTPUT);
  pinMode(X, OUTPUT);
}

void loop()
{
  // X0
  digitalWrite(A, 0);
  digitalWrite(B, 0);
  digitalWrite(C, 0);
  analogWrite(X, 2);
  delay(pause);
  
  // X1
  digitalWrite(A, 1);
  digitalWrite(B, 0);
  digitalWrite(C, 0);
  analogWrite(X, 70);
  delay(pause);
  
  // X2
  digitalWrite(A, 0);
  digitalWrite(B, 1);
  digitalWrite(C, 0);
  analogWrite(X, 180);
  delay(pause);
  
  // X3
  digitalWrite(A, 1);
  digitalWrite(B, 1);
  digitalWrite(C, 0);
  analogWrite(X, 255);
  delay(pause);
}
  
Print Friendly
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Leave a Reply

Your email address will not be published. Required fields are marked *