Multiplexing multiple analog values

Dear all,

I have hall sensor that can measure current upto 25 A .with analog output 0~5v. I am using Arduino mega Board for programming. There are totally 30 Hall sensor and where arduino mega has 16 analog channel. Because of this i am planning to use multiplexer circuit

question:

1)Is above circuit is write to build multiplexing circuit??
2)How Multiple analog output values are read
3)What is purpose of selector pins S0,s1,s2 . it say that depend on state of pin it read value . is it true or false. means to say if s0=s1=s2=0 it read analog out put of hall sensor 1 , if S0=0 s1=0s2=1 it read HS4 it is correct or not.
4)using multiplexer i can read one value @ time but multiple IO connected or using delay in program i can say read value after every 1000ms

Multiplexer.JPG

The three selector pins determine which of the multiple inputs of the chip, connects to the output of the chip which feeds into your arduino a/d input.

You control the three selector pins to either high ( 1 ) or low ( 0 ) with three digital outputs of your arduino. These three pins form a 3 bit binary number which has the values 000 001 010 011 100 101 110 111 which are the binary numbers for 0 to 7 which selects which of the 8 analog inputs on the chip you currently want to measure.

Hi,

Yes, I think 74hc4051 should be suitable. You will need at least 2, which will give you 16 analog inputs at the cost of 2 Arduino analog inputs. You will then have 14 remaining Arduino analog inputs, giving 30 in total. You will need to connect 3 Ardino digital outputs to the chips to select the channel, but both chips can share the same 3 digital outputs.

Yes, you can measure all 30 channels every second, or any other sequence you need.

Paul

THANKS FOR QUICK REPLY. Here i am attaching Modified circuit With board. SO i am instead of using mega . I can do within arduino UNO with modbus Interface.WIth above requirement

Alternatively you could use 4 mux units to address your 30 inputs read by 3 address lines. You then need one more mux unit to address the 4 mux outputs so's the system reads only one output. This last mux needs only 2 address lines. That way you use a total of 6 lines (5 address lines and 1 input line ) to read all your 30 inputs.

Hi, for Uno you will need 4 x 74hc4051. All 4 can share same 3 digital pins. Each '4051 feeds separate Arduino analog input. This gives total of 32 + 2 analog inputs.

Unfortunately 3 x '4051 would only give 24 + 3 analog inputs, so not enough.

It really boils down to how much i/o you wish to use and how it's configured 5 digout + 1 anin by my method or 3 digout + 4 anin by Paul's method

If you need a lot of I/O You can use a multiplex chip to other multiplex chips. The below is a 4051 chip setup. The bottom 4067 is a similar chip.

http://playground.arduino.cc/Learning/4051

https://www.sparkfun.com/products/9056?gclid=CMHq1f_pur4CFaYF7AodpHQAcQ

If you're really after fast readings, I would go with a multichannel external ADC such as MCP3208 http://www.digikey.com/product-search/en?FV=fff40027%2Cfff80183&k=mcp3208&mnonly=0&newproducts=0&ColumnSort=1000011&page=1&stock=0&pbfree=0&rohs=0&quantity=&ptm=0&fid=0&pageSize=25 Each conversion takes 3 SPI transfers, see page 21 of datasheet, at 2 MHz SPI speed, so 12uS vs 110uS, and provides 12-bit results. http://ww1.microchip.com/downloads/en/DeviceDoc/21298e.pdf and will not have the annoying channel-to-channel 'interference't that onboard ADC suffers (and made worse by external analog muxes). 3 SPI pins, 4 chip select pins, 32 channels of readings.

i HAVE ATTACHED THE RELEVANT CIRCUIT DIAGRAM AND ASSOCIATED TRUTH TABLE .
I would like to know how to create time frame in arduino.Can some one suggest me Create time frame here

int sensorArray[32] ;
int selectPinZero = 8;
int selectPinOne = 9;
int selectPinTwo = 10;
int selectpinthree=11;
int inputPinOne = 0;
int inputPinTwo = 1;

static float ARDUINO_ANALOG_SCALING = 0.00488758;
int sensor1;
int sensor2;
int voltage1;
int voltage2;
int Current_Sensor1;
int Current_Sensor2;

int array[17][5]={
                    {0,0,0,0,0},
                    {0,0,0,0,1},
                    {0,0,0,1,0},  
                    {0,0,0,1,1},
                    {0,0,1,0,0},
                    {0,0,1,0,1},
                    {0,0,1,1,0},
                    {0,0,1,1,1},
                    {0,1,0,0,0},
                    {0,1,0,0,1 },
                    {0,1,0,1,0},
                    {0,1,0,1,1},
                    {0,1,1,0,0 },
                    {0,1,1,0,1},
                    {0,1,1,1,0 },
                    {0,1,1,1,1}, 
                    {1,0,0,0,0} 
                 };



