Electronic – arduino – Using Multiplexer with an Arduino


I am trying to get a Multiplexer to work with the Arduino. Description at sparkfun Datasheet

I thought the wiring was pretty simple and as a basic test, I have AREF connected to C1(multiplexer) and a floating wire connected to C0. Everything on the interfacing side maps almost 1 to 1 with the arduino.

I am using this simple code for switching the multiplexer

void select_wire(char which){
    delay(1); //required?

and then I just read from the Analog pin at S on the multiplexer. My problem is that it is not switching! How do I fix this so that it will behave as intended and give a zero(or close) whenever I do select_wire(1) and read the analog pin?

Also, I am not using the Wiring "language" but I am using the Wiring library. I have also set all the appropriate pinModes in the init

Best Answer

As rzrgenesys187 said:

If pin C0 floats HIGH and C1 is connected to AREF which is also HIGH, then there shouldn't be any change. Did you try connecting C1 to ground to get zero when you run select_wire(1)?

Yea, so it actually was switching the entire time.. however, there is a lot more distortion, so the wire connected to ground floated somewhere in the 10s. And AREF isn't high, so I don't understand how that works. AREF for me gave about the same values as ground when using


so not sure why, but AREF is giving me near-ground values... very strange, but the MUX does infact switch, so this question is answered.. and I actually never had any problems.. meh.


Actually, hooking straight into AREF does make it the input go high to 1023, so I have no idea why the input won't go that high with the MUX. maybe some kinda voltage limit, idk. I have to read up on it..


Ok, finally think I'm figuring it out. Apparently breadboards leak a lot of current, so that if I was connected to C0 and it was reading C1, then a lot of voltage would leak to C1. Anyway though, connecting to AREF to C3 makes both inputs go high, so now I'm just even more confused.