Same-day dispatch before 2 PM · Free delivery over ₹999 · GST invoices Get the appPrices incl. GST
Geekobot
Snap & SendNEWGeeko AIWhere's myOrder
Log in
Products
  • Projects
    • Component guidesHow parts work, with code you can run
    • Learning pathsFrom your first LED to your first robot
    • Workshops & eventsOnline sessions for makers and classes
    • ElectrolarkFree guided builds, simulator and certificates
    • Students & teachersStudent discount and classroom help
    • CommunityShare builds and ask other makers
    • CalculatorsOhm's law, LED resistor, 555 and 100+ more
    • Circuit builderWire parts and run the circuit, powered by Electrolark
    • Geeko AIAsk what to buy or how to wire it
    • Snap & SendPhotograph a part or list, we find it
    • Part finderAnswer a few questions, get the right part
    • Compatibility checkWill these two parts work together?
    • Compare partsSpecs side by side
    • Business & bulk ordersGST invoices, credit and volume prices
    • Request a quotationSend your list, get a quote
    • Classroom kitsPer-student kits and lab bundles
    • Gift cardsFor students, teams and events
  • Atal Tinkering Lab
BOM to cart
Geekobot

Components, kits and know-how for makers, students, engineers, labs and businesses across India.

Ask Geeko AIOrders, parts and projects, any timeEmail supportReply within 1 working dayGet the Geekobot appAdd it to your home screen, free

Follow us

Shop

  • Boards & SBCs
  • Sensors & Modules
  • IoT & Wireless
  • Drone & FPV
  • 3D Printing
  • Filaments & Resins
  • Motors & Drivers
  • Power & Batteries
  • Semiconductors
  • Passive
  • Displays & LEDs
  • Switches & Relays
  • Wires & Cables
  • Prototyping
  • Tools & Test
  • Robotics
  • STEM Kits
  • Atal Tinkering Lab
  • Mechanical Parts
  • Audio

Orders

  • Track your order
  • Help & support
  • Shipping and delivery
  • Refunds and cancellation
  • Contact us

Learn

  • Projects
  • Geeko AI project assistant
  • Learning paths
  • Guides
  • Calculators
  • Electrolark: free guided builds

Part tools

  • Part finder
  • Compare parts
  • Will it work with my board?

Institutions

  • Classroom kits
  • Atal Tinkering Lab
  • Students & teachers
  • Workshops & Events

Business

  • Business & education
  • Request a quotation
  • BOM bulk upload
  • Quick order by SKU

Company

  • About Geekobot
  • Community
  • Gift cards
  • Terms & conditions
  • Privacy policy
  • Product directory
  • Sitemap

© 2026 Geekobot, a trade name of OLatus Systems Private Limited. All rights reserved.

20, 1st Floor, Neeladri Complex, 10th Cross, Sampige Rd, 2nd Main, Malleshwaram, Bengaluru, Karnataka 560003 · GSTIN 29AACCO0462F1ZM

+91 91810 15607 · connect@geekobot.in · Monday to Saturday, 10 AM to 2 PM IST

UPI · CARDS · NETBANKING · GST INVOICES

ShopProjectsGeeko AIGuides
Compare 0 parts →
Log in

Shop by category

