user50425: I am trying to interface 4052 demux with arduino, but my program is not working as high is not displayed on serial monitor corresponding to select lines.
//output coming from demux pins
int sensorValue0=A0;  
int sensorValue1=A1;
int sensorValue2=A2;
int sensorValue3=A3;

void setup() {
  Serial.begin(9600);
  Serial.println("start");
  //select pins connected A,B connected to 2 and 3
  pinMode(2,OUTPUT);
  pinMode(3,OUTPUT);
}

void loop() {
  digitalWrite(2,LOW);
  digitalWrite(3,LOW);
  analogRead(sensorValue0);
  //Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  int voltage0= sensorValue0 * (5.0 / 1023.0); 
  Serial.println("volatge0");
  Serial.println(voltage0); 
}


user4143: You are ignoring the value read by analogRead().  You are then using the value A0 (14) in your sum to calculate the voltage.
Instead:
int adcReading = analogRead(sensorValue0);
int voltage0 = adcReading * (5.0 / 1023.0);

Although I think what you really meant to write was, in total:
int sensorPin = A0;
int sensorValue0;//output coming from demux pins
int sensorValue1;
int sensorValue2;
int sensorValue3;

void setup() {
Serial.begin(9600);
  Serial.println("start");
  pinMode(2,OUTPUT);//selecr pins connected A,B connected to 2 and 3
  pinMode(3,OUTPUT);
}

void loop() {
  digitalWrite(2,LOW);
  digitalWrite(3,LOW);
  sensorValue0 = analogRead(sensorPin);
  float voltage0 = sensorValue0 * (5.0 / 1023.0);//Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  Serial.print("voltage0 = ");
  Serial.println(voltage0); 
}

Note that the value sensorPin is where you read the voltage from, and sensorValue0 is where you store that reading. Also note the use of a float type to store the calculated voltage, since an int will give you only values of 0, 1, 2, 3, 4 or 5 in this situation (so, pretty meaningless really).

50425: <p>I am trying to interface 4052 demux with arduino, but my program is not working as high is not displayed on serial monitor corresponding to select lines.</p>

<pre><code>//output coming from demux pins
int sensorValue0=A0;  
int sensorValue1=A1;
int sensorValue2=A2;
int sensorValue3=A3;

void setup() {
  Serial.begin(9600);
  Serial.println("start");
  //select pins connected A,B connected to 2 and 3
  pinMode(2,OUTPUT);
  pinMode(3,OUTPUT);
}

void loop() {
  digitalWrite(2,LOW);
  digitalWrite(3,LOW);
  analogRead(sensorValue0);
  //Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  int voltage0= sensorValue0 * (5.0 / 1023.0); 
  Serial.println("volatge0");
  Serial.println(voltage0); 
}
</code></pre>
 4143: <p>You are ignoring the value read by <code>analogRead()</code>.  You are then using the value <code>A0</code> (14) in your sum to calculate the voltage.</p>

<p>Instead:</p>

<pre><code>int adcReading = analogRead(sensorValue0);
int voltage0 = adcReading * (5.0 / 1023.0);
</code></pre>

<p>Although I <em>think</em> what you really meant to write was, in total:</p>

<pre><code>int sensorPin = A0;
int sensorValue0;//output coming from demux pins
int sensorValue1;
int sensorValue2;
int sensorValue3;

void setup() {
Serial.begin(9600);
  Serial.println("start");
  pinMode(2,OUTPUT);//selecr pins connected A,B connected to 2 and 3
  pinMode(3,OUTPUT);
}

void loop() {
  digitalWrite(2,LOW);
  digitalWrite(3,LOW);
  sensorValue0 = analogRead(sensorPin);
  float voltage0 = sensorValue0 * (5.0 / 1023.0);//Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  Serial.print("voltage0 = ");
  Serial.println(voltage0); 
}
</code></pre>

<p>Note that the value <code>sensorPin</code> is where you read the voltage from, and <code>sensorValue0</code> is where you store that reading. Also note the use of a <code>float</code> type to store the calculated voltage, since an <code>int</code> will give you only values of 0, 1, 2, 3, 4 or 5 in this situation (so, pretty meaningless really).</p>
