1

I have an Uno hooked up to a sparkfun 8 channel multiplexer (https://learn.sparkfun.com/tutorials/multiplexer-breakout-hookup-guide). I have it wired up like this:

Arduino0 --> S0
Arduino1 --> S1
Arduino2 --> S2
Arduino3 --> Z
Arduino 5v --> VCC
Arduino GND --> GND

I'm running a simple code to blink two different LED's, one attached to Y7, and one attached to Y6.

//Define MUX pins
int pin0 = 0;
int pin1 = 1;
int pin2 = 2;
int zOutPut1 = 3;

void setup() {
    Serial.begin(9600); 

    // Set controll pins
    pinMode(pin0, OUTPUT);
    pinMode(pin1, OUTPUT);
    pinMode(pin2, OUTPUT);
    pinMode(zOutPut1, OUTPUT);
}

void loop() {
    samplerStarter();
}

void samplerStarter() {
    sample(1); // Takes sample for 5 min
    delay(1000);
    sample(2);
    delay(1000);
}

void sample(int noidNum){
    //MUX 1
    if(noidNum == 1) {
        digitalWrite(pin0, HIGH);
        digitalWrite(pin1, HIGH);
        digitalWrite(pin2, HIGH);
        digitalWrite(zOutPut1, HIGH); //Y7
    }
    else if (noidNum == 2) {
        digitalWrite(pin0, LOW);
        digitalWrite(pin1, HIGH);
        digitalWrite(pin2, HIGH);
        digitalWrite(zOutPut1, HIGH); //Y6
    }
    delay(500); 

    //Set everythign back to Low
    digitalWrite(pin0, LOW);
    digitalWrite(pin1, LOW);
    digitalWrite(pin2, LOW);
    digitalWrite(zOutPut1, LOW);

    delay(500);
}

But when I run this code, only the first LED attached to Y7 blinks. But if I remove the Serial.begin(9600) line:

//Serial.begin(9600);

Everything works fine. So I have no idea why this one line dealing with Serial Communication is affecting my multiplexor.

1 Answer 1

3

(Digital) Pins 0 and 1 are used by the hardware serial port you initialize with Serial.begin() on a classic Arduino like an Uno.

With this type of board it is generally best not to use those for any other purpose; if you do, you have to accept that you cannot use the hardware serial for input or debug/status output.

Even if you don't want to use serial during the operation of the your creation, having those pins connected to other functions can interefere with uploading sketches via the bootloader, or else the act of uploading a sketch can misoperate the functions connected to those pins.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.