This project demonstrates how to interface the MQ135 Gas Sensor with Arduino to measure CO2 levels in parts per million (ppm). When the CO2 level exceeds a threshold (650 ppm), the display will flash a warning message prompting the user to open a window for ventilation.
- Arduino Nano
- MQ135 Gas Sensor
- 128x64 OLED Display (SSD1306)
- Jumper Wires
-
OLED Display:
- VCC to 5V
- GND to GND
- SDA to A4 (SDA on Arduino Nano)
- SCL to A5 (SCL on Arduino Nano)
-
MQ-135 Sensor:
- VCC to 5V
- GND to GND
- A0 to A0 on Arduino Nano
If you are wondering why the pinouts are different in the photo its because the photo uses diffent display, i have used 4 pin oled display and have given the pinouts accordingly, refer those.
To calculate the Ro values in clean air, follow these steps:
- Download the MQ-135 Library and preheat the sensor for 24 hours before reading the Ro values.
- Use the following code to read the Ro values:
#include "MQ135.h"
void setup (){
Serial.begin (9600);
}
void loop() {
MQ135 gasSensor = MQ135(A0); // Attach sensor to pin A0
float rzero = gasSensor.getRZero();
Serial.println (rzero);
delay(1000);
}
- Once you have obtained the Ro values, navigate to
Documents > Arduino > libraries > MQ135-master
folder and open theMQ135.h
file. - Change the
RLOAD
andRZERO
values in the file:
/// The load resistance on the board
#define RLOAD 22.0
/// Calibration resistance at atmospheric CO2 level
#define RZERO 5804.99
- Scroll down and replace the
ATMOCO2
value with the current Atmospheric CO2 level (e.g., 411.29):
/// Atmospheric CO2 level for calibration purposes
#define ATMOCO2 397.13
- Connect the components according to the pinout provided.
- Install the required libraries:
- Adafruit GFX Library: Download from Adafruit
- Adafruit SSD1306 Library: Download from Adafruit
- MQ135 Library: Download from Arduino Library Manager
- Upload the provided Arduino code to your Arduino Nano board.
- Open the serial monitor or connect display to view the CO2 readings and warnings when CO2 levels are high.
Integrate the system with home automation platforms like Home Assistant to monitor CO2 levels in closed rooms. Automatically trigger actions such as opening windows or activating ventilation systems when CO2 levels exceed a predefined threshold. (Will probably use an ESP32)
This project is licensed under the MIT License - see the LICENSE file for details.