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)
topinMode(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);
}
pinMode(A0,INPUT_PULLUP);
does it improve the readings?pinMode(A0,INPUT_PULLUP);
topinMode(A0,INPUT);
I had read that page before typing out my sketch, but I didn't pay much attention to the line that said: "Be aware however that turning on a pull-up will affect the values reported by analogRead()." Is this because in a short time interval like 1000 ms there isn't enough time for the voltage to drop to low and then rise again to the correct input given from the sensor?