Mux knobs on an Arduino Uno
A CD74HC4067 reads three potentiometers on one analog pin, picking each channel with four address lines. 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 $33. On Mokxi they're free.
Step by step, with the wiring and the common mistakes: Arduino CD74HC4067 Multiplexer: 16 Analog Inputs
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// Mux knobs: a CD74HC4067 reads three potentiometers on one analog pin.
//
// CD74HC4067 S0 S1 S2 S3 -> pins 2 3 4 5 EN -> GND COM -> A0
// VCC -> 5 V GND -> GND
// pots wipers on channels 0, 5 and 15, ends across 5 V and GND
//
// The 4067 is sixteen switches with one common pin, and the four address
// lines pick which one is closed. To read channel n the sketch puts n on S0
// to S3, waits a moment for the switch and the ADC's input to settle, and
// reads A0. Sixteen knobs, four digital pins and one analog pin.
//
// Turn the three knobs.
const uint8_t ADDRESS[4] = {2, 3, 4, 5};
const uint8_t CHANNELS[3] = {0, 5, 15};
int readChannel(uint8_t channel) {
for (uint8_t bit = 0; bit < 4; 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 < 4; bit++) pinMode(ADDRESS[bit], OUTPUT);
Serial.println("Mux knobs: channels 0, 5 and 15");
}
void loop() {
for (uint8_t i = 0; i < 3; i++) {
Serial.print("ch");
Serial.print(CHANNELS[i]);
Serial.print(" ");
Serial.print(readChannel(CHANNELS[i]));
Serial.print(i < 2 ? " " : "\n");
}
delay(300);
}
Parts list
6 parts, plus the jumper wires. They retail for about $33; on Mokxi they're free.
How it is wired
11 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.
- Ground: Arduino Uno R3 pin GND; CD74HC4067 analog multiplexer pin EN; CD74HC4067 analog multiplexer pin GND
- Arduino Uno R3 pin 5; CD74HC4067 analog multiplexer pin S3
- Arduino Uno R3 pin 4; CD74HC4067 analog multiplexer pin S2
- Arduino Uno R3 pin 3; CD74HC4067 analog multiplexer pin S1
- Arduino Uno R3 pin 2; CD74HC4067 analog multiplexer pin S0
- Arduino Uno R3 pin 5V; Potentiometer (1) pin 3; Potentiometer (2) pin 3; Potentiometer (3) pin 3; CD74HC4067 analog multiplexer pin VCC
- Ground: Arduino Uno R3 pin GND; Potentiometer (1) pin 1; Potentiometer (2) pin 1; Potentiometer (3) pin 1
- Arduino Uno R3 pin A0; CD74HC4067 analog multiplexer pin COM
- Potentiometer (1) pin 2; CD74HC4067 analog multiplexer pin I15
- Potentiometer (2) pin 2; CD74HC4067 analog multiplexer pin I5
- Potentiometer (3) pin 2; CD74HC4067 analog multiplexer pin I0
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.