const int mq135Pin = A0; // Analog pin for MQ-135
const int mq7Pin = A1; // Analog pin for MQ-7
void setup() {
Serial.begin(9600);
}
void loop() {
// Read analog values from MQ-135 and MQ-7 sensors
int mq135Value = analogRead(mq135Pin);
int mq7Value = analogRead(mq7Pin);
// Convert analog values to gas concentration values
float mq135PPM = MQ135_getPPM(mq135Value);
float mq7PPM = MQ7_getPPM(mq7Value);
// Print the values to the Serial Monitor
Serial.print("MQ-135 PPM: ");
Serial.print(mq135PPM);
Serial.print("\tMQ-7 PPM: ");
Serial.println(mq7PPM);
delay(1000); // Adjust the delay as needed
}
float MQ135_getPPM(int rawValue) {
// Convert raw sensor value to PPM concentration
// Replace these calibration values with your own
float RS_air = 60.0; // Sensor resistance at clean air
float RL = 10.0; // Load resistance
float ratio = (1023.0 - rawValue) / rawValue;
return 100.0 * pow(ratio, -2.805);
}
float MQ7_getPPM(int rawValue) {
// Convert raw sensor value to PPM concentration
// Replace these calibration values with your own
float RL = 10.0; // Load resistance
float Vcc = 5.0; // Arduino Uno voltage
return (Vcc - ((rawValue / 1023.0) * Vcc)) / (rawValue / 1023.0) * RL;
}
/*This code assumes you have the MQ-135 connected to analog pin A0 and the MQ-7 connected to analog pin A1 of the Arduino Uno. Also, please note that the code includes calibration values which you might need to adjust based on your specific setup and calibration process.
The MQ135_getPPM and MQ7_getPPM functions are used to convert the raw analog values from the sensors into parts per million (PPM) gas concentration values. You may need to adjust the calibration values in these functions to match your specific sensors and environment.
Remember, the MQ sensors require some time to warm up before accurate readings can be obtained. So, it's a good practice to let the sensors stabilize for a few minutes after powering up your Arduino.*/