Interfacing of Gas Sensor with Arduino | Proteus Simulation
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.
This project focuses on interfacing a Gas Sensor (digital output) with Arduino UNO 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.

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.
- 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
Below are the libraries you will need:
You will need the custom Arduino UNO library to place the microcontroller inside your Proteus workspace.
3. Gas Sensor (MQ-2) Library
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.
- 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 on the LCD. I am going to use 1k ohm resistor. The 1kΩ Resistor Color Code is Brown, Black and Red, while Gold band gives the tolerance.
- 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.
Your components list should include:
- Arduino UNO
- 20x4 LCD Display
- Logic Toggle
- LED
- Resistor
- Potentiometer (POT-HG for LCD contrast)
- Power/Ground terminals
- Place the Logic Toggle beside the sensor.
- Place the LED and resistor with the sensor’s output terminal.
- Add power and ground lines for the LCD and sensor.
- Make the connections of all these components.
- Connect the digital output of the logic toggle to pin 7 of Arduino.
- Place the LCD just at the right side of the Arduino.
- Wire the LCD to the Arduino exactly as follows:
RS | 13
EN | 12
D4 | 11
D5 | 10
D6 | 9
D7 | 8
- Once done, your circuit will look similar to the following:
- Create a new sketch in the Arduino IDE.
- Delete the default code and paste the following code:
// 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
1. LCD Initialization
#include
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
The MQ-series gas sensors provide:
- Analog output (continuous gas concentration)
- Digital output (simple HIGH/LOW threshold indication)
3. LCD Startup Screen
This ensures the user can confirm that the LCD is wired correctly and initialized before real data appears.
4. Reading the Gas Sensor Output
The Arduino continuously reads the logic state from pin 7:
- LOW → No gas detected (environment is safe)
- HIGH → Gas leakage detected (above threshold)
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
- “SAFE”
- “DETECTED”
If not, it shows “Environment Normal”.
- Click Verify in Arduino IDE.
- Wait for the loading at the bottom of the screen. Search for the address of the file that ends with the “.hex” extension.
- Copy the HEX file path from the console.
- Open Proteus where the circuit is already complete.
- Double-click Arduino UNO microcontroller.
- Paste the HEX file path into the Program File field.
- 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.
- Click okay.
- Start the simulation.
1. Safe Environment Mode
- Digital value = LOW
- LCD shows:
- Sensor output: LOW
- Status: SAFE
2. Gas Detected Mode
- Digital value = HIGH
- LCD shows:
- Sensor output: HIGH
- Status: GAS DETECTED
This confirms the system is detecting gas presence successfully.
- LPG
- Propane
- Methane
- Arduinos trigger alarms, buzzers, or SMS alerts when gas levels rise.
Factories require continuous gas monitoring to prevent:
- Explosions
- Fire hazards
- Health risks
Gas sensors can detect smoke and help build early-warning fire alarm systems.
- Open windows
- Turn on exhaust fans
- Alert users through IoT systems
- Sensor interfacing
- Digital reading
- LCD interfacing
- Safety system design

Discussion (0 commentaire(s))