Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
AJ-Explains-It-All
Published © GPL3+

MQ-2 Gas Sensor Arduino

I have worked on MQ-2 gas sensor (FC-22) powered and interfaced it with an Arduino Uno.

IntermediateFull instructions provided1 hour37,395
MQ-2 Gas Sensor Arduino

Things used in this project

Story

Read more

Schematics

schematic

PIN diagram MQ2

Code

Code snippet #1

Plain text
******
 
 All the resources for this project:
 https://www.electromaniaweb.wordpress.com 
https://www.arduino.cc

*******/

int LED1 = 12;
int LED2 = 11;
int buzzer = 10;
int smokeA0 = A5;
int sensorThreshold = 400;

void setup() {
  pinMode(LED1, OUTPUT);
  pinMode(greenLed, OUTPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(smokeA0, INPUT);
  Serial.begin(9600);
}

void loop() {
  int analogSensor = analogRead(smokeA0);

  Serial.print("Pin A0: ");
  Serial.println(analogSensor);
  // Checks if it has reached the threshold value
  if (analogSensor > sensorThreshold)
  {
    digitalWrite(LED1, HIGH);
    digitalWrite(LED2, LOW);
    tone(buzzer, 1000, 200);
  }
  else
  {
    digitalWrite(LED1, LOW);
    digitalWrite(LED2, HIGH);
    noTone(buzzer);
  }
  delay(100);
}

CODE

Arduino
All the resources for this project:
 https://www.electromaniaweb.wordpress.com 
https://www.arduino.cc

*******/

int LED1 = 12;
int LED2 = 11;
int buzzer = 10;
int smokeA0 = A5;
int sensorThreshold = 400;

void setup() {
  pinMode(LED1, OUTPUT);
  pinMode(greenLed, OUTPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(smokeA0, INPUT);
  Serial.begin(9600);
}

void loop() {
  int analogSensor = analogRead(smokeA0);

  Serial.print("Pin A0: ");
  Serial.println(analogSensor);
  // Checks if it has reached the threshold value
  if (analogSensor > sensorThreshold)
  {
    digitalWrite(LED1, HIGH);
    digitalWrite(LED2, LOW);
    tone(buzzer, 1000, 200);
  }
  else
  {
    digitalWrite(LED1, LOW);
    digitalWrite(LED2, HIGH);
    noTone(buzzer);
  }
  delay(100);
}

Credits

AJ-Explains-It-All
12 projects • 10 followers
Experienced embedded firmware and software developer. I have a great affinity towards ARM cortex based MCU's.

Comments