<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.cognifront.com/docs/index.php?action=history&amp;feed=atom&amp;title=MDM331AID%2FExperiment_4</id>
	<title>MDM331AID/Experiment 4 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.cognifront.com/docs/index.php?action=history&amp;feed=atom&amp;title=MDM331AID%2FExperiment_4"/>
	<link rel="alternate" type="text/html" href="https://www.cognifront.com/docs/index.php?title=MDM331AID/Experiment_4&amp;action=history"/>
	<updated>2026-10-21T01:58:17Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>https://www.cognifront.com/docs/index.php?title=MDM331AID/Experiment_4&amp;diff=1363&amp;oldid=prev</id>
		<title>CogWikiEditor: /* Arduino Program */</title>
		<link rel="alternate" type="text/html" href="https://www.cognifront.com/docs/index.php?title=MDM331AID/Experiment_4&amp;diff=1363&amp;oldid=prev"/>
		<updated>2026-10-07T16:00:19Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Arduino Program&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 16:00, 7 October 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l142&quot;&gt;Line 142:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 142:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Arduino Program ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Arduino Program ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;syntaxhighlight lang=&quot;cpp&quot;&lt;/del&gt;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;pre&lt;/ins&gt;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;const int gasPin = A0;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;const int gasPin = A0;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;const int ledPin = 8;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;const int ledPin = 8;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l182&quot;&gt;Line 182:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 182:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   delay(1000);&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   delay(1000);&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;}&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;syntaxhighlight&lt;/del&gt;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;pre&lt;/ins&gt;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Code Explanation ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Code Explanation ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>CogWikiEditor</name></author>
	</entry>
	<entry>
		<id>https://www.cognifront.com/docs/index.php?title=MDM331AID/Experiment_4&amp;diff=1313&amp;oldid=prev</id>
		<title>CogWikiEditor: Created page with &quot; = Experiment: Gas Leakage Detection Using Arduino UNO =  == Aim ==  To develop a gas leakage detection application using an Arduino UNO and an MQ-2 gas sensor to monitor the surrounding environment and generate an alert when the sensor reading exceeds a predefined threshold.  == Objectives ==  * To understand the working principle of the MQ-2 gas sensor. * To interface a gas sensor with the Arduino UNO. * To read analog sensor values using the ADC of the Arduino. * To i...&quot;</title>
		<link rel="alternate" type="text/html" href="https://www.cognifront.com/docs/index.php?title=MDM331AID/Experiment_4&amp;diff=1313&amp;oldid=prev"/>
		<updated>2026-10-02T14:39:07Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot; = Experiment: Gas Leakage Detection Using Arduino UNO =  == Aim ==  To develop a gas leakage detection application using an Arduino UNO and an MQ-2 gas sensor to monitor the surrounding environment and generate an alert when the sensor reading exceeds a predefined threshold.  == Objectives ==  * To understand the working principle of the MQ-2 gas sensor. * To interface a gas sensor with the Arduino UNO. * To read analog sensor values using the ADC of the Arduino. * To i...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
