5853

In today's lecture, we will design a project in Proteus, where we will Interface Gas Sensor with Arduino. I will provide the complete code and simulation.

Gas sensors are widely used in fire alarms, industrial safety systems, home gas leakage detectors, and air-quality monitoring devices. They play a critical role in detecting flammable gases such as LPG, Propane, Methane, Hydrogen, and smoke. These sensors convert gas concentration levels into electrical signals, which microcontrollers such as Arduino can process for monitoring and decision-making. Their ability to detect hazardous conditions early makes them essential for creating warning systems that protect life and property.

This project focuses on interfacing a Gas Sensor (digital output) with Arduino and simulating the complete system inside Proteus. The goal is to read the sensor’s digital HIGH/LOW output and display its real-time status on a 20x4 LCD, indicating whether gas is detected or the environment is safe. By relying on a digital signal, this project becomes extremely easy for beginners to understand — yet highly practical for safety-based applications.
gas-sensor-1.png
The simulation is ideal for students, beginners, and electronics hobbyists who want to explore how gas sensors work using Proteus before implementing the system with real hardware. Through this project, you will learn how a gas sensor’s output changes with varying air conditions, how Arduino interprets these changes, and how to display the readings visually on an LCD.

By the end of this demonstration, you will clearly understand digital input reading, LCD interfacing, and how to build a functional gas detection system suitable for automation, safety, and monitoring applications.

Introduction to Gas Sensor (MQ-2 / Digital Gas Sensor Module)


A gas sensor (such as the MQ-2 module) is used to detect flammable gases and smoke in the surrounding environment. It typically consists of a heating element and a sensitive material that reacts with gases in the air. When gas concentration increases, the resistance of the sensor changes, and the module outputs a digital HIGH or LOW signal depending on the threshold.

Key Points About Gas Sensors


  • Detect gases such as LPG, Butane, Propane, Hydrogen, Methane, and smoke.
  • Produce either:
    • Analog output (gas concentration level) — not used in this project
    • Digital output (High = Gas Detected / Low = Safe)
  • Commonly found in:
    • Home gas leakage alarms
    • Fire detection systems
    • Industrial safety devices
    • Air-quality monitors
    • Smart home automation systems
Gas sensors require some warm-up time in real hardware, but in Proteus simulation, the digital output changes instantly using the logic toggle, making it ideal for teaching and testing purposes.

Below is what an actual MQ-2 sensor looks like:

Libraries Required for Interfacing Gas Sensor with Arduino


To run this project smoothly in Proteus, you need to install the external libraries for the components used in the simulation. Proteus does not include these modules by default, so make sure you add all required libraries before creating the circuit.

Below are the libraries you will need:

1. Arduino UNO Library

You will need the custom Arduino UNO library to place the microcontroller inside your Proteus workspace.

2. 20x4 LCD Library

A dedicated 20x4 Alphanumeric LCD library is required for proper display functionality.

3. Gas Sensor (MQ-2) Library

Proteus does not include the MQ-2 gas sensor by default, so you must add the custom library to simulate gas detection behavior.

Interfacing of Gas Sensor with Arduino | Proteus Simulation


In this section, we will simulate a Gas Sensor’s digital output using a Logic Toggle connected to Arduino pin 7. The idea is to detect whether gas is present or the environment is safe, and display this information on a 20x4 LCD.

Steps:

  • Open Proteus and Create a New Project
  • Open the Device Library and search for the gas sensor. You can choose any version, I am getting the MQ2 sensor.
  • Now, get the Arduino UNO. The version 3.0 is the most advanced.
  • Search for and Add a 20x4 LCD Module
  • Add a Logic Toggle. This will act as the Gas Sensor’s digital output.
  • Add an LED to clearly see the output.
  • Now, get the resistor to visually indicate gas detection.
  • Add Power and Ground Terminals from the terminal mode present on the left side of the screen. You will need the ground with the LED, LCD, and the sensor whereas, the power terminal is also required with the sensor and LCD.
Required Components


Your components list should include:

  • Arduino UNO
  • 20x4 LCD Display
  • Logic Toggle
  • LED
  • Resistor
  • Potentiometer (POT-HG for LCD contrast)
  • Power/Ground terminals

Circuit Building


  1. Place the Logic Toggle beside the sensor.
  2. Place the LED and resistor with the sensor’s output terminal.
  3. Add power and ground lines for the LCD and sensor.
  4. Make the connections of all these components.
  5. Connect the digital output of the logic toggle to pin 7 of Arduino.
  6. Place the LCD just at the right side of the Arduino.
  7. Wire the LCD to the Arduino exactly as follows:

LCD Pin | Arduino Pin
RS | 13
EN | 12
D4 | 11
D5 | 10
D6 | 9
D7 | 8

  • Once done, your circuit will look similar to the following: 
Interfacing of Gas Sensor with Arduino | Arduino IDE Code

  • Create a new sketch in the Arduino IDE. 
  • Delete the default code and paste the following code:
#include
// LCD pins: RS, EN, D4, D5, D6, D7LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
#define SENSOR_PIN 7 // Only digital sensor pin
void setup() { pinMode(SENSOR_PIN, INPUT);
 lcd.begin(20, 4); lcd.clear();
 lcd.setCursor(2, 0); lcd.print("Gas Sensor Test");
 delay(2000); lcd.clear();}
