Hello,
I'm kinda new to Arduino and would be needing help with an Arduino nano based gas sensor circuit I'm working on. The sensing mechanism is based on a change in the initial resistance of the sensor material. In my code, the initial resistance R1 of the sensor (before exposure to target gas) and final resistance of the sensor R2 (after exposure to target gas) are captured and sensitivity (related to gas concentration) is computed with the formula S% = ((R2-R1)/R1)*100.
Since the gas sensor is a chemi-resistor, I am using a simple voltage divider circuit to measure the changing R1 & R2. There's a 60 seconds delay after R1 is measured, to allow for sensor response when exposed to the target gas and R2 is then measured. The known resistor is an 18MOhm resistor, the unknown resistor (sensor) has an initial resistance of about 5MOhm and when exposed to the target gas, rises to about 35-40MOhm.
My problem is that the measured R1 and R2 values most times are inaccurate, unsteady and sometimes goes as low as 0.02MOhm and stays there. I have included a low pass filter with a cut-off freq. of 5Hz and an op-amp voltage follower at the Vout, before feeding the Arduino nano Analog input A0 pin. I have read where it says including a 0.1uF capacitor at the analog input A0 may help to steady the readings. When I do this, the R1 and R2 readings stay constantly at 0.02MOhms and doesn't change even with exposure to the target gas. The values are steady and normal only when I replace the sensor with a regular 10MOhm resistor. I'm also using a DHT11 to track the humidity and temperature changes.
I'll really appreciate some assistance as this is my final year project and I'm kinda new to using Arduino. I have included my code below...
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#define DHTPIN 2
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
int analogPin = 0;
int raw = 0;
int Vin = 5;
float Vout = 0;
float Ri = 18000000; //known resistor
float R1 = 0; //unknown(sensor resistance)
float buffer = 0;
float R2; //final resistance
float s;
void setup() {
Serial.begin(9600);
Serial.println("CLEARDATA");
Serial.println("CLEARSHEET");
Serial.println("LABEL, DATE, TIME, RH %, TEMP *C, S %, R1 *MOhm, R2 *MOhm, Glucose mg/dL");
dht.begin();
}
void loop() {
delay(2000);
float h = dht.readHumidity();
float t = dht.readTemperature();
raw = analogRead(analogPin);
if (raw)
{
buffer = raw * Vin;
Vout = (buffer) / 1024.0;
buffer = (Vin / Vout) - 1;
R1 = (Ri * buffer)/1000000;
delay(60000);
}
raw = analogRead(analogPin);
if (raw)
{
buffer = raw * Vin;
Vout = (buffer) / 1024.0;
buffer = (Vin / Vout) - 1;
R2 = (Ri * buffer)/1000000;
s = ((R2 - R1) / R1) * 100;
}
if (isnan(h) || isnan(t) || isnan(s) || isnan(R1) || isnan(R2)) {
Serial.println("Failed to read from Humidty & Acetone sensor!");
return;*/
}
Serial.print("DATA,DATE,TIME,");
Serial.print(h);
Serial.print(",");
Serial.print(t);
Serial.print(",");
Serial.print(s);
Serial.print(",");
Serial.print(R1);
Serial.print(",");
Serial.println(R2);
delay(10000);
}
