

During the warm-up period, the sensor typically reads high and gradually decreases until it stabilizes. If the sensor has recently been used, it will only take 5-10 minutes to fully warm up. When first used after a long period of storage (a month or more), the sensor must be fully warmed up for 24-48 hours to ensure maximum accuracy. Calibrating the MQ2 Gas Sensorīecause the MQ2 is a heater-driven sensor, the calibration of the sensor may drift if it is left in storage for an extended period of time. D0 becomes LOW when the gas concentration exceeds the threshold value (as set by the potentiometer), and HIGH otherwise.Ī0 produces an analog output voltage proportional to gas concentration, so a higher concentration results in a higher voltage and a lower concentration results in a lower voltage. Connect it to the 5V output of your Arduino.ĭ0 indicates the presence of combustible gasses. Remarks: The sensor and the load resistor forms a voltage divider.VCC supplies power to the module. Input: raw_adc - raw value read from adc, which represents the voltage Lcd.print(MQGetGasPercentage(MQRead(MQ_PIN) / Ro, GAS_SMOKE) ) Lcd.print(MQGetGasPercentage(MQRead(MQ_PIN) / Ro, GAS_CO) ) Lcd.print(MQGetGasPercentage(MQRead(MQ_PIN) / Ro, GAS_LPG) )

Serial.print(MQGetGasPercentage(MQRead(MQ_PIN) / Ro, GAS_SMOKE) ) Serial.print(MQGetGasPercentage(MQRead(MQ_PIN) / Ro, GAS_CO) ) Serial.print(MQGetGasPercentage(MQRead(MQ_PIN) / Ro, GAS_LPG) ) Please make sure the sensor is in clean air Ro = MQCalibration(MQ_PIN) //Calibrating the sensor. Serial.begin(9600) //UART setup, baudrate = 9600bps #define READ_SAMPLE_TIMES (5) //define the time interal(in milisecond) between each samples inįloat LPGCurve = point1: (lg200, 0.53), point2: (lg10000, -0.22)įloat Ro = 10 //Ro is initialized to 10 kilo ohms #define READ_SAMPLE_INTERVAL (50) //define how many samples you are going to take in normal operation #define CALIBRATION_SAMPLE_INTERVAL (500) //define the time interal(in milisecond) between each samples in the #define CALIBARAION_SAMPLE_TIMES (50) //define how many samples you are going to take in the calibration phase which is derived from the chart in datasheet #define RO_CLEAN_AIR_FACTOR (9.83) //RO_CLEAR_AIR_FACTOR=(Sensor resistance in clean air)/RO, #define RL_VALUE (5) //define the load resistance on the board, in kilo ohms #define MQ_PIN (0) //define which analog input channel you are going to use
#Arduino sensors tutorial mq2 tutorial code
The MQ-2 gas sensor analog output pin(A0) is connected to the A0 ADC pin of the Arduino.īelow is the program code for detecting gas using MQ2 gas sensor and displaying the PPM values on the LCD. The Arduino pins 13 to 8 are used for LCD. The following diagram shows the wiring diagram of Arduino, 16x2 LCD with MQ-2 gas sensor.

Wiring Diagram of MQ2 Gas Sensor with Arduino and LCD In the MQ-2 pin-out picture you can also see the potentiometer knob which is used to vary the sensitivity of the gas sensor. The third pin is the ground pin and the fourth pin the power supply Vcc pin. When the digital output is high, a LED on the module will turn ON. The second pin is digital output pin which can be configured to output high signal when certain level of gas is reached. The first pin is continuous analog output pin which can be read by the ADC module of a microcontroller. The module has four pins as shown in the MQ-2 pin out figure. The output voltage is taken from this voltage divider. The load resistor(Rl) and the sensor resistor(Rs) form a voltage divider. The potentiometer is used to adjust the sensitivity.
#Arduino sensors tutorial mq2 tutorial series
These two resistor together forms a series load resistor(Rl). The MQ-2 module has protection resistor and potentiometer.