void setup(){

  pinMode(selectPinZero, OUTPUT);
  pinMode(selectPinOne, OUTPUT);
  pinMode(selectPinTwo, OUTPUT);
  pinMode(selectpinthree,OUTPUT);

  pinMode(inputPinOne, INPUT);
  pinMode(inputPinTwo, INPUT);
}


 void loop()
{

  for(row=0;row<17;row++)
  {
    for(column=0;column<5;column++);
    {
      digitalWrite(Enablepin,array[row][column]);
      digitalWrite(selectPinZero,array[row][column+1]);
      digitalWrite(selectPinOne,array[row][column+2]);
      digitalWrite(selectPinTwo,array[row][column+3]);  
      digitalWrite(selectpinthree,array[row][column+4]);  
      sensor1=analogRead(inputPinOne);
      sensor2=analogRead(inputPinTwo);
      voltage1=sensor1 * ARDUINO_ANALOG_SCALING;
      voltage2=sensor2* ARDUINO_ANALOG_SCALING;
      Current_Sensor1=(10*voltage1)-25;
      Current_Sensor2=(10*voltage2)-25;

    }
  }
}

Dear all,
I am trying to read 30 analog value Using arduino UNO Board. using Mux network. Could someone help me how to create a time frame In arduino like in Truth table.Truth table as given below image. Ao and A1 analog pin read

int sensorArray[32] ;
int selectPinZero = 8;
int selectPinOne = 9;
int selectPinTwo = 10;
int selectpinthree=11;
int inputPinOne = 0;
int inputPinTwo = 1;

static float ARDUINO_ANALOG_SCALING = 0.00488758;
int sensor1;
int sensor2;
int voltage1;
int voltage2;
int Current_Sensor1;
int Current_Sensor2;

int array[17][5]={
                    {0,0,0,0,0},
                    {0,0,0,0,1},
                    {0,0,0,1,0},  
                    {0,0,0,1,1},
                    {0,0,1,0,0},
                    {0,0,1,0,1},
                    {0,0,1,1,0},
                    {0,0,1,1,1},
                    {0,1,0,0,0},
                    {0,1,0,0,1 },
                    {0,1,0,1,0},
                    {0,1,0,1,1},
                    {0,1,1,0,0 },
                    {0,1,1,0,1},
                    {0,1,1,1,0 },
                    {0,1,1,1,1}, 
                    {1,0,0,0,0} 
                 };



void setup(){

  pinMode(selectPinZero, OUTPUT);
  pinMode(selectPinOne, OUTPUT);
  pinMode(selectPinTwo, OUTPUT);
  pinMode(selectpinthree,OUTPUT);

  pinMode(inputPinOne, INPUT);
  pinMode(inputPinTwo, INPUT);
}


 void loop()
{

  for(row=0;row<17;row++)
  {
    for(column=0;column<5;column++);
    {
      digitalWrite(Enablepin,array[row][column]);
      digitalWrite(selectPinZero,array[row][column+1]);
      digitalWrite(selectPinOne,array[row][column+2]);
      digitalWrite(selectPinTwo,array[row][column+3]);  
      digitalWrite(selectpinthree,array[row][column+4]);  
      sensor1=analogRead(inputPinOne);
      sensor2=analogRead(inputPinTwo);
      voltage1=sensor1 * ARDUINO_ANALOG_SCALING;
      voltage2=sensor2* ARDUINO_ANALOG_SCALING;
      Current_Sensor1=(10*voltage1)-25;
      Current_Sensor2=(10*voltage2)-25;

    }
  }
}

cd74hc4067.pdf (385 KB)

MC14067B-D.PDF (137 KB)

At work so cannot check but I don’t think you need the column for/loop

for(column=0;column<5;column++);

as your explicitly reading columns with

      digitalWrite(Enablepin,array[row][column]);
      digitalWrite(selectPinZero,array[row][column+1]);
      digitalWrite(selectPinOne,array[row][column+2]);
      digitalWrite(selectPinTwo,array[row][column+3]);  
      digitalWrite(selectpinthree,array[row][column+4]);

I have not looks at the mux data sheet but do you really need to manipulate the enable pin?
You can reduce your memory usage by making array byte size instead of int size or get rid of it all together by using bit manipulation on a for/loop that counts from 0x00 to 0x0F.

Something like this (un-tested)

const int selectPinZero = 8;
const int selectPinOne = 9;
const int selectPinTwo = 10;
const int selectpinThree=11;
const int inputPinOne = A0;
const int inputPinTwo = A1;

const float ARDUINO_ANALOG_SCALING = 0.00488758;
int sensor1;
int sensor2;
float voltage1;
float voltage2;
int Current_Sensor1;
int Current_Sensor2;


