user47497: I have been trying to interface the Figaro KE25 2 lead fuel cell type oxygen gas sensor with Arduino Uno. I am not getting the required output on the Serial Monitor for regular air (Oxygen concentration of 19%).
I have attached the sketch I have typed out, the output I have obtained on the Serial Monitor, the output(mV) vs Oxygen concentration (%) graph of the Figaro KE25 sensor I have obtained from the datasheet, the chemical reactions governing the working of the sensor,the circuit diagram I have used, and the construction of the sensor.
In this question; I will explain the sensor first, then my circuit, then my sketch, and lastly the problem I have with my output.
In electronics, the Anode is the positive electrode and the cathode is the negative electrode. In electrochemistry, the Anode is the Negative electrode and the Cathode is the positive electrode. Do check the image of the construction of the sensor I have provided obtained from the datasheet.[![image of the construction of the sensor][1]][1] Full Technical Datasheet
The Cathode, that is, the positive electrode is the sensing electrode (Oxygen gets consumed here and an electric current is generated). Since a current is being generated by the sensor (fuel cell), no power supply needs to be given to the sensor. Check the image of the chemical reactions provided (obtained from the full technical datasheet of the sensor). Technical Datasheet
The sensor in question is an analog voltage type sensor. Keeping this and everything I have mentioned above in mind, I have constructed the following circuit with Arduino Uno. Refer the picture I have put up. I have connected the Cathode (the sensing positive electrode, red in colour) to the Arduino's analog A0 pin and the Anode (negative electrode) to the Arduino's ground. 
The sketch I have used is as follows:
 /*the analog pin of the alcohol sensor goes into analog pin A0 of the  
 Arduino*/

 void setup()
 {
     Serial.begin(9600); //sets the baud rate
 }

 void loop()
 {
     float v1;
     float oxy = 0.0;
     float v2 = 0.0;
     pinMode(A0,INPUT_PULLUP);

     /*To make sure that reading is zero when the circuit is open*/

     v1 = analogRead(A0); 

     /*reads the analog value from the Oxygen gas sensor and this value can
     be anywhere from 0 to 1023 (10 bit ADC used in Arduino Uno)*/ 

     if(v1>900) //To make sure that reading is zero when the circuit is open
     {
         v1=0;
     }
     v2 = (v1*3000)/992; 

     /*The above line calculates the output of the sensor in mV using the
     fact that a HIGH reading in an input pin of an Arduino Uno board is
     equivalent to a voltage of 3V or higher. When I displayed just 'v1',
     the lowest of the high values I got was 992. So I equated it to 3V
     (3000mV) and used the unitary method to find out what a non-HIGH v1 
     value would be in terms of mV.*/

     oxy = v2/0.6; 

     /*The above line calculates the Oxygen concentration from the mV output 
     of the sensor using the output(mV) vs concentration(%) graph from the 
     sensor's datasheet. The graph is a straight line passing through (0,0) 
     and hence the governing equation is of the form y = m * x. Where 'y' is 
     'v2' and 'x' is Oxygen conc. in %.*/

     Serial.print("Oxygen value: ");
     Serial.print(v1);
     Serial.print("    ");
     Serial.print(v2);
     Serial.print("mV    ");
     Serial.print(oxy);//prints the Oxygen value
     Serial.println("%");

     delay(1000);
 }

he output(mV) vs Oxygen concentration(%) graph provided in the datasheet is shown below. The straight line labeled as 'KE25' is to be considered.  Product information (datasheet)
he output I have obtained on the serial monitor is as follows:

Such a high voltage from the sensor is not possible. My output reading is not possible at all. Where have I made a mistake and how do I correct it?

