Different Voltage Output on Grove MQ9 gas sensor when plugged into its own Arduino vs. grouped with other sensors

Hello!

I have created a monitoring system for a lab that has a sound sensor, oxygen sensor, temp, humidity, CO2 and CO. When I am using the 5V pin on the arduino with the MQ9 gas sensor from Grove all by itself (no other sensors connected), I get the correct voltage output. When I combine it in parallel with the other sensors, the output voltage more then doubles in the same exact conditions. Does anyone know why this is? If you would like to read the code of the full system, here it is:

#include "thingProperties.h"

// Temp and Humid needed info
#include <DHT.h>
#define DHTPIN 8   
#define DHTTYPE DHT22   
DHT dht(DHTPIN, DHTTYPE);

// CO2 sensor needed info
#define MG_PIN (0)     // define which analog input channel you are going to use
#define BOOL_PIN (2)
#define DC_GAIN (8.5)   // define the DC gain of amplifier

// Software Related Macros
#define READ_SAMPLE_INTERVAL (50)    // define how many samples you are going to take in normal operation
#define READ_SAMPLE_TIMES (5)     // define the time interval (in milliseconds) between each sample in normal operation

// Application Related Macros
#define ZERO_POINT_VOLTAGE (0.234) // define the output of the sensor in volts when the concentration of CO2 is 400PPM
#define REACTION_VOLTAGE (0.020) // define the voltage drop of 
float CO2Curve[3] = {2.602, ZERO_POINT_VOLTAGE, (REACTION_VOLTAGE/(2.602-3))};   

// Oxygen sensor needed info
#include <DFRobot_OxygenSensor.h>
#define Oxygen_IICAddress ADDRESS_3
#define COLLECT_NUMBER  10 // collect number, the collection range is 1-100.
DFRobot_OxygenSensor oxygen;

// Timers for sensor readings
unsigned long previousMillisTemperature = 3509999;
unsigned long previousMillisSound = 0;
unsigned long previousMillisOtherSensors = 0;

// Intervals
const long intervalTemperature = 3600000; // 1 hour
const long intervalSound = 20; // 0.04 seconds
const long intervalOtherSensors = 2000; // 1 second

void setup() {
  Serial.begin(9600);
  initProperties();
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);

  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();

  // Initialize sensors
  pinMode(sensor_volt_co, INPUT);
  dht.begin();
  pinMode(BOOL_PIN, INPUT);
  digitalWrite(BOOL_PIN, HIGH);

  while(!oxygen.begin(Oxygen_IICAddress)) {
    Serial.println("I2c device number error !");
  }
  Serial.println("I2c connect success !");
}

void loop() {
  ArduinoCloud.update();
  unsigned long currentMillis = millis();

  // Temperature and Humidity reading every hour
  if (currentMillis - previousMillisTemperature >= intervalTemperature) {
    previousMillisTemperature = currentMillis;
    readTemperatureHumidity();
  }

  // Sound sensor reading every 0.04 seconds
  if (currentMillis - previousMillisSound >= intervalSound) {
    previousMillisSound = currentMillis;
    readSoundSensor();
  }

  // Other sensors reading every second
  if (currentMillis - previousMillisOtherSensors >= intervalOtherSensors) {
    previousMillisOtherSensors = currentMillis;
    readOtherSensors();
  }
}

void readTemperatureHumidity() {
  humidity = dht.readHumidity();
  temperature_far = dht.readTemperature(true);  // Read temperature in Fahrenheit
  cel = dht.readTemperature();
  Serial.print("Humidity: ");
  Serial.print(humidity);
  Serial.print("%  Temperature: ");
  Serial.print(temperature_far);
  Serial.println("F");

  if (temperature_far > 80) {
    tempLED = false;  // Update soundLED without redeclaring it
  } else {
    tempLED = true;  // Update soundLED without redeclaring it
  }

  if (humidity > 60) {
  humidityLED = false;  // Update soundLED without redeclaring it
  } else {
    humidityLED = true;  // Update soundLED without redeclaring it
  }
}

