Project 2
Project 2
INTRODUCTION
1.1 INTRODUCTION
1
2
1.2 METHOD
Initially, the required hardware components are assembled. The MQ-135 gas
sensor is interfaced with the Arduino Nano using appropriate jumper wires. A 22 kΩ
load resistor is connected to the sensor to ensure proper voltage division and stable
sensor output. The 0.96-inch OLED display module is connected to the Arduino using
the SPI communication protocol to display real-time gas concentration values.
The Arduino processes the sensor data using predefined calibration constants to
estimate gas concentration values in parts per million (ppm). Separate mathematical
models and sensitivity curves are used to calculate the concentrations of CO₂, LPG,
smoke, and ammonia. The processed values are then displayed on the OLED screen in
real time.
To validate the accuracy of the MQ-135 sensor, the measured CO₂ concentration
values are compared with readings obtained from an infrared (IR) CO₂ sensor under
the same environmental conditions. The comparison helps in analyzing the
performance, accuracy, and limitations of the MQ-135 sensor for CO₂ measurement.
3
1.3 BLOCK DIAGRAM
4
CHAPTER 2
LITEATURE SURVEY
2.1 Air Quality and Carbon Monoxide Monitoring Using IoT-based System
2.2 Air Quality Monitoring Using MQ135 Gas Sensor and Arduino Uno
Authors: Manoj Kumar, Garvit Mishra, Ayush Sharma, Ashish Shaini, Sahil
Saxena
Abstract: This paper presents an Arduino Uno-based air quality monitoring
device using the MQ-135 gas sensor to detect pollutants including CO₂, NH₃,
benzene, and smoke. Sensor outputs are calibrated and converted into ppm
levels to assess air quality. Real-time readings are displayed on an LCD and
alerts are triggered when pollutant thresholds are exceeded. The authors discuss
system performance, practical limitations, and potential improvements such as
future IoT integration and advanced data analytics.
5
2.3 Air Quality Monitoring System Based on Internet of Things:
Authors: Muhammad Ghozi Arkhan, Zulhipni Reno Saputra Elsi
2.4 Smart Air Monitoring with IoT-based Multiple Gas Sensors using NodeMCU
ESP32:
Authors: (Publication in Procedia Computer Science, 2024)
Abstract: This work integrates multiple gas sensors (MQ-2, MQ-7, MQ-8,
MQ-135) with a NodeMCU ESP32 microcontroller to develop a smart air
quality monitoring system where collected data is transmitted to a cloud
platform for analysis and visualization. The project demonstrates the capability
of low-cost IoT sensors to provide continuous monitoring of CO₂, CO,
hydrogen gases, and environmental parameters like temperature and humidity.
Experimental results reveal effective detection and data communication for
practical air.
6
CHAPTER 3
SYSTEM ANALYSIS
Some existing low-cost systems use single-gas detectors that are not capable of
monitoring multiple gases simultaneously. Additionally, most conventional
systems do not offer real-time data visualization or comparative analysis for
validation of sensor readings. a parallel connection, you connect all the
positive terminals together and all the negative terminals together.
7
3.2 PROPOSED SYSTEM
8
CHAPTER - 4
SYSTEM ARCHITECTURE
Arduino Nano
MQ-135 Sensor
Buzzer
Jumper Wires
Adapter
Embedded C
Arduino IDE
9
CHAPTER 5
SOFTWARE ANALYSIS
5.1 EMBEDDED C
Embedded C is a programming language that is used in the development of
Embedded Systems. Embedded Systems are specialized systems designed to
perform very specific functions or tasks. Embedded System is the combination
of hardware and software, and the software is generally known as firmware
which is embedded into the system hardware.
Embedded C has some additional data types and keywords. There are some
special datatypes in Embedded C like sbit, sfr which are used for addressing
special function registers in memory.
The devices like air conditioners, printers, and mobile phones that we use in
our daily lives are programmed by embedded C.
10
5.1.1. INTRODUCTION OF ARDUINO C
12
from where to start the program execution.
5.1.2 INTERFACING C PROGRAMS WITH ARDUINO IDE
13
EEPROM Support – Provides non-volatile memory for data storage.
Low-Power Mode Support – Optimized for embedded applications with
power-efficient features.
14
5.2 ARDUINO IDE
15
5.2.1 INSTALLING ARDUINO IDE
The Arduino IDE 2 is an open-source project. It is a big step from its sturdy
predecessor, Arduino IDE 1.x, and comes with revamped UI, improved board
& library manager, debugger, autocomplete feature and much more.
To run Arduino IDE, go to the following website to download and install the
latest version:
Download the latest release (The download will start after you click this
link. Check your browser’s download manager or the Downloads folder on your
computer to find the downloaded file)
Double-click the executable (.exe) file.
Follow the instructions in the installation guide.
When completing the setup, leave Run Arduino IDE ticked to launch the
application, or launch it later from the Start Menu.
16
Fig.5.2 Installation steps
17
CHAPTER 6
HARDWARE ANALYSIS
18
The Arduino Nano may be small in size, but don’t let that fool you—it
packs nearly all the functionality of the larger Arduino Uno into a
compact, breadboard-friendly package. This makes it perfect for
projects where space is tight but capability still matters.
To harness the full power of the Nano, you’ll need to understand its pinout. In
this guide, we’ll walk you through the different types of pins on the
Arduino Nano so you can make the most of this compact board.
6.1.1 SPECIFICATIONS
Table.6.1 Specifications
Arduino Nano Specifications
Microcontroller ATmega328P
Architecture AVR
Operating Voltage 5 Volts
Flash Memory 32 KB of which 2 KB used
by Bootloader
SRAM 2KB
Clock Speed 16 MHz
Analog I/O Pins 8
EEPROM 1 KB
DC Current per I/O 40 milliAmps
Pins
Input Voltage (7-12) Volts
Digital I/O Pins 22
PWM Output 6
Power 19 milliAmps
Consumption
19
Fig.6.1.2 Arduino Nano Pin description
Digital Pins
Arduino Nano has 14 digital I/O pins that can be used either as digital
input or output. The pins work with 5V voltage as maximum, i.e., digital high is
5V and digital low is 0V. Each pin can provide or receive a current of 40mA,
and has a pull-up resistance of about 20-50k ohms. Each of the 14 digital pins
on the Nano pinout can be used as an input or output, using pinMode(),
digitalWrite(), and digitalRead() functions.
Other than the digital input and output functions, the digital pins have some
additional functionality as well.
PWM Pins
Each of these digital pins provide a Pulse Width Modulation signal of 8-
bit resolution. The PWM signal can be generated using analogWrite () function.
External Interrupts
When we need to provide an external interrupt to other processor or
controller we can make use of these pins. These pins can be used to enable
interrupts INT0 and INT1 respectively by using the attachInterrupt () function.
These pins can be used to trigger three types of interrupts such as interrupt on a
low value, a rising or falling edge interrupt and a change in value interrupt.
SPI Pins
When you want the data to be transmitted asynchronously you can use
these Serial Peripheral Interface pins. These pins support synchronous
communication with SCK as the synchronizing clock. Even though the
hardware has this feature, the Arduino software doesn’t have this by default.
So you have to include a library called SPI Library for using this feature.
LED
If you remember your first Arduino code, blinking LED, then you’ll
definitely came across this Pin16. The pin 16 is being connected to the blinking
LED on the board.
21
inbuilt ADC of resolution of 1024 bits (so it will give 1024 values). By default,
the pins are measured from ground to 5V. If you want the reference voltage to
be 0V to 3.3V, we can give 3.3V to AREF pin (18 th Pin) by using the
analogReference () function.
I2C
Since SPI communication also has its disadvantages such as 4 essential
pins and limited within a device. For long distance communication we use the
I2C protocol. I2C supports multi master and multi slave with only two wires.
One for clock (SCL) and another for data (SDA). For using this I2C feature we
need to import a library called Wire library.
AREF
As mentioned already the AREF- Analog Reference pin is used as a
reference voltage for analog input for the ADC conversion.
Reset
Reset pins in Arduino are active LOW pins which means if we make this
pin value as LOW i.e., 0v, it will reset the controller. Usually used to be
connected with switches to use as reset button.
22
MISO / digital pin 12 (Pin 15); MOSI on the ISCP header is connected to MOSI
/ digital pin 11 (Pin 16); and so forth. Note, MISO, MOSI, and SCK pins taken
together make up most of an SPI interface.
The Arduino Nano is a compact, breadboard-friendly microcontroller board
based on the ATmega328P (or sometimes ATmega168). It’s part of the Arduino
family and is ideal for small-scale projects where space is limited.
The Arduino Nano is a small, breadboard-friendly microcontroller used
for compact DIY electronics, robotics, automation, and IoT projects, leveraging
its small size for embedded systems, wearables, and sensor-based applications
like home automation (smart lighting, monitors), custom game controllers,
RFID locks, and even medical instruments, functioning as the brain to read
sensors and control outputs like LEDs and motors.
The Arduino Uno supports a total of 14 digital I/O pins and 6 analog inputs.
The Nano has 14 digital I/O pins as well but only 8 analog inputs.
Therefore, the Uno is better for projects needing more analog input capability.
23
Fig. 6.2.1 MQ135 Air Quality Sensor
24
Fig.6.2.2 Pin Configuration
Pin 1: VCC: This pin refers to a positive power supply of 5V that power up the
MQ135 sensor module.
Pin 2: GND (Ground): This is a reference potential pin, which connects the
MQ135 sensor module to the ground.
Pin 3: Digital Out (Do): This pin refers to the digital output pin that gives the
digital output by adjusting the threshold value with the help of a potentiometer.
This pin is used to detect and measure any one particular gas and makes the
MQ135 sensor work without a microcontroller.
25
Pin 4: Analog Out (Ao): This pin generates the analog output signal of 0V to
5V and it depends on the gas intensity. This analog output signal is
proportional to the gas vapor concentration, which is measured by the MQ135
sensor module. This pin is used to measure the gases in PPM. It is driven by
TTL logic, operates with 5V, and is mostly interfaced with microcontrollers.
To measure or detect the gases, use analog pins or digital pins. Just apply
5V to the module and you can observe that the module’s power LED turns ON
(glows) and the output LED turns OFF when no gas is detected by the module.
This means that the output of the digital pin is 0V. Note that the sensor must be
kept for preheating time for 20seconds (as mentioned in the specifications)
before the actual operation.
Now, once when the MQ135 sensor is operated to detect, then the LED
output goes high along with the digital output pin. Otherwise, use the
27
potentiometer until the output increases. Whenever the sensor detects a certain
gas concentration, the digital pin goes high (5V), otherwise it stays low (0V).
We can also use analog pins to get the same result. The output analog
values (0-5V) are read from the microcontroller. This value is directly
proportional to the gas concentration detected by the sensor. By the
experimental values, we can observe the working and reaction of the MQ135
sensor with different gas concentrations and the programming developed
accordingly.
The MQ-135 gas sensor uses SnO2, a gas-sensitive material that has
higher resistance in clean air. An increase in the number of harmful gases
decreases the resistance of the gas MQ135 sensor. To measure PPM with the
MQ-135 air quality sensor, observe the graph between (Rs/Ro) and PPM
shown below.
28
Fig.6.2.4 MQ135 PPM Graph
The typical sensitivity characteristics of the MQ135 sensor are shown in the
above graph.
Temperature is 20°C, humidity is 65%, the concentration of O2 is 21% and
load resistance RL is 20kilo ohms.
Here Ro refers to the resistance value of the sensor at 100ppm of NH3 in
clean air or fresh air.
Rs refers to the resistance of the sensor at several gas concentrations.
We can calibrate the MQ135 sensor by determining the Rs value from the
below formula,
Resistance of sensor Rs = (Vc/VRL-1)RL
After calculating the Ro and Rs values, the ratio is found, and using the
above graph we can calculate the PPM value of the particular gas, which is
to be measured.
The circuit diagram of interfacing the MQ135 air quality sensor with
Arduino is shown below. The components required are,
29
Fig.6.2.5 MQ135 Interface with Arduino
Connections are made as per the circuit diagram shown above. The MQ135
sensor’s VCC pin is connected to the Arduino’s 5V pin. This power ups the
MQ135 sensor. The analog output pin Ao and digital output pin Do of the
MQ135 sensor are connected to the Ao and pin 2 of the Arduino. Finally, the
ground pins of the MQ135 and the Arduino are connected to a common
ground. This interfacing circuit gives both digital and analog outputs of the
MQ135 air quality sensor.
When the Ao (analog output) of the MQ135 is higher than the 400, then the
30
LED turns ON, which is connected to pin 2 of the Arduino board. Else the
LED turns OFF. Observe the readings of both digital and analog outputs of the
sensor on the LCD or monitor.
Upload the Arduino code as shown below for gas detection.
void setup()
{
[Link](9600); // sets the serial port to 9600 (sets the serial
communication to 9600 baud rate)
pinMode(13, OUTPUT); (pin 13 is connected to the anode terminal of the
LED as an output)
pinMode(2, INPUT); (pin 2 of Arduino is connected to the Do pin of the
MQ135 as an input)
}
void loop()
{
sensorValue = analogRead(0); // read analogue input pin 0 (to read the
analogue input on Ao)
digitalValue = digitalRead(2); (to read and save the digital output on pin 2
of Arduino)
if (sensorValue > 400)
{
digitalWrite(13, HIGH); (if the analogue reading is greater than
400, then the LED turns ON)
}
31
else
digitalWrite(13, LOW); (if the analogue reading is less than 400,
the LED turns OFF)
[Link](sensorValue, DEC); // prints the value read
[Link](digitalValue, DEC);
delay(1000); // wait 100ms for the next reading (analogue and
digital output readings are displayed on the monitor)
}
The organic light-emitting diode (OLED) display that we’ll use in this
tutorial is the SSD1306 model: a monocolor, 0.96-inch display with 128×64
pixels as shown in the following figure.
The OLED display doesn’t require backlight, which results in a very nice
contrast in dark environments. Additionally, its pixels consume energy only
when they are on, so the OLED display consumes less power when compared
with other displays.
The model we’re using here has only four pins and communicates with the
Arduino using I2C communication protocol. There are models that come with
an extra RESET pin. There are also other OLED displays that communicate
32
using SPI communication.
6.3.1 FEATURES
Wiring to
Pin Arduino
Uno
Vin 5V
GND GND
SCL A5
33
SDA A4
If you’re using a different Arduino board, make sure you check the correct I2C
pins:
Nano: SDA (A4); SCL (A5);
MEGA: SDA (20); SCL (21);
Leonardo: SDA (20); SCL (21);
1. Open your Arduino IDE and go to Sketch > Include Library > Manage
34
Libraries. The Library Manager should open.
2. Type “SSD1306” in the search box and install the SSD1306 library
from Adafruit.
3. After installing the SSD1306 library from Adafruit, type “GFX” in the
search box and install the library.
35
Fig.6.3.4 Install DFX from Library Manager
4. After installing the libraries, restart your Arduino IDE.
After wiring the OLED display to the Arduino and installing all required
libraries, you can use one example from the library to see if everything is
working properly.
In your Arduino IDE, go to File > Examples > Adafruit SSD1306 and
select the example for the display you’re using.
36
Fig.6.3.5 Example program for OLED
Fig.6.3.6 OLED_RESET
1. Importing libraries
First, you need to import the necessary libraries. The Wire library to use I2C
and the Adafruit libraries to write to the
display: Adafruit_GFX and Adafruit_SSD1306.
38
In case you’re using a different OLED display, you may need to change
the OLED address. In our case, the address is 0x3C.
After initializing the display, add a two second delay, so that the OLED
has enough time to initialize before writing text:
Clear display, set font size, color and write text
After initializing the display, clear the display buffer with
the clearDisplay() method:
Before writing text, you need to set the text size, color and where the text
will be displayed in the OLED.
Set the font size using the setTextSize() method:
Set the font color with the setTextColor() method:
WHITE sets white font and black background.
Define the position where the text starts using the setCursor(x,y) method.
In this case, we’re setting the text to start at the (0,10) coordinates.
Finally, you can send the text to the display using the println() method, as
follows:
Then, you need to call the display() method to actually display the text on
the screen.
6.4 BUZZER
39
piezoeletric effect.
Buzzer is a kind of voice device that converts audio model into sound
signal. It is mainly used to prompt or alarm. According to different design and
application, it can produce music sound, flute sound, buzzer, alarm sound,
electric bell and other different [Link] applications include siren,
alarm device, fire alarm, air defense alarm, burglar alarm, timer, etc. It is
widely used in household appliances, alarm system, automatic production line,
low-voltage electrical equipment, electronic toys, game machines and other
products and industries. An arduino buzzer is also called a piezo buzzer. It is
basically a tiny speaker that you can connect directly to an Arduino. You can
make it sound a tone at a frequency you set. The buzzer produces sound based
on reverse of the piezoelectric effect.
For this tutorial you will need:
Breadboard
Fig.6.4.1 Buzzer
40
The pin configuration of the buzzer is shown below. It includes two pins
namely positive and negative. The positive terminal of this is represented with
the ‘+’ symbol or a longer terminal. This terminal is powered through 6Volts
whereas the negative terminal is represented with the ‘-‘symbol or short
terminal and it is connected to the GND terminal.
41
elements. In automobile alternators and central power station generator plants,
voltage regulators control the output of the plant. In an electric power
distribution system, voltage regulators may be installed at a substation or along
distribution lines so that all customers receive steady voltage independent of
how much power is drawn from the line.
This DC-DC 12V to 3.3V 5V 12V Power Module Multi Output Voltage
Conversion is also known as Buck Converter or also as Step-Down Voltage
Converter. The module is capable of altering the output of the power
source/supply before supplying it to the load so as to deliver the specified
power to your load.
The device is very flexible and easy to use. The module is powered by 6V
42
to 12V DC input, and provides three fixed DC outputs: 3.3V, 5.0V, and a third
output which is a direct connection to the DC input (input to the module).
Perfect for providing support power for your electronic design, every DIY
hobbyist should have a couple of these flexible power supplies on
their electronics workbench. They can also be used as a multi-output fixed
voltage DC power supply in electronic equipment designs.
Output power on/off switch
Two-row multiple pin outputs, easy to use and connect
Red LED illuminates when input DC power is supplied and output is
turned ON.
Outputs
o 3.3V DC at 800mA maximum current
o 5.0V DC at 800mA maximum current
o 12V DC (the 12V output is directly connected to the input, i.e. with
12VDC input, this output will be 12VDC; with 9VDC input, this
output will be 9VDC)
Small and Handy Module.
Dual-side plate design
Easy to use.
43
stopthe operation of the circuit, and operate a circuit that does not operate with
ordinary wiring
Types of Jumper Wires
Jumper wires are categorized by the connectors on their ends:
Male-to-Male (M-M): These have pins on both ends, ideal for connecting
two female sockets, such as points on a breadboard or a breadboard to a
development board.
Male-to-Female (M-F): These have a pin on one end and a socket on the
other, typically used for connecting male headers on sensors or modules to
the female GPIO pins on microcontrollers like Arduino or Raspberry Pi.
Female-to-Female (F-F): These have sockets on both ends and are used
to connect two male pins or to extend existing male-to-female
connections.
Alligator Clips: Some specialized wires have alligator clips for a more
secure, temporary grip on components or testing points, which is useful
for troubleshooting.
6.7 ADAPTER
An adapter is a device that connects otherwise incompatible electrical or
physical interfaces, enabling them to work together. Primarily used for power
conversion (AC to DC) for laptops and phones, they also adapt physical
45
connector shapes, such as in travel plugs or USB-C to HDMI converters. They
ensure compatibility without losing functionality.
46
Fig.6.7.1 Adapter
6.8 BREADBOARD
47
Fig.6.8.1 Medium Size Bread board
For those new to electronics and circuits, breadboards are often the best
place to start. That is the real beauty of breadboards--they can house both the
simplest circuit as well as very complex circuits. As you'll see later in this
tutorial, if your circuit outgrows its current breadboard, others can be be
attached to accommodate circuits of all sizes and complexities.
48
Another common use of breadboards is testing out new parts, such as
Integrated circuits (ICs). When you are trying to figure out how a part works
and constantly rewiring things, you don’t want to have to solder your
connections each time.
49
CHAPTER 7
50
Fig.7.2 Maximum Acceptable
51
Fig.7.3 Normal Condition
53
DANGEROUS).
The display is updated every few seconds to reflect real-time air
quality changes.
6. Continuous Monitoring
The entire process runs continuously in a loop.
Sensor data is updated at regular intervals, ensuring real-time air
quality monitoring.
Debug information is also sent to the serial monitor for analysis and
calibration.
54
CHAPTER 8
8.1 CONCLUSION
In this project, a low-cost and efficient system for measuring CO₂
concentration and other harmful gases in air using an Arduino Nano and MQ-
135 gas sensor was successfully designed and implemented. The system is
capable of detecting carbon dioxide, LPG, smoke, and ammonia, providing
real-time gas concentration values that are displayed on a 0.96-inch OLED
display. This enables continuous monitoring of air quality in indoor and small-
scale environments.
The proposed system can be further improved and expanded in several ways:
Integration of IoT modules such as ESP8266 or ESP32 to enable remote
monitoring through mobile or web applications
Cloud-based data logging and visualization for long-term air quality
analysis
55
Implementation of automatic alert systems using SMS, email, or mobile
notifications when gas levels exceed safety thresholds
Use of advanced calibration techniques or machine learning models to
improve gas concentration accuracy
Addition of temperature and humidity sensors to compensate for
environmental variations affecting sensor readings
Replacement or integration of high-precision infrared CO₂ sensors for
enhanced measurement accuracy
Development of a portable battery-powered version for outdoor air
quality monitoring
8.3APPLICATION
Indoor Air Quality Monitoring
The system can be used in homes, offices, classrooms, and
conference halls to continuously monitor indoor air quality and alert
occupants when harmful gas levels exceed safe limits.
Industrial Safety Monitoring
In industries such as chemical plants, factories, and workshops, the
system helps detect the presence of hazardous gases and poor air
quality, ensuring worker safety through early warning alerts.
Smart Building and Smart Home Systems
The air quality monitoring unit can be integrated into smart buildings
to automatically control ventilation systems, exhaust fans, or air
purifiers based on real-time pollution levels.
Hospitals and Healthcare Facilities
Maintaining clean air is critical in hospitals, ICUs, and laboratories.
This system helps monitor air quality to reduce the risk of airborne
contamination and protect patients and staff.
56
Educational Institutions
Schools and colleges can use the system to ensure a healthy learning
environment and also as a practical teaching tool for environmental
monitoring and IoT-based sensor applications.
Public Places Monitoring
The device can be deployed in shopping malls, theaters, airports,
railway stations, and auditoriums to monitor crowd-induced air
pollution and trigger alerts when air quality deteriorates.
Environmental Monitoring and Research
Researchers can use the system for studying air pollution trends in
different locations and for collecting environmental data for analysis
and awareness programs.
Early Warning System for Gas Leakage
The buzzer alert feature makes the system suitable for detecting
abnormal gas concentration rises due to leakage or fire-related
emissions, providing immediate alerts.
Portable Air Quality Analyzer
Due to its compact size and low power consumption, the system can
be used as a portable device for on-site air quality assessment.
IoT-Based Monitoring Systems (Future Integration)
With the addition of Wi-Fi or GSM modules, the system can be
extended for remote monitoring, cloud data logging, and mobile
notifications.
57
REFERENCES
58
APPENDIX
59
/******** BASELINE (CALIBRATE IN CLEAN AIR) ********/
int baselineADC = 265; // Adjust after observing clean-air ADC
void setup() {
[Link](9600);
[Link]();
pinMode(BUZZER_PIN, OUTPUT);
digitalWrite(BUZZER_PIN, LOW);
if () {
[Link]("SH1106 OLED not found");
while (1);
}
[Link]();
[Link]();
}
void loop() {
/******** READ MQ135 ********/
rawADC = analogRead(MQ135_PIN);
/*
MQ135 principle:
Gas ↑ → Resistance ↓ → ADC ↓ → PPM ↑
60
*/
ppm = (baselineADC - rawADC) * 10 + 400;
61
uint16_t w, h;
// LABEL
[Link](2);
String label = "CO2 (PPM)";
[Link](label, 0, 0, &x1, &y1, &w, &h);
[Link]((SCREEN_WIDTH - w) / 2, 30);
[Link](label);
[Link]();
62
[Link](rawADC);
[Link](" | CO2(eq): ");
[Link](ppm);
[Link](" ppm | AQ: ");
[Link](airQuality);
delay(2000);
}
63