multiplexing hall sensors with cd74hc4067

Hi,

I'm having a problem using the CD74HC4067 multiplexer to read analog values from several hall sensors (A1301-2). The output seems to be very erratic -- sometimes it reads the values properly and sometimes it seems some of the values leak into some of the other outputs (ghosting? but a1301s have super low output impedance...) and sometimes different sensors get printed out of order... Have no idea what's going on?

If anybody can help me out that'd be awesome and super appreciated.

Here's my super simple code which I'm using to try to debug...

//Mux control pins
int s0 = 8;
int s1 = 9;
int s2 = 10;
int s3 = 11;

//Mux in "SIG" pin
int SIG_pin = A0;


void setup(){
  pinMode(s0, OUTPUT); 
  pinMode(s1, OUTPUT); 
  pinMode(s2, OUTPUT);
  pinMode(s3, OUTPUT); 
 

  digitalWrite(s0, LOW);
  digitalWrite(s1, LOW);
  digitalWrite(s2, LOW);
  digitalWrite(s3, LOW);



  Serial.begin(115200);
}


void loop(){

  //Loop through and read all 8 sensor values
  for(int i = 0; i < 8; i++){
    Serial.print(readMux(i));
    Serial.print(" ");
  }
  delay(30);
 Serial.println("");  

}


int readMux(int channel){
  int controlPin[] = {s0, s1, s2, s3};

  int muxChannel[16][4]={
    {0,0,0,0}, //channel 0
    {1,0,0,0}, //channel 1
    {0,1,0,0}, //channel 2
    {1,1,0,0}, //channel 3
    {0,0,1,0}, //channel 4
    {1,0,1,0}, //channel 5
    {0,1,1,0}, //channel 6
    {1,1,1,0}, //channel 7
    {0,0,0,1}, //channel 8
    {1,0,0,1}, //channel 9
    {0,1,0,1}, //channel 10
    {1,1,0,1}, //channel 11
    {0,0,1,1}, //channel 12
    {1,0,1,1}, //channel 13
    {0,1,1,1}, //channel 14
    {1,1,1,1}  //channel 15
  };

  //loop through the 4 sig
  for(int i = 0; i < 4; i ++){
    digitalWrite(controlPin[i], muxChannel[channel][i]);
  }

  //read the value at the SIG pin
  int val = analogRead(SIG_pin);
//I read doing 2 analogReads back to back can sometimes help but not doing it... 
//val = analogRead(SIG_pin); 


  //return the value
  return val;
}

The first thing I would suggest to to ensure that your 8 sensors are connected up properly to the 8 mux inputs.

It looks that you are using inputs 0:7 on the 16 input multiplexer so be sure that the inputs you are selecting in your code are actually the inputs which you have your sensor outputs connected to.

If you read them very slowly 1 at a time are you getting correct readings?

It is important that:-

  1. You have decoupling capacitors on all the chips
  2. All unused inputs to the chip are connected to ground
  3. If the hall effect sensors have open collector outputs these need pulling up before they go into the multiplexer and not just a single pull up at the output. This prevents unselected inputs floating.

Hello i was looking for a code like this one because i want to connect 8 or more lm35 temp sensors on arduino uno rev.3 with this mux SparkFun Analog/Digital MUX Breakout - CD74HC4067 - BOB-09056 - SparkFun Electronics.
Could you please tell me if the code is suitable for me?
Thanks a lot