Update 1 : I changed the line pinMode(A0,INPUT_PULLUP) to pinMode(A0,INPUT). Now I am getting sensible values on my Serial Monitor. However, I am also getting many '0' outputs (many). I am also getting many random values (many). I need more information on how to interface a fuel cell type Oxygen sensor using Arduino Uno in terms of how to get a proper voltage reading across such a sensor. I have found no question on electrochemical, fuel cell type Oxygen gas sensor interfacing. All questions asked are regarding sensors that require a power supply. In case of fuel cell type Oxygen gas sensors, current is generated when Oxygen is sensed and hence, no power supply is required. Also, if anyone is into electrochemistry, how do I check the voltage output of a fuel cell type Oxygen gas sensor using a voltmeter? Do I use a DC voltmeter or an AC voltmeter?
Update 2: I've made changes to the code based on @EdgarB's suggestions. The output I am getting now is better but still wrong. I checked if the sensors I am using are functional using a multimeter (I confirmed if the method I am using is right, and it is), and they are. The Oxygen values I am getting now are still really low: 6-8%. I should be getting: 19-21%. I used a reference voltage of 600 mV and modified the code.
Modified code:

 void setup()

 {

     Serial.begin(9600);//sets the baud rate
     analogReference(INTERNAL);
 }

 void loop()
 {
     const float A_REF = 0.6e3;
     const float Scalc = (1/0.6);

     float v1;
     float oxy = 0.0;
     float v2 = 0.0;
     pinMode(A0, INPUT); 
     v1 = analogRead(A0);
     v2 = (v1 * A_REF) / 1024;
     oxy = v2 * Scalc;
     Serial.print("Oxygen value: ");
     Serial.print(v1);
     Serial.print("    ");
     Serial.print(v2,4);
     Serial.print("mV    ");
     Serial.print(oxy,4);//prints the Oxygen value
     Serial.println("%");
     delay(1000);
 }


Output:
  


user4143: Your problem stems from having the internal pullup resistor for A0 turned on.
The sensor is a current generator with a load resistor (plus thermistor) built in to convert the current into a voltage. By adding a pullup resistor you turn it into a voltage divider across 5V with a small current being injected into the central node:

simulate this circuit – Schematic created using CircuitLab
Since the datasheet doesn't specify the load resistance nor the source current I have made up some values to demonstrate.
If we take just the current source and load resistance RL+RT and calculate the voltage drop across that we get:
V=R×I = 5000 × 0.00001 = 50mV

Which is a reasonable value. It's a lot of oxygen, but that's because these are made-up values.
Now what would be the voltage with the pullup resistor added? Well, this is where it gets a little more complex. At times like this it's easier to just simulate the circuit in something like the falstad simulator and I can tell you it's 757.1mV (If you want to learn how to do this kind of circuit analysis manually you should learn superposition theory).
A massive change.
Obviously you're not seeing a change that big - and that's because the pullup resistor is more than just a simple resistor. There's many more factors that influence the reading, including the output impedance of the network, as well as the rest of the internal ADC circuitry.
Suffice it to say, though, adding a pullup resistor is a bad idea when using the ADC.
But you want to keep the pullup resistor so you can know if the sensor is connected or not. That's not a problem. Just turn it on and off at will:
pinMode(A0, INPUT_PULLUP);
delay(1);
bool connected = analogRead(A0) < 900;
if (connected) {
    pinMode(A0, INPUT);
    delay(1);
    v1 = analogRead(A0);
}

It's recommended to wait a moment after changing the pullup resistor state before reading from the ADC to reduce electrical noise picked up by the ADC - hence the delay(1) calls. 

47497: <p>I have been trying to interface the <strong>Figaro KE25 2 lead fuel cell type oxygen gas sensor</strong> with <strong>Arduino Uno</strong>. I am not getting the required output on the Serial Monitor for regular air (Oxygen concentration of 19%).</p>

<p>I have attached the <strong>sketch</strong> I have typed out, the <strong>output I have obtained on the Serial Monitor</strong>, the <strong>output(mV) vs Oxygen concentration (%) graph</strong> of the Figaro KE25 sensor I have obtained from the datasheet, the <strong>chemical reactions governing the working of the sensor</strong>,the <strong>circuit diagram</strong> I have used, and the <strong>construction of the sensor</strong>.</p>

<p>In this question; I will explain the sensor first, then my circuit, then my sketch, and lastly the problem I have with my output.</p>

<p>In <strong>electronics</strong>, the <strong>Anode is the positive electrode</strong> and the <strong>cathode is the negative</strong> electrode. In <strong><em>electrochemistry</em></strong>, the <strong><em>Anode is the Negative electrode</em></strong> and the <strong><em>Cathode is the positive electrode</em></strong>. Do check the image of the construction of the sensor I have provided obtained from the datasheet.[![image of the construction of the sensor][1]][1] <a href="http://www.meditronik.com.pl/doc/b0-b9999/ke25.pdf" rel="nofollow noreferrer">Full Technical Datasheet</a></p>

