CD4053BE CMOS Analog Multiplexers/Demultiplexers with Logic Level Conversion (Analog Input)

used products:

1. Arduino UNO
2. CD4053BE
3. CD74HC4053E

content:

CD4053BE or CD74HC4053E 0g083n91bU0

Arduino:

const int cInput = A0; const int cSelectPin = 2; int inputValue; void setup() { Serial.begin(9600); pinMode(cSelectPin, OUTPUT); } void loop() { digitalWrite(cSelectPin, LOW); inputValue = analogRead(cInput); Serial.print(String(inputValue) + "\t"); digitalWrite(cSelectPin, HIGH); inputValue = analogRead(cInput); Serial.print(String(inputValue) + "\t"); Serial.println(); delay(100); }

C:

#include <avr/io.h> #include <util/delay.h> #include <Arduino.h> const int cInput = PC0; const int cSelectPin = PD2; int inputValue = 0; int main(void) { Serial.begin(9600); DDRD |= (1<<cSelectPin); setupADC(); while (1) { PORTD &= ~(1<<cSelectPin); inputValue = readADCValue(cInput); Serial.print(String(inputValue) + "\t"); PORTD |= (1<<cSelectPin); inputValue = readADCValue(cInput); Serial.print(String(inputValue) + "\t"); Serial.println(); _delay_ms(50); } return 0; } void setupADC() { ADMUX = (1<<REFS0); // For Aref=AVcc; ADCSRA = (1<<ADEN) | (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0); //Rrescalar div factor =128 } uint16_t readADCValue(uint8_t ch){ //Select ADC Channel ch must be 0-7 ADMUX |= ch & 0b00000111; //Start Single conversion ADCSRA |= (1<<ADSC); //Wait for conversion to complete while(!(ADCSRA & (1<<ADIF))); //Clear ADIF by writing one to it //Note you may be wondering why we have write one to clear it //This is standard way of clearing bits in io as said in datasheets. //The code writes '1' but it result in setting bit to '0' !!! ADCSRA|=(1<<ADIF); return(ADC); }