void readSoundSensor() {
static int count = 0;
  static float maxSoundValue = 0;

  float rawsensorvalue = analogRead(A1);
  if (rawsensorvalue > maxSoundValue) {
    maxSoundValue = rawsensorvalue;
  }

  count++;

  if (count == 15) { 
    float soundsensorvalue = maxSoundValue;
    float y = 0.17 * soundsensorvalue + 65;

    soundsensor = y;
    Serial.print("sound level: ");
    Serial.println(soundsensor);
    
    // Reset for next 25 data points
    count = 0;
    maxSoundValue = 0;
  }
  
  // soundLED
  if (soundsensor > 89) {
    soundLED = false;  // Update soundLED without redeclaring it
  } else {
    soundLED = true;  // Update soundLED without redeclaring it
  }
}

void readOtherSensors() {
  // CO sensor Code:
  float sensorValue;
  sensorValue = analogRead(A3);
  sensor_volt_co = (sensorValue/1024*5.0)*10000;
  Serial.print("sensor_volt = ");
  Serial.print(sensor_volt_co);
  Serial.println("V");
  delay(1000);
  /*
  int sensorValue = analogRead(A3);
  sensor_volt_co = (float)sensorValue / 1024 * 5.0;
  float rS_gas = (5.0 - sensor_volt_co) / sensor_volt_co;
  float r0 = 0.91;
  float ratio = rS_gas / r0;
  Serial.print("CO Sensor Voltage: ");
  Serial.println(sensor_volt_co);
*/
  if (sensor_volt_co > 250) {
  coLED = false;  // Update soundLED without redeclaring it
  } else {
    coLED = true;  // Update soundLED without redeclaring it
  }

  // Oxygen Sensor Code
  oxygenData = oxygen.getOxygenData(COLLECT_NUMBER);
  Serial.print("Oxygen concentration: ");
  Serial.print(oxygenData);
  Serial.println("% vol");

  if (oxygenData < 19.5 ) {
  o2LED = false;  // Update soundLED without redeclaring it
  } else {
    o2LED = true;  // Update soundLED without redeclaring it
  }

  // CO2 sensor code
   volts = MGRead(MG_PIN);
  percentage_co2 = MGGetPercentage(volts, CO2Curve);

  if (percentage_co2 >  700) {
  co2LED = false;  // Update soundLED without redeclaring it
  } else {
    co2LED = true;  // Update soundLED without redeclaring it
  }
 Serial.print(volts);
  
  Serial.print("CO2 concentration: ");
  if (percentage_co2 == -1) {
    Serial.print("<400");
    percentage_co2 = 400;
  } else {
    Serial.print(percentage_co2);
  }
  Serial.println("ppm");
}

float MGRead(int mg_pin) {
  int i;
  float v = 0;
  for (i = 0; i < READ_SAMPLE_TIMES; i++) {
    v += analogRead(mg_pin);
    delay(READ_SAMPLE_INTERVAL);
  }
  v = (v / READ_SAMPLE_TIMES) * 5 / 1024;
  return v;  
}

int MGGetPercentage(float volts, float *pcurve) {
  if ((volts / DC_GAIN) >= ZERO_POINT_VOLTAGE) {
    return -1;
  } else { 
    return pow(10, ((volts / DC_GAIN) - pcurve[1]) / pcurve[2] + pcurve[0]);
  }
}

void onSoundsensorChange() {
  // Add your code here to act upon Soundsensor change
}

void onSensorVoltChange() {
  // Add your code here to act upon SensorVolt change
}

void onHumidityChange() {
  // Add your code here to act upon Humidity change
}

void onTemperatureFarChange() {
  // Add your code here to act upon TemperatureFar change
}

void onPercentageChange() {
  // Add your code here to act upon Percentage change
}

void onOxygenDataChange() {
  // Add your code here to act upon OxygenData change
}

void onSensorVoltCoChange() {
  // Add your code here to act upon SensorVoltCo change
}

void onPercentageCo2Change() {
  // Add your code here to act upon PercentageCo2 change
}

void onCelChange() {
  // Add your code here to act upon Cel change
}

/*
  Since Volts is READ_WRITE variable, onVoltsChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onVoltsChange()  {
  // Add your code here to act upon Volts change
}

Most likely, this is a wiring, inadequate power supply, calibration or burn-in problem.

1 Like

Post an annotated schematic showing all power sources and wire sizes to the sensors. Also post links to technical information on all of the hardware devices.