<p>The <strong>Cathode</strong>, that is, <strong>the positive electrode</strong> is the <strong>sensing electrode</strong> (Oxygen gets consumed here and an electric current is generated). Since a current is being generated by the sensor (fuel cell), <strong>no power supply needs to be given to the sensor</strong>. Check the image of the chemical reactions provided (obtained from the full technical datasheet of the sensor). <a href="https://i.stack.imgur.com/3uZsB.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3uZsB.jpg" alt="Chemical Reactions"></a><a href="http://www.figarosensor.com/products/entry/ke-25.html#ti" rel="nofollow noreferrer">Technical Datasheet</a></p>

<p>The sensor in question is an analog voltage type sensor. Keeping this and everything I have mentioned above in mind, I have constructed the following circuit with Arduino Uno. Refer the picture I have put up. I have connected the <strong>Cathode (the sensing positive electrode, red in colour) to the Arduino's analog A0 pin</strong> and <strong>the Anode (negative electrode) to the Arduino's ground</strong>. <a href="https://i.stack.imgur.com/HaJQd.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HaJQd.jpg" alt="Circuit"></a></p>

<p>The sketch I have used is as follows:</p>

<pre><code> /*the analog pin of the alcohol sensor goes into analog pin A0 of the  
 Arduino*/

 void setup()
 {
     Serial.begin(9600); //sets the baud rate
 }

 void loop()
 {
     float v1;
     float oxy = 0.0;
     float v2 = 0.0;
     pinMode(A0,INPUT_PULLUP);

     /*To make sure that reading is zero when the circuit is open*/

     v1 = analogRead(A0); 

     /*reads the analog value from the Oxygen gas sensor and this value can
     be anywhere from 0 to 1023 (10 bit ADC used in Arduino Uno)*/ 

     if(v1&gt;900) //To make sure that reading is zero when the circuit is open
     {
         v1=0;
     }
     v2 = (v1*3000)/992; 

     /*The above line calculates the output of the sensor in mV using the
     fact that a HIGH reading in an input pin of an Arduino Uno board is
     equivalent to a voltage of 3V or higher. When I displayed just 'v1',
     the lowest of the high values I got was 992. So I equated it to 3V
     (3000mV) and used the unitary method to find out what a non-HIGH v1 
     value would be in terms of mV.*/

     oxy = v2/0.6; 

     /*The above line calculates the Oxygen concentration from the mV output 
     of the sensor using the output(mV) vs concentration(%) graph from the 
     sensor's datasheet. The graph is a straight line passing through (0,0) 
     and hence the governing equation is of the form y = m * x. Where 'y' is 
     'v2' and 'x' is Oxygen conc. in %.*/

     Serial.print("Oxygen value: ");
     Serial.print(v1);
     Serial.print("    ");
     Serial.print(v2);
     Serial.print("mV    ");
     Serial.print(oxy);//prints the Oxygen value
     Serial.println("%");

     delay(1000);
 }
</code></pre>

<p>he output(mV) vs Oxygen concentration(%) graph provided in the datasheet is shown below. The straight line labeled as 'KE25' is to be considered. <a href="https://i.stack.imgur.com/qUd6u.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qUd6u.jpg" alt="O/P(mV) vs. O2 conc.(%)"></a> <a href="http://www.figarosensor.com/products/docs/KE%20Prod%20Info%20%281014%29.pdf" rel="nofollow noreferrer">Product information (datasheet)</a></p>

<p>he output I have obtained on the serial monitor is as follows:
<a href="https://i.stack.imgur.com/1IdtW.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1IdtW.jpg" alt="SerialMonitor"></a></p>

<p>Such a high voltage from the sensor is not possible. My output reading is not possible at all. Where have I made a mistake and how do I correct it?</p>

