Example Code for Arduino-Gas Detection

Last revision 2026/01/15

Wiring Diagram

Analog sensor connection diagram

Other Preparation Work

Potentiometer is used to calibrate the readings from this sensor as stated on the datasheet:

SENSITVITY ADJUSTMENT

Resistance value of MQ-4 is difference to various kinds and various concentration gases. So,When using this components, sensitivity adjustment is very necessary. we recommend that you calibrate the detector for 5000ppm of CH4 concentration in air and use value of Load resistance ( RL) about 20KΩ(10KΩ to 47KΩ). When accurately measuring, the proper alarm point for the gas detector should be determined after considering the temperature and humidity influence.

Sample Code


///Arduino Sample Code
void setup()
{
  Serial.begin(9600); //Set serial baud rate to 9600 bps
}
void loop()
{
int val;
val=analogRead(0);Read Gas value from analog 0
Serial.println(val,DEC);//Print the value to serial port
delay(100);
}

Was this article helpful?

TOP