

- ARDUINO SENSORS TUTORIAL MQ2 TUTORIAL HOW TO
- ARDUINO SENSORS TUTORIAL MQ2 TUTORIAL CODE
- ARDUINO SENSORS TUTORIAL MQ2 TUTORIAL TRIAL
- ARDUINO SENSORS TUTORIAL MQ2 TUTORIAL SERIES

Input: raw_adc - raw value read from adc, which represents the voltage Lcd.print(MQGetGasPercentage(MQRead(MQ_PIN) / Ro, GAS_SMOKE) ) MQ2 Smoke Sensor Arduino Uno Jumper wires Arduino IDE Nowadays, electrical systems are used in every part of our lives. 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). Circuit DiagramĪs you can see, V cc of MQ2 is connected to 5V, GND to GND and A out to A0.The MQ-2 module has protection resistor and potentiometer.
ARDUINO SENSORS TUTORIAL MQ2 TUTORIAL TRIAL
Depending on your application, you can perform some trial and errors, and determine the threshold of A out voltage above which you want to raise an alarm.Īlternatively, you can adjust the potentiometer on the other side of the sensor to set the threshold, and then use the D out pin to get digital value (whether concentration of gas is above or below threshold). Higher the gas concentration, higher the voltage on the A out pin. Out of these the A out pin gives the Analog voltage in proportion to the gas concentration. This principle can be used to raise an alarm based on the concentration of the gas.Īn image of the MQ2 gas sensor is given above. It changes its resistance depending on the type of the gas. MQ2 gas sensor is used for detecting smoke and some flammable gases like LPG, Methane, etc.
ARDUINO SENSORS TUTORIAL MQ2 TUTORIAL HOW TO
In this article, we will see how to interface Arduino with the MQ-2 gas sensor.