<blockquote>
  <p><strong>Update 1 :</strong> I changed the line <code>pinMode(A0,INPUT_PULLUP)</code> to <code>pinMode(A0,INPUT)</code>. Now I am getting sensible values on my Serial Monitor. However, I am also getting many '0' outputs <strong>(many)</strong>. I am also getting many random values <strong>(many)</strong>. I need more information on how to interface a fuel cell type Oxygen sensor using Arduino Uno in terms of how to get a proper voltage reading across such a sensor. I have found no question on electrochemical, fuel cell type Oxygen gas sensor interfacing. All questions asked are regarding sensors that require a power supply. In case of fuel cell type Oxygen gas sensors, current is generated when Oxygen is sensed and hence, no power supply is required. Also, if anyone is into electrochemistry, how do I check the voltage output of a fuel cell type Oxygen gas sensor using a voltmeter? Do I use a DC voltmeter or an AC voltmeter?</p>
  
  <p><strong>Update 2:</strong> I've made changes to the code based on @EdgarB's suggestions. The output I am getting now is better but still wrong. I checked if the sensors I am using are functional using a multimeter (I confirmed if the method I am using is right, and it is), and they are. The Oxygen values I am getting now are still really low: 6-8%. I should be getting: 19-21%. I used a reference voltage of 600 mV and modified the code.</p>
  
  <p>Modified code:</p>
</blockquote>

<pre><code> void setup()

 {

     Serial.begin(9600);//sets the baud rate
     analogReference(INTERNAL);
 }

 void loop()
 {
     const float A_REF = 0.6e3;
     const float Scalc = (1/0.6);

     float v1;
     float oxy = 0.0;
     float v2 = 0.0;
     pinMode(A0, INPUT); 
     v1 = analogRead(A0);
     v2 = (v1 * A_REF) / 1024;
     oxy = v2 * Scalc;
     Serial.print("Oxygen value: ");
     Serial.print(v1);
     Serial.print("    ");
     Serial.print(v2,4);
     Serial.print("mV    ");
     Serial.print(oxy,4);//prints the Oxygen value
     Serial.println("%");
     delay(1000);
 }
</code></pre>

<blockquote>
  <p>Output:
  <a href="https://i.stack.imgur.com/yw9Hm.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yw9Hm.jpg" alt="Output"></a></p>
</blockquote>
 4143: <p>Your problem stems from having the internal pullup resistor for A0 turned on.</p>

<p>The sensor is a current generator with a load resistor (plus thermistor) built in to convert the current into a voltage. By adding a pullup resistor you turn it into a voltage divider across 5V with a small current being injected into the central node:</p>



<p><img src="https://i.stack.imgur.com/zCEPV.png" alt="schematic"></p>



<p><sup><a href="/plugins/schematics?image=http%3a%2f%2fi.stack.imgur.com%2fzCEPV.png">simulate this circuit</a> &ndash; Schematic created using <a href="https://www.circuitlab.com/" rel="nofollow">CircuitLab</a></sup></p>

<p>Since the datasheet doesn't specify the load resistance nor the source current I have made up some values to demonstrate.</p>

<p>If we take just the current source and load resistance RL+RT and calculate the voltage drop across that we get:</p>

<pre><code>V=R×I = 5000 × 0.00001 = 50mV
</code></pre>

<p>Which is a reasonable value. It's a lot of oxygen, but that's because these are made-up values.</p>

<p>Now what would be the voltage with the pullup resistor added? Well, this is where it gets a little more complex. At times like this it's easier to just simulate the circuit in something like the <a href="http://tinyurl.com/yalptakx" rel="nofollow noreferrer">falstad simulator</a> and I can tell you it's <strong>757.1mV</strong> (If you want to learn how to do this kind of circuit analysis manually you should learn <a href="https://www.allaboutcircuits.com/textbook/direct-current/chpt-10/superposition-theorem/" rel="nofollow noreferrer">superposition theory</a>).</p>

<p>A massive change.</p>

<p>Obviously you're not seeing a change <em>that</em> big - and that's because the pullup resistor is <em>more</em> than just a simple resistor. There's many more factors that influence the reading, including the output impedance of the network, as well as the rest of the internal ADC circuitry.</p>

<p>Suffice it to say, though, adding a pullup resistor is a bad idea when using the ADC.</p>

<p>But you want to keep the pullup resistor so you can know if the sensor is connected or not. That's not a problem. Just turn it on and off at will:</p>

<pre><code>pinMode(A0, INPUT_PULLUP);
delay(1);
bool connected = analogRead(A0) &lt; 900;
if (connected) {
    pinMode(A0, INPUT);
    delay(1);
    v1 = analogRead(A0);
}
</code></pre>

<p>It's recommended to wait a moment after changing the pullup resistor state before reading from the ADC to reduce electrical noise picked up by the ADC - hence the <code>delay(1)</code> calls. </p>
