Devices & Components
Arduino Uno Rev3
Gravity: Analog Gas Sensor (MQ2) For Arduino
Software & Tools
Arduino IDE
Project description
Code
Program of MQ2 Sensor with Arduino UNO R3
arduino
1//Coded and tested by : 2// Sheekar Banejee, AI-ML-IOT Solution Engineer and Researcher 3 4int smokeA0 = A0; 5// Your threshold value 6int sensorThres = 700; 7 8void setup() { 9 pinMode(smokeA0, INPUT); 10 Serial.begin(9600); //Streaming 9600 bits of Sensor Data per Second 11} 12 13void loop() { 14 int analogSensor = analogRead(smokeA0); 15 16 Serial.println("Sensor Value: "); 17 Serial.println(analogSensor); 18 // Checks if it has reached the threshold value 19 if (analogSensor > sensorThres) 20 { 21 Serial.println("Alert! Smoke Detected!"); 22 } 23 else 24 { 25 Serial.println("Normal..."); 26 } 27 delay(3000); 28}
Downloadable files
Circuit Diagram of MQ2 Sensor with Arduino UNO R3
Circuit Diagram of MQ2 Sensor with Arduino UNO R3

Circuit Diagram of MQ2 Sensor with Arduino UNO R3
Circuit Diagram of MQ2 Sensor with Arduino UNO R3

Comments
Only logged in users can leave comments