Alex WhitakerSam Weaver
Published

Hazardous Gas Detector

The handheld hazardous gas detector is a lifesaving device for technicians and engineers who want to ensure their safety at work.

IntermediateFull instructions provided20 hours124
Hazardous Gas Detector

Things used in this project

Hardware components

Argon
Particle Argon
×2
LED (generic)
LED (generic)
×6
Gravity: Analog Gas Sensor (MQ2) For Arduino
DFRobot Gravity: Analog Gas Sensor (MQ2) For Arduino
×1
Gravity: Analog LPG Gas Sensor (MQ5) For Arduino
DFRobot Gravity: Analog LPG Gas Sensor (MQ5) For Arduino
×1
Carbon Monoxide Sensor (MQ7)
DFRobot Carbon Monoxide Sensor (MQ7)
×1
Gravity: Analog CO/Combustible Gas Sensor (MQ9) For Arduino
DFRobot Gravity: Analog CO/Combustible Gas Sensor (MQ9) For Arduino
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×2
Rechargeable Battery, Lithium Ion
Rechargeable Battery, Lithium Ion
×2
Resistor 100 ohm
Resistor 100 ohm
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)
Tape, Electrical
Tape, Electrical
3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

Hazard Gas Case

Schematics

IOT Hazard Gas Detector IOT Circuit

Code

Argon 1 Code

Arduino
// MQ-2 Smoke Sensor
int Led1 = D3;
int smokeSensor = A5;
int smokeThres = 1140;

// MQ-7 Carbon Monoxide Sensor
int Led2 = D5;
int coSensor = A3;
int coThres = 1060;

// led goes off when other Argon senses gas
int buddyLED = D1;

int natGasSensor = 0;
int combustibleSensor = 0;

void natGasHandler(const char *event, const char *data) {
  natGasSensor = String(data).toInt();
}

void combustibleHandler(const char *event, const char *data) {
  combustibleSensor = String(data).toInt();
}

void setup() {
  pinMode(Led1, OUTPUT);
  pinMode(smokeSensor, INPUT);
  pinMode(Led2, OUTPUT);
  pinMode(coSensor, INPUT);
  pinMode(buddyLED, OUTPUT);

  Particle.subscribe("Natural Gas Sensor", natGasHandler);
  Particle.subscribe("Combustible Sensor", combustibleHandler);
}

void loop() {
  // reads the smoke sensor data
  int smokeSensorReading = analogRead(smokeSensor);

  // lights up LED if sensor is higher than the sensor threshold
  if (smokeSensorReading > smokeThres) {
    digitalWrite(Led1, HIGH);
  }
  else {
    digitalWrite(Led1, LOW);
  }

  // publishes data and waits until a set amount of time has passed to keep running
  Particle.publish("Smoke Sensor", String(smokeSensorReading));
  delay(4500);
  
  // reads the data from the CO sensor
  int coSensorReading = analogRead(coSensor);
  
  // lights up another LED if sensor is higher than sensor threshold
  if (coSensorReading > coThres) {
    digitalWrite(Led2, HIGH);
  }
  else {
    digitalWrite(Led2, LOW);
  }

  // publishes data and waits until a set amount of time has passed to keep running
  Particle.publish("Carbon Monoxide Sensor", String(coSensorReading));
  delay(4500);
  
  // turns on LED if the other Argon detects hazardous gas
  if (natGasSensor>880 || combustibleSensor>1400) {
    digitalWrite(buddyLED, HIGH);
  } else {
    digitalWrite(buddyLED, LOW);
  }
}

Argon 2 Code

Arduino
// MQ-5 Natural Gas Sensor
int Led1 = D3;
int natGasSensor = A5;
int natGasThres = 880;

// MQ-9 Combustible Sensor
int Led2 = D5;
int combustibleSensor = A3;
int combustibleThres = 1400;

// led goes off when other Argon senses gas
int buddyLED = D1;

int smokeSensor = 0;
int coSensor = 0;

void smokeHandler(const char *event, const char *data) {
  smokeSensor = String(data).toInt();
}

void coHandler(const char *event, const char *data) {
  coSensor = String(data).toInt();
}

void setup() {
  pinMode(Led1, OUTPUT);
  pinMode(natGasSensor, INPUT);
  pinMode(Led2, OUTPUT);
  pinMode(combustibleSensor, INPUT);
  pinMode(buddyLED, OUTPUT);

  Particle.subscribe("Smoke Sensor", smokeHandler);
  Particle.subscribe("Carbon Monoxide Sensor", coHandler);
}

void loop() {
  // reads the natural gas sensor data
  int natGasSensorReading = analogRead(natGasSensor);
  
  // lights up another LED if sensor is higher than sensor threshold
  if (natGasSensorReading > natGasThres) {
    digitalWrite(Led1, HIGH);
  }
  else {
    digitalWrite(Led1, LOW);
  }

  // publishes data to particle
  Particle.publish("Natural Gas Sensor", String(natGasSensorReading));
  delay(4500);
  
  // reads the data from the combustibel sensor
  int combustibleSensorReading = analogRead(combustibleSensor);
  
  // lights up another LED if sensor is higher than sensor threshold
  if (combustibleSensorReading > combustibleThres) {
    digitalWrite(Led2, HIGH);
  }
  else {
    digitalWrite(Led2, LOW);
  }
 
  // publishes the data to particle
  Particle.publish("Combustible Sensor", String(combustibleSensorReading));
  delay(4500);

  // turns on LED if the other Argon detects hazardous gas
  if (smokeSensor>1140 || coSensor>1060) {
    digitalWrite(buddyLED, HIGH);
  } else {
    digitalWrite(buddyLED, LOW);
  }
}

Credits

Alex Whitaker

Alex Whitaker

1 project • 2 followers
Sam Weaver

Sam Weaver

1 project • 2 followers

Comments