void setup(){
  
  pinMode(selectPinZero, OUTPUT);
  pinMode(selectPinOne, OUTPUT);
  pinMode(selectPinTwo, OUTPUT);
  pinMode(selectpinThree,OUTPUT);
  
  pinMode(inputPinOne, INPUT);
  pinMode(inputPinTwo, INPUT);
}


void loop()
{
  
  for(byte x=0;x<16;x++)
  {
    digitalWrite(selectPinZero,bitRead(x,0));
    digitalWrite(selectPinOne,bitRead(x,1));
    digitalWrite(selectPinTwo,bitRead(x,2));
    digitalWrite(selectpinThree,bitRead(x,3));
    sensor1=analogRead(inputPinOne);
    sensor2=analogRead(inputPinTwo);
    voltage1=sensor1 * ARDUINO_ANALOG_SCALING;
    voltage2=sensor2* ARDUINO_ANALOG_SCALING;
    Current_Sensor1=(10*voltage1)-25;
    Current_Sensor2=(10*voltage2)-25;
    
  }
}

See blink without delay in the example sketches in the IDE. Lets you control how often something is performed.

Hi amps-n,

I can see an error in your sketch. When the loop counter “column” is greater than zero, the code will attempt to read columns from the array that do not exist. There is no need for this inner for-loop that I can see. In fact I see no need for the array either. It contains only a binary count. You can get the settings for each of the select pins by using bitRead() on the “row” loop counter.

Also I don’t understand why you need an Arduino pin for the enable pins on the multiplexors. You could connect the enable pins to gnd. Is this for future expansion?

Paul

Deja-vu I responded to this in another thread somewhere.

void loop()
{
  
  for(byte x=0;x<16;x++)
  {
    digitalWrite(selectPinZero,bitRead(x,0));
    digitalWrite(selectPinOne,bitRead(x,1));
    digitalWrite(selectPinTwo,bitRead(x,2));
    digitalWrite(selectpinthree,bitRead(x,3));
    sensor1=analogRead(inputPinOne);
    sensor2=analogRead(inputPinTwo);
    voltage1=sensor1 * ARDUINO_ANALOG_SCALING;
    voltage2=sensor2* ARDUINO_ANALOG_SCALING;
    Current_Sensor1[x]=(10*voltage1)-25;
    Current_Sensor2[x]=(10*voltage2)-25;
    delay(1000);
  }
  
  for(int i=0; i<16;i++)
  {
   Serial.print("Currentsensor1:");
  Serial.println( Current_Sensor1[i]);
    Serial.print("Currentsensor2:");
  Serial.println( Current_Sensor2[i]);
  Serial.println(".......................");
  
  
  }
    
}

i made changes Like This after all seeing Views

It seems that this is the same problem (or, at least, it seems related to that one) that you're discussing here: http://forum.arduino.cc/index.php?topic=241328.new#new

Please don't cross-post and continue in one single thread.

int array[17][5]={
                    {0,0,0,0,0},
                    {0,0,0,0,1},
                    {0,0,0,1,0},  
                    {0,0,0,1,1},
                    {0,0,1,0,0},
                    {0,0,1,0,1},
                    {0,0,1,1,0},
                    {0,0,1,1,1},
                    {0,1,0,0,0},
                    {0,1,0,0,1 },
                    {0,1,0,1,0},
                    {0,1,0,1,1},
                    {0,1,1,0,0 },
                    {0,1,1,0,1},
                    {0,1,1,1,0 },
                    {0,1,1,1,1}, 
                    {1,0,0,0,0} 
                 };

Using 1360 bits of a precious resource to store 85 bits of information is not the way to go.

Here is mine updated code. But i dont know how to keep time frame Here.Like PDF attacged,
As we know using mUX we cant read at once .SO i wanna activate pins particular time frame and each value get stored in array value of current .

Question how to keep time frame Here.

void loop()
{
  
  for(byte x=0;x<16;x++)
  {
    digitalWrite(selectPinZero,bitRead(x,0));
    digitalWrite(selectPinOne,bitRead(x,1));
    digitalWrite(selectPinTwo,bitRead(x,2));
    digitalWrite(selectpinthree,bitRead(x,3));
    sensor1=analogRead(inputPinOne);
    sensor2=analogRead(inputPinTwo);
    voltage1=sensor1 * ARDUINO_ANALOG_SCALING;
    voltage2=sensor2* ARDUINO_ANALOG_SCALING;
    Current_Sensor1[x]=(10*voltage1)-25;
    Current_Sensor2[x]=(10*voltage2)-25;
Serial.print("Currentsensor1:");
  Serial.println( Current_Sensor1[x]);
    Serial.print("Currentsensor2:");
  Serial.println( Current_Sensor2[x]);
  Serial.println(".......................");
  


    delay(1000);
  }

  
  
  
  
}

TIME -TABLE.pdf (29.6 KB)