Shop all components
  • Boards & SBCs1,910 products
    • Alternative Single Board Computers
    • Arduino Ecosystem
    • FPGA & Logic Boards
    • Microcontroller & Wireless Boards
    View all
  • Sensors & Modules4,701 products
    • Biomedical & Heart Rate
    • Current, Voltage & Power
    • Force, Weight & Pressure
    • Gas, Weather & Environmental
    View all
  • IoT & Wireless2,314 products
    • RF Modules
    • RFID & NFC
    • Antennas & RF Accessories
    • Cameras & Smart Vision
    View all
  • Drone & FPV3,558 products
    • Flight Control & Navigation
    • FPV Video & Optics
    • Frames & Structural Parts
    • Motors & Propulsion
    View all
  • 3D Printing2,204 products
    • 3D Printers
    • 3D Scanners & Digitizers
    • Laser Engravers & Cutters
    • Material Management & Upgrades
    View all
  • Filaments & Resins1,472 products
    • Filaments
    • Photopolymer Resins
    View all
  • Motors & Drivers463 products
    • BLDC Motor Drivers
    • DC & Geared Motors
    • DC Motor Drivers
    • Linear Actuators & Solenoids
    View all
  • Power & Batteries557 products
    • Battery Holders & Connectors
    • Breadboard Power
    • Chargers & BMS
    • DC-DC Converters
    View all
  • Semiconductors295 products
    • Diodes & Rectifiers
    • Interface & RF Encoder ICs
    • Logic ICs (74xx)
    • Logic ICs (CD4000)
    View all
  • Passive67 products
    • Capacitors
    • Circuit Protection
    • Crystals & Oscillators
    • Inductors
    View all
  • Displays & LEDs572 products
    • 7-Segment & Dot Matrix
    • Addressable LEDs
    • Character LCDs
    • Graphic LCDs
    View all
  • Switches & Relays184 products
    • Keypads & Touch
    • Push Buttons & Tactile
    • Relay Modules
    • Relays
    View all
  • Wires & Cables233 products
    • Board-to-Wire Connectors
    • Crimp & Splice
    • Headers & Dupont
    • Heat Shrink & Sleeving
    View all
  • Prototyping101 products
    • Breadboards
    • Interface Modules
    • PCBs & Perfboards
    View all
  • Tools & Test717 products
    • Bench Power Supplies
    • Hand Tools
    • Measuring Tools
    • Meters & Testers
    View all
  • Robotics180 products
    • Humanoid & Legged Robots
    • Robot Chassis & Platforms
    • Robotic Arms & Grippers
    • Wheels & Casters
    View all
  • STEM Kits268 products
    • Arduino Learning Kits
    • Coding & IoT Kits
    • Early Coding (Ages 3-8)
    • Invention Kits
    View all
  • Atal Tinkering Lab196 products
    • Package 1: Electronics, Robotics, IoT and Sensors
    • Package 2: Rapid Prototyping Tools
    • Package 3: Mechanical, Electrical and Measurement Tools
    • Package 4: Power Supply, Accessories and Safety Equipment
    View all
  • Mechanical Parts212 products
    • Bearings
    • Brackets & Mounts
    • Couplers
    • Fasteners & Standoffs
    View all
  • Audio109 products
    • Amplifier Modules
    • Buzzers & Sirens
    • Speakers
    View all
  1. Home
  2. ›Guides
  3. ›Sensors
  4. ›MQ-4 Methane (CNG) Sensor

Component guide · Beginner · 3 min read

MQ-4 Methane (CNG) Sensor

Pinout, Wiring and Code

By Geekobot Learning Team · Updated 29 Oct 2026

I'm using
Wiring, code and the Run it panels follow your board.
On this page
Short answerWhat the MQ-4 isMQ-4 pinoutWiring the MQ-4Example codeSetup and tuningWhat you needAlternatives and when to choose themTry itCommon mistakesFAQsParts and next steps
Short answer

The MQ-4 is a heated metal-oxide sensor most sensitive to methane, the main gas in natural gas and CNG. Its module gives an analog voltage that rises with methane level and a digital alarm output set by a trim pot. Power it from 5 V, mount it high because methane rises, and calibrate in clean air before use.

Key specs at a glance

Detects
Methane (CNG)
Range
About 200 to 10,000 ppm methane
Heater
5 V, about 150 mA (about 0.75 W)
Output
Analog (AO) and digital threshold (DO) on modules
Warm-up
A few minutes before use; 24 to 48 hours of burn-in for stable readings
Most sensitive to
Methane (CH4) and natural gas; low response to alcohol and smoke

Models in this guide

These are alternatives. Pick the one that fits your project; you only need one.

  • Option 1MQ-4 Methane CNG Gas Detector Module – Analog & TTL Output₹94
  • Option 2ACEBOTT MQ-4 Natural Gas & Methane Sensor – Analog Output, Easy-Plug Compatible₹419
  • Option 3DFRobot Gravity Analog CH4 Gas Sensor MQ4 for Arduino – Module Only₹839
  • Option 4Winsen MQ-4 Methane Gas Sensor Module – Semiconductor Sensor₹129
01

What the MQ-4 is

The MQ-4 uses the same tin dioxide principle as the other MQ sensors but is most sensitive to methane, the main part of natural gas and CNG. Its resistance falls as methane rises.

It is used in learning projects for kitchen gas leak indicators, biogas monitoring and CNG experiments. MQ sensors are for hobby and learning projects. They are not certified gas alarms; for safety use an approved detector.