= Experiment: Gas Leakage Detection Using Arduino UNO =&lt;br /&gt;
&lt;br /&gt;
== Aim ==&lt;br /&gt;
&lt;br /&gt;
To develop a gas leakage detection application using an Arduino UNO and an MQ-2 gas sensor to monitor the surrounding environment and generate an alert when the sensor reading exceeds a predefined threshold.&lt;br /&gt;
&lt;br /&gt;
== Objectives ==&lt;br /&gt;
&lt;br /&gt;
* To understand the working principle of the MQ-2 gas sensor.&lt;br /&gt;
* To interface a gas sensor with the Arduino UNO.&lt;br /&gt;
* To read analog sensor values using the ADC of the Arduino.&lt;br /&gt;
* To implement threshold-based gas detection.&lt;br /&gt;
* To activate an alert using an LED and buzzer when the sensor reading exceeds the set threshold.&lt;br /&gt;
&lt;br /&gt;
== Components Required ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Sr. No.&lt;br /&gt;
! Component&lt;br /&gt;
! Quantity&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| Arduino UNO Development Board (COG-U1)&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| MQ-2 Gas Sensor (COG-MSBA)&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
| LED bar&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
| Buzzer&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
| USB data cable&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 6&lt;br /&gt;
| Patch cords&lt;br /&gt;
| As required&lt;br /&gt;
|-&lt;br /&gt;
| 7&lt;br /&gt;
| Computer with Arduino IDE&lt;br /&gt;
| 1&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Theory ==&lt;br /&gt;
&lt;br /&gt;
=== Gas Leakage Detection ===&lt;br /&gt;
&lt;br /&gt;
Gas leakage detection is an important application in homes, industries, laboratories, and other environments where combustible gases may be present. A gas sensor detects changes in the surrounding gas concentration and generates an electrical signal that can be processed by a microcontroller.&lt;br /&gt;
&lt;br /&gt;
=== MQ-2 Gas Sensor ===&lt;br /&gt;
&lt;br /&gt;
The MQ-2 is a semiconductor gas sensor commonly used for detecting combustible gases and smoke. It is sensitive to gases such as LPG, propane, methane, hydrogen, and smoke.&lt;br /&gt;
&lt;br /&gt;
The sensor contains a sensing element whose electrical resistance changes in the presence of certain gases. The sensor module converts this change into an electrical output.&lt;br /&gt;
&lt;br /&gt;
Common MQ-2 module interfaces include:&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;VCC:&amp;#039;&amp;#039;&amp;#039; Power supply input.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;GND:&amp;#039;&amp;#039;&amp;#039; Ground connection.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;AO:&amp;#039;&amp;#039;&amp;#039; Analog output voltage related to the sensor response.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;DO:&amp;#039;&amp;#039;&amp;#039; Digital output from an onboard comparator, often with an adjustable threshold.&lt;br /&gt;
&lt;br /&gt;
In this experiment, the analog output is used to read sensor values through the Arduino UNO&amp;#039;s analog input.&lt;br /&gt;
&lt;br /&gt;
=== Analog-to-Digital Conversion ===&lt;br /&gt;
&lt;br /&gt;
The Arduino UNO has a 10-bit analog-to-digital converter (ADC). The analogRead() function converts the analog input voltage into a digital value ranging from 0 to 1023 when using the default reference.&lt;br /&gt;
&lt;br /&gt;
=== Threshold-Based Detection ===&lt;br /&gt;
&lt;br /&gt;
The Arduino continuously reads the analog output of the MQ-2 sensor. The measured value is compared with a predefined threshold.&lt;br /&gt;
&lt;br /&gt;
* If the sensor reading is below the threshold, the system indicates normal operation.&lt;br /&gt;
* If the sensor reading is equal to or above the threshold, the system activates the alert LED and buzzer.&lt;br /&gt;
&lt;br /&gt;
The threshold used in this experiment is a demonstration value and must be adjusted based on actual sensor readings. It does not represent a calibrated gas concentration.&lt;br /&gt;
&lt;br /&gt;
== Pin Connections ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Arduino UNO Pin&lt;br /&gt;
! MQ-2 / Output Connection&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| 5V&lt;br /&gt;
| MQ-2 VCC&lt;br /&gt;
| Sensor power supply&lt;br /&gt;
|-&lt;br /&gt;
| GND&lt;br /&gt;
| MQ-2 GND&lt;br /&gt;
| Common ground&lt;br /&gt;
|-&lt;br /&gt;
| A0&lt;br /&gt;
| MQ-2 AO&lt;br /&gt;
| Analog sensor output&lt;br /&gt;
|-&lt;br /&gt;
| D8&lt;br /&gt;
| LED bar input&lt;br /&gt;
| Visual alert output&lt;br /&gt;
|-&lt;br /&gt;
| D9&lt;br /&gt;
| Buzzer input&lt;br /&gt;
| Audible alert output&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Note:&amp;#039;&amp;#039;&amp;#039; These connections assume that the MQ-2 board exposes an analog output compatible with the Arduino UNO and that the LED bar and buzzer accept active-HIGH digital control. Verify the actual pin labels and interface of your Cognifront sensor and output boards before connecting.&lt;br /&gt;
&lt;br /&gt;
== Connection Diagram ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
          MQ-2 Gas Sensor&lt;br /&gt;
         +---------------+&lt;br /&gt;
         |               |&lt;br /&gt;
         | VCC  ---------+---- 5V&lt;br /&gt;
         | GND  ---------+---- GND&lt;br /&gt;
         | AO   ---------+---- A0&lt;br /&gt;
         +---------------+&lt;br /&gt;
