Built-in project · Arduino Uno R3

Mux eight on an Arduino Uno

Three knobs read on one analog pin through a 74HC4051: three address lines pick which of its eight channels reaches A0. The whole build, an Arduino Uno and 4 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.

Teaching? Assign it to your class in one click.

Intermediate Runs in your browser. Free, and no account needed.

The parts retail for about $32. On Mokxi they're free.

Mux eight · Arduino Uno R3live0.000 s 0.00x
Click to open it in the editor
The circuit itself, running here on the simulator. Press what can be pressed; click anything else to open it in the editor.

The code

The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.

sketch.ino · Arduino Uno R3
// Mux eight: three knobs read on one analog pin through a 74HC4051.
//
// Wiring, multiplexer to board:
//   S0 (pin 11) -> pin 2, S1 (pin 10) -> pin 3, S2 (pin 9) -> pin 4
//   Z  (pin 3)  -> A0
//   E (pin 6), VEE (pin 7) and GND (pin 8) to GND, VCC (pin 16) to 5 V
//   the knobs' wipers on Y0, Y1 and Y2
//
// The address on S0 to S2 joins one of the eight channels to Z through an
// analog switch, so A0 reads whichever knob is selected. The switch has some
// 70 ohm of resistance and A0 has a little capacitance, so the sketch waits
// a moment after changing the address before it reads.

const uint8_t ADDRESS[3] = {2, 3, 4};

int readChannel(uint8_t channel) {
  for (uint8_t bit = 0; bit < 3; bit++) {
    digitalWrite(ADDRESS[bit], (channel >> bit) & 1 ? HIGH : LOW);
  }
  delayMicroseconds(50);
  return analogRead(A0);
}

void setup() {
  Serial.begin(9600);
  for (uint8_t bit = 0; bit < 3; bit++) pinMode(ADDRESS[bit], OUTPUT);
  Serial.println("Mux eight: channels 0, 1 and 2");
}

void loop() {
  for (uint8_t ch = 0; ch < 3; ch++) {
    Serial.print("Y");
    Serial.print(ch);
    Serial.print(" ");
    Serial.print(readChannel(ch));
    Serial.print(ch < 2 ? "  " : "\n");
  }
  delay(300);
}

Parts list

6 parts, plus the jumper wires. They retail for about $32; on Mokxi they're free.

How it is wired

9 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.

  • Arduino Uno R3 pin 4; 74HC4051 analog multiplexer pin S2
  • Arduino Uno R3 pin 3; 74HC4051 analog multiplexer pin S1
  • Arduino Uno R3 pin 2; 74HC4051 analog multiplexer pin S0
  • Arduino Uno R3 pin 5V; Potentiometer (1) pin 3; Potentiometer (2) pin 3; Potentiometer (3) pin 3; 74HC4051 analog multiplexer pin VCC
  • Ground: Arduino Uno R3 pin GND; Potentiometer (1) pin 1; Potentiometer (2) pin 1; Potentiometer (3) pin 1; 74HC4051 analog multiplexer pin E; 74HC4051 analog multiplexer pin VEE; 74HC4051 analog multiplexer pin GND
  • Arduino Uno R3 pin A0; 74HC4051 analog multiplexer pin Z
  • Potentiometer (1) pin 2; 74HC4051 analog multiplexer pin Y0
  • Potentiometer (2) pin 2; 74HC4051 analog multiplexer pin Y1
  • Potentiometer (3) pin 2; 74HC4051 analog multiplexer pin Y2

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.