electronicsfan123
Published © GPL3+

Smoke detector using MQ-2 Gas sensor

In this tutorial, we will see how to make a smoke detector that will help prevent smoking in public areas.

BeginnerFull instructions provided4,814
Smoke detector using MQ-2 Gas sensor

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
LED Dot Matrix Display, Red
LED Dot Matrix Display, Red
×1
Buzzer
Buzzer
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Circuit diagram

Image

Image

Code

Code

C#
#include <MaxMatrix.h>
int buzzer = 10;
int smokeA0 = A5;
int sensorThres = 400;
int DIN = 7;
int CLK = 6;
int CS = 5;
int maxInUse = 1;
byte buffer[20];
char text[] = "a";
MaxMatrix m(DIN, CS, CLK, maxInUse);

void setup() {
  pinMode(buzzer, OUTPUT);
  pinMode(smokeA0, INPUT);
  Serial.begin(9600);
  {
 m.init();
 m.setIntensity(8);
}
}

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

  Serial.print("Pin A0: ");
  Serial.println(analogSensor);
  // Checks if it has reached the threshold value
  if (analogSensor > sensorThres)
  {

    tone(buzzer, 1000, 200);
  }
  else
  {
    
    noTone(buzzer);
  }
  delay(100);
{
  m.setDot(7, 7, true);
  delay(300);
  m.setDot(6, 6, true);
  delay(300);
m.setDot(5, 5, true);
  delay(300);
  m.setDot(4, 4, true);
  delay (300);
  m.setDot(3, 3, true);
  delay(300);
  m.setDot(2, 2, true);
  delay(300);
  m.setDot(1, 1, true);
  delay(300);
  m.setDot(0, 0, true);
  delay(300);
  m.setDot(0, 7, true);
  delay(300);
  m.setDot(1, 6, true);
  delay(300);
  m.setDot(2, 5, true);
  delay(300);
  m.setDot(3, 4, true);
  delay(300);
  m.setDot(4, 3, true);
  delay(300);
  m.setDot(5, 2, true);
  delay(300);
  m.setDot(6, 1, true);
  delay(300);
  m.setDot(7, 0, true);
  delay(300);
  
 
  m.clear();
  delay(1000);}
} 

Credits

electronicsfan123

electronicsfan123

5 projects • 8 followers

Comments