#include <Arduino.h>
const int enablePin = 22; // EN pin of CD74HC4067
const int s0Pin = 26; // S0 pin
const int s1Pin = 27; // S1 pin
const int s2Pin = 32; // S2 pin
const int s3Pin = 33; // S3 pin
const int analogPin = 36; // Z pin of CD74HC4067
void setup() {
Serial.begin(9600);
pinMode(enablePin, OUTPUT);
pinMode(s0Pin, OUTPUT);
pinMode(s1Pin, OUTPUT);
pinMode(s2Pin, OUTPUT);
pinMode(s3Pin, OUTPUT);
// Set the CD74HC4067 to channel 0 initially
selectChannel(0);
}
void loop() {
for (int channel = 0; channel < 2; channel++) {
selectChannel(channel);
int sensorValue = analogRead(analogPin);
float voltage = (sensorValue / 4095.0) * 3.3; // Convert ADC reading to voltage (assuming 12-bit ADC)
Serial.print("Potentiometer ");
Serial.print(channel);
Serial.print(" Voltage: ");
Serial.print(voltage, 2); // Display voltage with 2 decimal places
Serial.println(" V");
delay(1000); // Delay for 1 second before reading the next potentiometer
}
}
void selectChannel(int channel) {
digitalWrite(s0Pin, channel & 0x01);
digitalWrite(s1Pin, (channel >> 1) & 0x01);
digitalWrite(s2Pin, (channel >> 2) & 0x01);
digitalWrite(s3Pin, (channel >> 3) & 0x01);
}
Loading
cd74hc4067
cd74hc4067