02

MQ-4 pinout

The pins on the MQ-4 and what each one does.

PinFunction
VCC5 V supply for the heater and the comparator
GNDGround
AOAnalog output: rises as the gas level rises
DODigital output from the LM393 comparator; switches at the level set by the trim pot
PinFunction
VCC
5 V supply for the heater and the comparator
GND
Ground
AO
Analog output: rises as the gas level rises
DO
Digital output from the LM393 comparator; switches at the level set by the trim pot
03

Wiring the MQ-4

The heater draws about 150 mA, so power it from the 5 V rail, not a 3.3 V pin. The analog output can reach 5 V, so an ESP32 needs a divider (10 kΩ over 20 kΩ gives a third off) on AO.

MQ-4 pinArduino UnoESP32
VCC5V5V (VIN)
GNDGNDGND
AOA0GPIO 34 through a 10k/20k divider
DOD2 (optional)GPIO 27 (optional, via divider)
VCC
Arduino Uno:
5V
ESP32:
5V (VIN)
GND
Arduino Uno:
GND
ESP32:
GND
AO
Arduino Uno:
A0
ESP32:
GPIO 34 through a 10k/20k divider
DO
Arduino Uno:
D2 (optional)
ESP32:
GPIO 27 (optional, via divider)
04

Example code

Rs/R0 falls as the gas level rises. Convert it to ppm with the curve in the datasheet; treat the result as an estimate, not a certified reading.

Measure Rs/R0 for the MQ-4 (Arduino Uno) · Arduino C++Verify & upload in Electrolark
const int AO = A0;
const float RL = 10.0;          // load resistor on the module, kOhm (check yours)
const float CLEAN_AIR = 4.4;  // Rs/R0 in clean air from the datasheet curve
float R0 = 0;

float readRs() {
  long sum = 0;
  for (int i = 0; i < 50; i++) { sum += analogRead(AO); delay(5); }
  float v = (sum / 50.0) * 5.0 / 1023.0;
  return RL * (5.0 - v) / v;          // sensor resistance, kOhm
}

void setup() {
  Serial.begin(115200);
  Serial.println("Warming up 3 minutes in clean air...");
  delay(180000);
  R0 = readRs() / CLEAN_AIR;          // calibrate in clean air
  Serial.print("R0 = "); Serial.println(R0);
}

void loop() {
  float ratio = readRs() / R0;        // lower ratio = more gas
  Serial.print("Rs/R0 = "); Serial.println(ratio, 2);
  delay(1000);
}
05

Setup and tuning

Burn-in

24 to 48 hours for a new sensor.

Placement

methane is lighter than air, so mount the sensor high on the wall, near the ceiling.

Calibration

set R0 in clean air; the clean-air ratio is about 4.4.

Alarm

use DO for a buzzer, or compare Rs/R0 in code for more control.

06

What you need

Shop this list7 of 8 found in our store · ₹1,735

  • MQ-4 methane CNG gas detector module: the sensor this guide coversMQ-4 Methane CNG Gas Detector Module – Analog & TTL Output₹94Closest match, check the specs
  • ACEBOTT MQ-4 Natural Gas & Methane Sensor – Analog Output, Easy-Plug Compatible: another version this guide coversACEBOTT MQ-4 Natural Gas & Methane Sensor – Analog Output, Easy-Plug Compatible₹419
  • DFRobot Gravity Analog CH4 Gas Sensor MQ4 for Arduino – Module Only: another version this guide coversDFRobot Gravity Analog CH4 Gas Sensor MQ4 for Arduino – Module Only₹839
  • Winsen MQ-4 Methane Gas Sensor Module – Semiconductor Sensor: another version this guide coversWinsen MQ-4 Methane Gas Sensor Module – Semiconductor Sensor₹129
  • Uno R3 development board: the controller used in the wiring tableFind this part
  • Buzzer module 3.3-5 V: for an audible alarmBuzzer Module 3.3–5V₹27
  • 16x2 LCD with I2C: to show readings on a character display16×2 LCD with I2C (RG1602A)₹179Closest match, check the specs
  • Dupont jumper wires: for the connectionsDupont Jumper Wires (40 pcs)₹49Closest match, check the specs
07

