Programming Examples
Arduino program to interface gas sensor to detect the gas

Interfacing a gas sensor with an Arduino is straightforward. In this example, we'll use the MQ-2 gas sensor, which can detect various gases like LPG, methane, and smoke. The sensor outputs an analog signal corresponding to the gas concentration.
Components Needed:
- Arduino board (e.g., Uno)
- MQ-2 gas sensor module
- Breadboard and jumper wires
Circuit Connection:
- Connect the VCC pin of the gas sensor to the 5V pin of the Arduino.
- Connect the GND pin of the gas sensor to the GND pin of the Arduino.
- Connect the A0 pin of the gas sensor to the A0 analog input pin of the Arduino.
Output/ Explanation:
analogRead(gasSensorPin);: Reads the analog value from the gas sensor. The value ranges from 0 to 1023, corresponding to the gas concentration.
Serial.print("Gas Sensor Value: ");: Prints a label to the Serial Monitor.
Serial.println(sensorValue);: Prints the sensor value to the Serial Monitor on a new line