void loop() {
 int sensorState = digitalRead(SENSOR_PIN);
 // Line 1: Title lcd.setCursor(0, 0); lcd.print("MQ Gas Sensor Status");
 // Line 2: Output state lcd.setCursor(0, 1); lcd.print("Digital Out: "); 
 if (sensorState == HIGH) { lcd.print("HIGH "); } else { lcd.print("LOW "); }
 // Line 3: Gas status lcd.setCursor(0, 2); lcd.print("Gas Level: "); if (sensorState == HIGH) { lcd.print("DETECTED "); } else { lcd.print("SAFE "); }
 // Line 4: Live message lcd.setCursor(0, 3); 
 if (sensorState == HIGH) { lcd.print("Alert! Check Leakage"); } else { lcd.print("Environment Normal "); }
 delay(200); 
}Source Code Explanation

The Arduino sketch used in this project is designed to read the digital output from the gas sensor and display the real-time status clearly on a 20×4 character LCD. The code is kept simple, clean, and optimized so that beginners can understand each section without confusion. Below is a breakdown of how the program works.

1. LCD Initialization

#include
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);

The project uses a 20×4 LCD in 4-bit mode, which requires six Arduino pins:
RS, EN, D4, D5, D6, D7.

These pins are mapped exactly as connected in the Proteus circuit.
The LiquidCrystal library makes it easy to control the LCD without manually handling low-level commands.

2. Sensor Pin Configuration

#define SENSOR_PIN 7
pinMode(SENSOR_PIN, INPUT);

Only one digital pin is used in this project.
The MQ-series gas sensors provide:

  • Analog output (continuous gas concentration)
  • Digital output (simple HIGH/LOW threshold indication)
In this simulation, we read only the digital output, which becomes HIGH when gas concentration crosses the built-in threshold of the module.

3. LCD Startup Screen

lcd.setCursor(2, 0);
lcd.print("Gas Sensor Test");

When the circuit starts, a short welcome message appears on the LCD.
 This ensures the user can confirm that the LCD is wired correctly and initialized before real data appears.

4. Reading the Gas Sensor Output

int sensorState = digitalRead(SENSOR_PIN);

The Arduino continuously reads the logic state from pin 7:

  • LOW → No gas detected (environment is safe)
  • HIGH → Gas leakage detected (above threshold)
This simple digital reading allows beginners to easily test gas leak detection behavior inside Proteus using the Logic Toggle.

5. Displaying Organized Information on the LCD

To make the output readable, each line of the 20×4 LCD is used for a separate piece of information.

Line 1: Header / Title
lcd.setCursor(0, 0);
lcd.print("MQ Gas Sensor Status");

Displays the purpose of the system.

Line 2: Digital Output State
lcd.setCursor(0, 1);
lcd.print("Digital Out: HIGH/LOW");

This tells the user exactly what voltage level is present on pin 7.

Line 3: Gas Detection Status
lcd.setCursor(0, 2);
lcd.print("Gas Level: DETECTED");

This line converts the naked HIGH/LOW signal into meaningful text:

  • “SAFE”
  • “DETECTED”
Line 4: Alert Message
lcd.setCursor(0, 3);
lcd.print("Alert! Check Leakage");

If the sensor detects gas, the LCD shows a warning message.
 If not, it shows “Environment Normal”.

This bottom line is designed to act as a quick visual prompt for the user.

6. Loop Refresh

delay(200);

A small delay ensures the display remains stable and updates smoothly without flickering.

Adding HEX File in Proteus


  1. Click Verify in Arduino IDE.
  2. Wait for the loading at the bottom of the screen. Search for the address of the file that ends with the “.hex” extension.
  3. Copy the HEX file path from the console.
  4. Open Proteus where the circuit is already complete.
  5. Double-click Arduino UNO microcontroller.
  6. Paste the HEX file path into the Program File field.
  7. Now, if you are using the gas sensor library for the first time, you have to include the hex file for this as well. Double click on the sensor>click on the file icon>provide the path of the hex file from your system. It is the one that you have installed into your proteus library folder. 
  8. Click okay.
  9. Start the simulation.
Testing the Interfacing of Gas Sensor


Being the digital project, this has only two outputs that are, the gas is present in the environment or not. Here is how you can test this project.

1. Safe Environment Mode

When the logic toggle = LOW:

  • Digital value = LOW
  • LCD shows:
    • Sensor output: LOW
    • Status: SAFE
LED remains OFF.

2. Gas Detected Mode

When the logic toggle = HIGH:

  • Digital value = HIGH
  • LCD shows:
    • Sensor output: HIGH
    • Status: GAS DETECTED
LED turns ON.

This confirms the system is detecting gas presence successfully.
Applications of Gas Sensor with Arduino


Gas sensors are extremely important for safety and monitoring in both homes and industries. When interfaced with Arduino, they become a versatile tool for automation and alert systems.

1. Home Gas Leakage Detection

Used to detect leakage of:

  • LPG
  • Propane
  • Methane
  • Arduinos trigger alarms, buzzers, or SMS alerts when gas levels rise.

2. Industrial Safety Systems

Factories require continuous gas monitoring to prevent:

  • Explosions
  • Fire hazards
  • Health risks

Arduino-based gas detection systems are cost-effective and flexible.

3. Fire and Smoke Detection

Gas sensors can detect smoke and help build early-warning fire alarm systems.

4. Smart Home Automation

Gas detection can automatically:

  • Open windows
  • Turn on exhaust fans
  • Alert users through IoT systems

5. Air Quality Monitoring

Useful for indoor laboratories, storage rooms, and kitchens.

6. Educational Projects

Ideal for electronics students to learn:

  • Sensor interfacing
  • Digital reading
  • LCD interfacing
  • Safety system design