Alternatives and when to choose them

  • ✓MQ-5: better for LPG (cooking gas cylinders).
  • ✓MQ gas sensors: the whole family compared.
  • ✓Winsen gas sensor modules: catalytic and MEMS alternatives.
08

Try it: Voltage divider calculator

Change the values and the diagram and results update as you type.

09

Common mistakes to avoid

  • !Mounting it low; methane rises.
  • !Relying on it as a certified safety alarm.
  • !Skipping the warm-up and burn-in.
  • !Running the 150 mA heater from a 3.3 V regulator.
10

Frequently asked questions

What gas does the MQ-4 detect?

Methane and natural gas (CNG) best, with smaller responses to other gases.

Can the MQ-4 detect LPG?

Weakly. For LPG cylinders, use the MQ-5 or MQ-6.

Where should I mount it?

High up, because methane is lighter than air.

Does it work at 3.3 V?

The heater needs 5 V; the output can be divided down for 3.3 V boards.

How accurate is it?

It gives an estimate; humidity and temperature shift the reading.

Parts for this guide

  • MQ-4 Methane CNG Gas Detector Module – Analog & TTL Output
    ₹94View
  • ACEBOTT MQ-4 Natural Gas & Methane Sensor – Analog Output, Easy-Plug Compatible
    ₹419View
  • DFRobot Gravity Analog CH4 Gas Sensor MQ4 for Arduino – Module Only
    ₹839View
  • Winsen MQ-4 Methane Gas Sensor Module – Semiconductor Sensor
    ₹129View
  • Uno R3 Development Board (No Cable)
    ₹359View
  • Buzzer Module 3.3–5V
    ₹27View
  • 16×2 LCD with I2C (RG1602A)
    ₹179View
  • Dupont Jumper Wires (40 pcs)
    ₹49View
Shop Gas, Air Quality & CO2 Sensors

Calculators

Voltage divider calculator

Projects that use it

Put this into practice: 10 step-by-step builds in our project library use parts from this guide.

Beginner · 1 hourBiogas plant leak alarmView projectIntermediate · 1–2 hoursWi-Fi biogas kitchen methane monitorView projectIntermediate · 2 hoursManhole and septic tank gas checkView project
Browse all 10 projects

Keep learning

Component guideIntermediateMQ Gas SensorsMQ sensors are cheap metal-oxide gas sensors: a heated tin-dioxide surface changes resistance when gas is present.3 min read · SensorsComponent guideBeginnerMQ-2 gas sensorThe MQ-2 module detects smoke and flammable gases such as LPG, propane, methane and hydrogen.3 min read · SensorsBuying guideIntermediateAir Quality SensorsCompare particle, CO2 and VOC sensors for an air monitor: PMS5003 and SDS011, NDIR CO2 vs eCO2, wiring, warm-up, power and placement for honest readings.3 min read · SensorsConcept explainerBeginnerADCs ExplainedAn analog-to-digital converter (ADC) measures a voltage and returns a number.4 min read · Electronics Fundamentals

Sources

  • MQ-4 gas sensor technical data (Hanwei Electronics)

Written by the Geekobot team from manufacturer datasheets. Always check the datasheet for the exact part and variant you buy.

On this page
Short answerWhat the MQ-4 isMQ-4 pinoutWiring the MQ-4Example codeSetup and tuningWhat you needAlternatives and when to choose themTry itCommon mistakesFAQsParts and next steps
Need a hand?Ask Geeko AI which part fits your project, or talk to the Geekobot team.Ask Geeko AIHelp & support

Parts for this guide5 items · ₹1,507

MQ-4 Methane CNG Gas Detector Module – Analog & TTL Output · ACEBOTT MQ-4 Natural Gas & Methane Sensor – Analog Output, Easy-Plug Compatible · DFRobot Gravity Analog CH4 Gas Sensor MQ4 for Arduino – Module Only · Winsen MQ-4 Methane Gas Sensor Module – Semiconductor Sensor · Buzzer Module 3.3–5V

Run itChange the inputs and watch the output

MQ-4. In clean air Rs/R0 reads about 4.4; it falls as methane rises.

Serial monitor115200 baud
Warming up 3 minutes in clean air...
R0 = 4.55
Rs/R0 = 4.39

A simulation of the sketch above, so you know what to expect. Real readings vary with your parts and wiring.

Ask the Community

Ask a question