&lt;br /&gt;
             Arduino UNO&lt;br /&gt;
         +------------------+&lt;br /&gt;
         |                  |&lt;br /&gt;
         | A0  &amp;lt;--- MQ-2 AO |&lt;br /&gt;
         |                  |&lt;br /&gt;
         | D8  ------------+---- LED Bar Input&lt;br /&gt;
         |                  |&lt;br /&gt;
         | D9  ------------+---- Buzzer Input&lt;br /&gt;
         |                  |&lt;br /&gt;
         | GND ------------+---- Common GND&lt;br /&gt;
         +------------------+&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Arduino Program ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
const int gasPin = A0;&lt;br /&gt;
const int ledPin = 8;&lt;br /&gt;
const int buzzerPin = 9;&lt;br /&gt;
&lt;br /&gt;
// Demonstration threshold; calibrate for your setup&lt;br /&gt;
const int gasThreshold = 400;&lt;br /&gt;
&lt;br /&gt;
int gasValue = 0;&lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
  Serial.begin(9600);&lt;br /&gt;
&lt;br /&gt;
  pinMode(ledPin, OUTPUT);&lt;br /&gt;
  pinMode(buzzerPin, OUTPUT);&lt;br /&gt;
&lt;br /&gt;
  digitalWrite(ledPin, LOW);&lt;br /&gt;
  digitalWrite(buzzerPin, LOW);&lt;br /&gt;
