Arduino Uno Based Gas Sensor
Arduino Uno Based Gas Sensor
Experiment Name: Study and Observation of Arduino Uno Based Gas Sensor.
Objective:
To study the functionality of a gas sensor using an Arduino Uno and to detect the presence of smoke/gas
using the sensor's digital output (D0). Additionally, determine if gas concentration is within acceptable
limits by finding a threshold value.
Theory:
Gas sensors, such as the MQ series, are widely used to detect the presence of various gases,
including smoke, carbon monoxide, and methane. These sensors consist of a sensitive layer that
changes resistance when exposed to gases, producing an output that indicates gas presence. The
MQ gas sensor provides both analog (A0) and digital (D0) outputs, where D0 is activated when the
gas concentration crosses a preset threshold.
In this experiment, we focus on the digital output (D0), which goes HIGH when gas concentration
exceeds a certain level. By observing the threshold, we can determine whether the environment is
safe or needs attention due to high gas levels.
Arduino Uno - 1
Gas Sensor Module (e.g., MQ-2, MQ-135) - 1
Jumper Wires - 5
Breadboard – 1
Required Software:
Working Procedure:
• Threshold Adjustment: The MQ sensor typically has a potentiometer that allows manual
adjustment of the threshold level. Set the threshold by turning the potentiometer until the sensor
responds at the desired gas concentration level.
• Programming the Arduino: Write and upload a sketch to the Arduino that reads the digital
signal (D0) from the sensor. When D0 sends a HIGH signal (indicating gas presence above the
threshold), the Arduino should respond by triggering an alert or indicator (e.g., turning on an LED).
• Testing: Expose the sensor to different concentrations of gas or smoke and observe the behavior.
Adjust the threshold potentiometer if necessary to get accurate detection at the desired
concentration level.
A simple diagram showing Arduino, gas sensor, connections for D0 can be inserted here. The
sensor D0 connects to digital pin 2 on Arduino, and VCC/GND to 5V/GND.
Sketch:
#define MQ135pin 0
float sensorValue; // variable to store sensor value
void setup() {
Serial.begin(9600); // sets the serial port to 9600
Serial.println("MQ135 warming up!");
delay(20000); // allow the MQ135 to warm up
}
void loop() {
sensorValue = analogRead(MQ135pin); // read analog input pin 0
Serial.print("Sensor Value: ");
Serial.println(sensorValue);
delay(2000); // wait 2s for next reading
}
When you run the sketch, you should see readings similar to the ones below:
• In the absence of smoke/gas (around 100)
• In the presence of smoke/gas (around 400)
#define MQ135pin 8
int sensorValue; //variable to store sensor value
void setup() {
Serial.begin(9600); // sets the serial port to 9600
Serial.println("MQ135 warming up!");
delay(20000); // allow the MQ135 to warm up
}
void loop() {
sensorValue = digitalRead(MQ135pin); // read digital output pin
Serial.print("Digital Output: ");
Serial.print(sensorValue);
// Determine the status
if (sensorValue) {
Serial.println(" | Smoke: -");
} else {
Serial.println(" | Smoke: Detected!");
}
delay(2000); // wait 2s for next reading
}
Result and Output:
We will find threshold value by running the “Finding the threshold value” code and the value is
400.
Fig02: Finding threshold value
By running “Determines whether the gas concentration is within acceptable limits” we find that
our surrounding environment is within acceptable limit or not.
Conclusion:
In this experiment, an Arduino Uno-based gas sensor was used to monitor gas concentration levels. By
adjusting the threshold value, we could reliably detect gas concentrations above acceptable limits. This
setup is effective for applications that require gas detection and warning mechanisms, such as in
industrial safety systems or home safety devices. The digital output (D0) of the MQ sensor provides a
straightforward method for monitoring gas concentrations.