&lt;br /&gt;
  Serial.println(&amp;quot;MQ-2 Gas Detection System&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void loop() {&lt;br /&gt;
  gasValue = analogRead(gasPin);&lt;br /&gt;
&lt;br /&gt;
  Serial.print(&amp;quot;Gas Sensor Value: &amp;quot;);&lt;br /&gt;
  Serial.println(gasValue);&lt;br /&gt;
&lt;br /&gt;
  if (gasValue &amp;gt;= gasThreshold) {&lt;br /&gt;
    digitalWrite(ledPin, HIGH);&lt;br /&gt;
    digitalWrite(buzzerPin, HIGH);&lt;br /&gt;
    Serial.println(&amp;quot;WARNING: Gas level threshold exceeded!&amp;quot;);&lt;br /&gt;
  } else {&lt;br /&gt;
    digitalWrite(ledPin, LOW);&lt;br /&gt;
    digitalWrite(buzzerPin, LOW);&lt;br /&gt;
    Serial.println(&amp;quot;Status: Normal&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  delay(1000);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Code Explanation ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Statement&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| const int gasPin = A0;&lt;br /&gt;
| Defines analog pin A0 as the gas sensor input.&lt;br /&gt;
|-&lt;br /&gt;
| const int ledPin = 8;&lt;br /&gt;
| Defines digital pin D8 as the LED control output.&lt;br /&gt;
|-&lt;br /&gt;
| const int buzzerPin = 9;&lt;br /&gt;
| Defines digital pin D9 as the buzzer control output.&lt;br /&gt;
|-&lt;br /&gt;
| const int gasThreshold = 400;&lt;br /&gt;
| Sets a demonstration threshold for gas detection.&lt;br /&gt;
|-&lt;br /&gt;
| analogRead(gasPin)&lt;br /&gt;
| Reads the analog output of the gas sensor and returns a value from 0 to 1023.&lt;br /&gt;
|-&lt;br /&gt;
| Serial.println(gasValue)&lt;br /&gt;
| Displays the sensor reading on the Serial Monitor.&lt;br /&gt;
|-&lt;br /&gt;
| if (gasValue &amp;gt;= gasThreshold)&lt;br /&gt;
| Checks whether the sensor reading has reached or exceeded the threshold.&lt;br /&gt;
|-&lt;br /&gt;
| digitalWrite(ledPin, HIGH)&lt;br /&gt;
| Activates the LED alert output.&lt;br /&gt;
|-&lt;br /&gt;
| digitalWrite(buzzerPin, HIGH)&lt;br /&gt;
| Activates the buzzer alert output.&lt;br /&gt;
|-&lt;br /&gt;
| delay(1000)&lt;br /&gt;
| Pauses the program for one second before the next reading.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Procedure ==&lt;br /&gt;
&lt;br /&gt;
# Connect the MQ-2 sensor&amp;#039;s VCC and GND pins to the Arduino UNO&amp;#039;s 5V and GND, respectively.&lt;br /&gt;
# Connect the sensor&amp;#039;s analog output (AO) to the Arduino analog input A0.&lt;br /&gt;
# Connect the LED bar input to D8 and the buzzer input to D9, ensuring that the output interfaces are compatible.&lt;br /&gt;
# Connect the Arduino UNO to the computer using the USB data cable.&lt;br /&gt;
# Open the Arduino IDE and select the Arduino UNO board and appropriate COM port.&lt;br /&gt;
# Enter the program and upload it to the Arduino UNO.&lt;br /&gt;
# Open the Serial Monitor and set the baud rate to 9600.&lt;br /&gt;
# Allow the MQ-2 sensor to warm up and stabilize according to its datasheet and module instructions.&lt;br /&gt;
# Observe the sensor readings under the available ambient conditions.&lt;br /&gt;
# Adjust the demonstration threshold based on observed readings, if required.&lt;br /&gt;
# Observe the LED and buzzer response when the reading crosses the configured threshold.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Safety precaution:&amp;#039;&amp;#039;&amp;#039; Do not intentionally release LPG, lighter gas, smoke, or other combustible gases to test the circuit. This is an educational demonstration, not a certified gas alarm or safety system. Conduct any controlled sensor testing only with appropriate laboratory safety procedures.&lt;br /&gt;
&lt;br /&gt;
== Observations ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Sr. No.&lt;br /&gt;
! Sensor Reading&lt;br /&gt;
! Condition&lt;br /&gt;
! LED&lt;br /&gt;
! Buzzer&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| Below threshold&lt;br /&gt;
| Normal&lt;br /&gt;
| OFF&lt;br /&gt;
| OFF&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| Equal to or above threshold&lt;br /&gt;
| Threshold exceeded&lt;br /&gt;
| ON&lt;br /&gt;
| ON&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The readings and alert response should be recorded during the experiment. The table describes expected behavior, not measured results.&lt;br /&gt;
&lt;br /&gt;
== Result ==&lt;br /&gt;
&lt;br /&gt;
An Arduino UNO-based gas detection demonstration was developed using an MQ-2 sensor. The sensor&amp;#039;s analog output was read and compared against a predefined threshold. An LED and buzzer were programmed to provide alerts when the reading exceeded the threshold.&lt;br /&gt;
&lt;br /&gt;
== Viva Questions ==&lt;br /&gt;
&lt;br /&gt;
# What is the purpose of a gas sensor?&lt;br /&gt;
# What is the working principle of the MQ-2 sensor?&lt;br /&gt;
# Which gases can the MQ-2 sensor detect?&lt;br /&gt;
# What is the difference between the analog and digital outputs of an MQ-2 module?&lt;br /&gt;
# What is the resolution of the Arduino UNO ADC?&lt;br /&gt;
# What is the purpose of the analogRead() function?&lt;br /&gt;
# Why is a threshold used in gas detection?&lt;br /&gt;
# Why does an MQ-2 sensor require a warm-up period?&lt;br /&gt;
# Can an MQ-2 sensor directly measure gas concentration in parts per million without calibration?&lt;br /&gt;
# What are the limitations of a threshold-based gas detection system?&lt;br /&gt;
# How can this project be extended to send gas alerts through an IoT cloud platform?&lt;/div&gt;</summary>
		<author><name>CogWikiEditor</name></author>
	</entry>
</feed>