Sitemap / Advertise

Introduction

Using an IR remote control, display the presence of hazardous gases w/ MQ-2, MQ-3, MQ-4, MQ-6, MQ-9 and get notified when they reach dangerous levels.


Tags

Share

Joker Remote Hazardous Gas Station and Monitor

Advertisement:


read_later

Read Later



read_later

Read Later

Introduction

Using an IR remote control, display the presence of hazardous gases w/ MQ-2, MQ-3, MQ-4, MQ-6, MQ-9 and get notified when they reach dangerous levels.

Tags

Share





Advertisement

Advertisement




    Components :
  • [1]PCBWay Custom PCB
  • [1]Arduino Nano
  • [1]ST7789 240x240 IPS Screen
  • [1]IR Remote Control and Receiver
  • [1]MQ-2 Gas Sensor
  • [1]MQ-3 Gas Sensor
  • [1]MQ-4 Gas Sensor
  • [1]MQ-6 Gas Sensor
  • [1]MQ-9 Gas Sensor
  • [1]Buzzer
  • [1]5mm Common Anode RGB LED
  • [7]220Ω Resistor
  • [5]20K Resistor
  • [1]Power Jack
  • [1]External Battery (5V)

Description

For a long time, I wanted to create a unique device to observe the presence of varying hazardous gases for a breadth of applications such as air quality monitoring and gas leak detection. Thus, I decided to develop this project.

First of all, to elicit assiduous gas measuring results, I chose to utilize these MQ series gas sensors by connecting them to the Arduino Nano:

After choosing gas sensors for my device, I decided to control its settings and features with an IR remote control. Hence, I connected an IR remote receiver module to the Arduino Nano. Then, to display generated gas measurements, I used an ST7789 IPS screen.

Finally, I added a buzzer and a 5mm common anode RGB LED to get notified when gases reach dangerous levels.

As you may have known, the toxic gas compound manufactured by Joker (Joker Venom or Laughing Gas) is considered remarkably dangerous in DC Universe. Hence, I shaped my device inspired by Joker's appearance in comics as a reminder of the detrimental effects of gases.

After completing wiring on a breadboard and testing the code, I designed my Joker-inspired PCB to complete my project. It became a stylish and intriguing addition to my workplace as an effective apparatus to monitor the presence of hazardous gases :)

Huge thanks to PCBWay for sponsoring this project.

project-image
Figure - 65.1


project-image
Figure - 65.2

Step 1: Designing and soldering the Joker Remote Gas Station PCB

Before prototyping my PCB design, I tested all connections and wiring with the Arduino Nano on the breadboard.

project-image
Figure - 65.3

Then, I designed the Joker Remote Gas Station PCB by using KiCad. I attached the Gerber file of the PCB below, so if you want, you can order this PCB from PCBWay to create a fitting and apt apparatus to observe the presence of hazardous gases and get notified when they reach dangerous levels - inspired by malicious Joker :)

Click here to inspect and order this PCB directly on PCBWay.

project-image
Figure - 65.4


project-image
Figure - 65.5

First of all, by utilizing a soldering iron, I attached Arduino Nano, IR receiver module, MQ-2 gas sensor, MQ-3 gas sensor, MQ-4 gas sensor, MQ-6 gas sensor, MQ-9 gas sensor, headers (female), buzzer, 5mm common anode RGB LED, 220Ω resistors, 20K resistors, and power jack.

Component list on the PCB:

A1 (Arduino Nano)

S1 (Headers for ST7789 IPS Screen)

IR1 (IR Receiver Module)

MQ2 (MQ-2 Gas Sensor)

MQ3 (MQ-3 Gas Sensor)

MQ4 (MQ-4 Gas Sensor)

MQ6 (MQ-6 Gas Sensor)

MQ9 (MQ-9 Gas Sensor)

BZ1 (Buzzer)

D1 (5mm Common Anode RGB LED)

R1, R2, R3, R4, R5, R6, R7 (220Ω Resistor)

R8, R9, R10, R11, R12 (20K Resistor)

J1 (Power Jack)

J2 (Headers for External Battery)

project-image
Figure - 65.6


project-image
Figure - 65.7


project-image
Figure - 65.8

Step 2: Programming Arduino Nano and setting up components

Download the required library to be able to control the IR receiver module:

Arduino-IRremote | Library

Download the required libraries to be able to use the ST7789 240x240 IPS screen:

Arduino_ST7789_Fast | Library

Adafruit_GFX | Library

⭐ Include the required libraries.

⭐ Define the IR receiver module pin and settings.


#include <Adafruit_GFX.h>
#include <Arduino_ST7789_Fast.h>
#include <IRremote.h>

// Define the IR receiver module pin and settings.
#define RECV_PIN 2
IRrecv irrecv(RECV_PIN); 
decode_results results;

⭐ By executing the IRrecvDemo.ino file in Examples, obtain the required IR codes from the IR remote control and define them.


#define up 0xFF18E7
#define down 0xFF4AB5
#define right 0xFF5AA5
#define left 0xFF10EF
#define ok 0xFF38C7

⭐ Define the ST7789 240x240 IPS display settings.


#define TFT_DC    10
#define TFT_RST   9
#define SCR_WD   240
#define SCR_HT   240

⭐ To display images on the ST7789 screen, convert them to .c files by using this image converter below:

ImageConverter (UTFT)

You can download the converted images I used in Downloads - gas.c, lethal.c, and toxic.c.

⭐ Include the converted images.


#include "gas.c"
#include "lethal.c"
#include "toxic.c"

⭐ Initiate the ST7789 240x240 IPS display.


Arduino_ST7789 tft = Arduino_ST7789(TFT_DC, TFT_RST); 

⭐ Initiate the IR receiver module.

⭐ Start and clear the ST7789 240x240 IPS display.


  irrecv.enableIRIn();

  tft.init(SCR_WD, SCR_HT);
  tft.fillScreen(RGBto565(235, 46, 0));

⭐ In the read_IR_controls function, collect IR codes from the IR remote control when transmitted.


void read_IR_controls(){
  // Read received IR codes from the IR remote control.
  if(irrecv.decode(&results)){
    IR_codeValue = results.value;
    irrecv.resume();
    delay(500);
  }else{
    IR_codeValue = 0;
  }
}

⭐ In the collect_Data function, get gas measurements produced by MQ series gas sensors - MQ-2, MQ-3, MQ-4, MQ-6, and MQ-9.


void collect_Data(){
  // Get variables generated by the gas sensors.
  mq_2_val = analogRead(mq_2);
  mq_3_val = analogRead(mq_3);
  mq_4_val = analogRead(mq_4);
  mq_6_val = analogRead(mq_6);
  mq_9_val = analogRead(mq_9);
}

⭐ In the interface function, print the interface with menu options.


void interface(){
  // Print interface with menu options.
  tft.setTextColor(RGBto565(0, 38, 153), RGBto565(235, 46, 0));
  tft.setTextSize(4);
  tft.setCursor(75, 25);
  tft.println("MQ-2");
  tft.setCursor(75, 65);
  tft.println("MQ-3");
  tft.setCursor(75, 105);
  tft.println("MQ-4");
  tft.setCursor(75, 145);
  tft.println("MQ-6");
  tft.setCursor(75, 185);
  tft.println("MQ-9");
}

⭐ In the change_menu_options function, increase or decrease the option number by using the IR remote control buttons - Up and Down - to switch between menu options on the interface.


void change_menu_options(){
  // Increase or decrease the option number using the IR remote control buttons.
  if(IR_codeValue == up) selected--; 
  if(IR_codeValue == down) selected++; 
  if(selected < 0) selected = 5;
  if(selected > 5) selected = 1;
  delay(100);

  // Depending on the selected option number, change the boolean status.
  switch(selected){
    case 1:
      mq2 = true;
      mq3 = false;
      mq4 = false;
      mq6 = false;
      mq9 = false;
    break;
    case 2:     
      mq2 = false;
      mq3 = true;
      mq4 = false;
      mq6 = false;
      mq9 = false;
    break;
    case 3:
      mq2 = false;
      mq3 = false;
      mq4 = true;
      mq6 = false;
      mq9 = false;
    break;
    case 4:
      mq2 = false;
      mq3 = false;
      mq4 = false;
      mq6 = true;
      mq9 = false;
    break;
    case 5:
      mq2 = false;
      mq3 = false;
      mq4 = false;
      mq6 = false;
      mq9 = true;
    break;
  }
}

project-image
Figure - 65.9


project-image
Figure - 65.10


project-image
Figure - 65.11


project-image
Figure - 65.12

Step 2.1: Displaying the presence of hazardous gases

To detect the presence of hazardous gases, I utilized these five MQ series gas sensors:

MQ-2 gas sensor has a high sensitivity to LPG, Propane, and Hydrogen, also can be used to detect Methane and other combustible steam.

MQ-3 gas sensor has a high sensitivity to Alcohol and has good resistance to gasoline, smoke, and vapor. This sensor can detect Alcohol with different concentrations.

MQ-4 gas sensor has a high sensitivity to Methane, Propane, and Butane. This sensor can detect different combustible gases.

MQ-6 gas sensor has a high sensitivity to Propane, Butane, and LPG, also response to Natural gas. This sensor can detect different combustible gases such as Natural gas, colorless flammable gaseous hydrocarbon consisting primarily of Methane and Ethane.

MQ-9 gas sensor has a high sensitivity to Carbon Monoxide, Methane, and LPG. This sensor can detect different gases containing CO and combustible gases.

As expected, after being connected to Arduino Nano, each sensor generates different value ranges depending on the amount of detectable hazardous gases.

After testing, I assigned these levels below for each sensor empirically. Change them after testing your sensors if required.


mq_2_val < 600 ➡ Low
600 < mq_2_val < 700 ➡ Moderate
mq_2_val >= 700 ➡ Dangerous

mq_3_val < 650 ➡ Low
650 < mq_3_val < 800 ➡ Moderate
mq_3_val >= 800 ➡ Dangerous

mq_4_val < 450 ➡ Low
450 < mq_4_val < 600 ➡ Moderate
mq_4_val >= 600 ➡ Dangerous

mq_6_val < 500 ➡ Low
500 < mq_6_val < 650 ➡ Moderate
mq_6_val >= 650 ➡ Dangerous

mq_9_val < 700 ➡ Low
700 < mq_9_val < 850 ➡ Moderate
mq_9_val >= 850 ➡ Dangerous

⭐ If a menu option is selected using the Up and Down buttons, highlight its name on the interface.

project-image
Figure - 65.13

⭐ After being selected, if a menu option is activated using the OK button:

⭐ Collect and display the gas measurement value of the selected MQ series sensor with the converted images.

⭐ If the gas measurement value is Low according to the assigned levels, adjust the RGB LED to green.

⭐ If the gas measurement value is Moderate according to the assigned levels, adjust the RGB LED to yellow.

⭐ If the gas measurement value is Dangerous according to the assigned levels, adjust the RGB LED to red and turn on the buzzer to notify the user.

⭐ By pressing the Left button, return to the interface.


  if(mq2){
    do{
      tft.setTextColor(RGBto565(0, 38, 153), WHITE);
      tft.setTextSize(4);
      tft.setCursor(75, 25);
      tft.println("MQ-2");
      if(IR_codeValue == ok){
        activated = true;
        tft.fillScreen(WHITE);
        while(activated){
          read_IR_controls();
          // Print data:
          collect_Data();
          tft.setCursor(75, 25);
          tft.setTextColor(BLACK, WHITE);
          tft.setTextSize(4);
          tft.print(F("MQ-2"));
          tft.drawImageF(30, 80, 40, 40, gas);
          tft.drawImageF(100, 80, 40, 40, lethal);
          tft.drawImageF(170, 80, 40, 40, toxic);
          tft.setCursor(60, 160);
          tft.setTextSize(7);
          tft.print(mq_2_val);
          // Check gas status:
          if(mq_2_val < 600){ adjustColor(0, 255, 0); }
          else if(mq_2_val >= 600 && mq_2_val < 700){ adjustColor(255, 255, 0); }
          else if(mq_2_val >= 700){ adjustColor(255, 0, 0); tone(buzzer, 500, 1000); }
          // Exit and Close:
          if(IR_codeValue == left){ activated = false; tft.fillScreen(RGBto565(235, 46, 0)); adjustColor(0, 0, 0); noTone(buzzer); }
        }
      }
    }while(!mq2);
  }
  
  ...
  

project-image
Figure - 65.14


project-image
Figure - 65.15

Step 2.2: Fixing the timer0_pin_port error

Unfortunately, when using the IR remote library and the tone library, the Arduino IDE throws the timer0_pin_port error. The error occurs because both libraries try to use the timer by declaring the same name - Timer2.

To fix this issue, open the boarddefs.h or IRremoteBoardDefs.h file depending on the IR remote library version. Then, change IR_USE_TIMER2 to IR_USE_TIMER1 for Arduino Nano.

project-image
Figure - 65.16

Connections and Adjustments


// Connections
// Arduino Nano :  
//                                IR Receiver Module
// D2  --------------------------- S         
//                                ST7789 240x240 IPS
// GND --------------------------- GND
// 3.3V -------------------------- VCC
// D13 --------------------------- SCL
// D11 --------------------------- SDA
// D9  --------------------------- RES
// D10 --------------------------- DC
//                                MQ-2 Air Quality Sensor
// A0  --------------------------- S
//                                MQ-3 Air Quality Sensor
// A1  --------------------------- S
//                                MQ-4 Air Quality Sensor
// A2  --------------------------- S
//                                MQ-6 Air Quality Sensor
// A3  --------------------------- S
//                                MQ-9 Air Quality Sensor
// A4  --------------------------- S
//                                5mm Common Anode RGB LED
// D3  --------------------------- R
// D5  --------------------------- G
// D6  --------------------------- B
//                                Buzzer
// D7  --------------------------- +

After completing soldering and uploading the code, I attached all remaining components to the board via headers - ST7789 240x240 IPS screen.

project-image
Figure - 65.17

Unluckily, even though Arduino Nano works at 5V, the current provided by Nano is not enough for five MQ series gas sensors to get heated and generate accurate gas measurements. Thus, I added a power jack (J1) and a connector (J2) to my PCB design to supply the sensors with an external battery (5V).

project-image
Figure - 65.18

Modes and Features

🤡🃏 The device shows five different MQ series sensors as menu options on the interface to display their gas measurements individually:

project-image
Figure - 65.19

🤡🃏 The device allows the user to switch between MQ series sensors (menu options) to observe their gas measurements via the IR remote control:

🤡🃏 After activating any MQ series sensors by pressing the OK button of the IR remote control to display their gas measurements, the device lets the user return to the interface by pressing the Left button.

📌 MQ Series Sensors (Menu Options)

🤡🃏 If the MQ-2 option is selected and activated, the device shows its hazardous gas measurement value.

🤡🃏 Depending on the assigned measurement levels for the selected sensor (Step 2.1), the device adjusts the RGB LED:

🤡🃏 The device turns on the buzzer if the hazardous gas measurement value is Dangerous according to the assigned levels.

project-image
Figure - 65.20


project-image
Figure - 65.21

🤡🃏 If the MQ-3 option is selected and activated, the device shows its hazardous gas measurement value.

🤡🃏 Depending on the assigned measurement levels for the selected sensor (Step 2.1), the device adjusts the RGB LED:

🤡🃏 The device turns on the buzzer if the hazardous gas measurement value is Dangerous according to the assigned levels.

project-image
Figure - 65.22


project-image
Figure - 65.23

🤡🃏 If the MQ-4 option is selected and activated, the device shows its hazardous gas measurement value.

🤡🃏 Depending on the assigned measurement levels for the selected sensor (Step 2.1), the device adjusts the RGB LED:

🤡🃏 The device turns on the buzzer if the hazardous gas measurement value is Dangerous according to the assigned levels.

project-image
Figure - 65.24


project-image
Figure - 65.25

🤡🃏 If the MQ-6 option is selected and activated, the device shows its hazardous gas measurement value.

🤡🃏 Depending on the assigned measurement levels for the selected sensor (Step 2.1), the device adjusts the RGB LED:

🤡🃏 The device turns on the buzzer if the hazardous gas measurement value is Dangerous according to the assigned levels.

project-image
Figure - 65.26


project-image
Figure - 65.27

🤡🃏 If the MQ-9 option is selected and activated, the device shows its hazardous gas measurement value.

🤡🃏 Depending on the assigned measurement levels for the selected sensor (Step 2.1), the device adjusts the RGB LED:

🤡🃏 The device turns on the buzzer if the hazardous gas measurement value is Dangerous according to the assigned levels.

project-image
Figure - 65.28


project-image
Figure - 65.29

Videos and Conclusion

After completing all steps above, I placed the device on my desk by utilizing a plastic easel as an efficient assistant to detect the presence of hazardous gases in my workplace. It works impeccably :)

project-image
Figure - 65.30

Code

Joker_Remote_Gas_Station.ino

Download



         /////////////////////////////////////////////  
        //   Joker Remote Hazardous Gas Station    //
       //              and Monitor                //
      //             ---------------             //
     //             (Arduino Nano)              //           
    //             by Kutluhan Aktar           // 
   //                                         //
  /////////////////////////////////////////////

//
// Using an IR remote control, display the presence of hazardous gases w/ MQ-2, MQ-3, MQ-4, MQ-6, MQ-9 and get notified when they reach dangerous levels.
//
// For more information:
// https://www.theamplituhedron.com/projects/Joker_Remote_Hazardous_Gas_Station_and_Monitor
//
//
// Connections
// Arduino Nano :  
//                                IR Receiver Module
// D2  --------------------------- S         
//                                ST7789 240x240 IPS
// GND --------------------------- GND
// 3.3V -------------------------- VCC
// D13 --------------------------- SCL
// D11 --------------------------- SDA
// D9  --------------------------- RES
// D10 --------------------------- DC
//                                MQ-2 Air Quality Sensor
// A0  --------------------------- S
//                                MQ-3 Air Quality Sensor
// A1  --------------------------- S
//                                MQ-4 Air Quality Sensor
// A2  --------------------------- S
//                                MQ-6 Air Quality Sensor
// A3  --------------------------- S
//                                MQ-9 Air Quality Sensor
// A4  --------------------------- S
//                                5mm Common Anode RGB LED
// D3  --------------------------- R
// D5  --------------------------- G
// D6  --------------------------- B
//                                Buzzer
// D7  --------------------------- +

/*
 ST7789 240x240 IPS (without CS pin) connections (only 6 wires required):

 #01 GND -> GND
 #02 VCC -> VCC (3.3V only!)
 #03 SCL -> D13/SCK
 #04 SDA -> D11/MOSI
 #05 RES -> D8 or any digital
 #06 DC  -> D7 or any digital
 #07 BLK -> NC
*/

// Include the required libraries.
#include <Adafruit_GFX.h>
#include <Arduino_ST7789_Fast.h>
#include <IRremote.h>

// Define the IR receiver module pin and settings.
#define RECV_PIN 2
IRrecv irrecv(RECV_PIN); 
decode_results results;

// IR codes obtained from the IR remote control by executing the IRrecvDemo.ino file.
#define up 0xFF18E7
#define down 0xFF4AB5
#define right 0xFF5AA5
#define left 0xFF10EF
#define ok 0xFF38C7

// Define the ST7789 240x240 IPS display settings.
#define TFT_DC    10
#define TFT_RST   9
#define SCR_WD   240
#define SCR_HT   240

// Include the converted images:
#include "gas.c"
#include "lethal.c"
#include "toxic.c"

// Initiate the ST7789 240x240 IPS display.
Arduino_ST7789 tft = Arduino_ST7789(TFT_DC, TFT_RST); 

// Define the gas sensors' pins.
#define mq_2 A0
#define mq_3 A1
#define mq_4 A2
#define mq_6 A3
#define mq_9 A4

// Define RGB pins.
#define redPin 3
#define greenPin 5
#define bluePin 6

// Define the buzzer pin.
#define buzzer 7

// Define interface options:
volatile boolean mq2, mq3, mq4, mq6, mq9, activated;

// Define data holders:
int mq_2_val, mq_3_val, mq_4_val, mq_6_val, mq_9_val, selected = 0;
unsigned long IR_codeValue = 0;
 
void setup() {
  Serial.begin(9600);

  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);  
  adjustColor(0,0,0);
  
  // Initiate the IR receiver module.
  irrecv.enableIRIn();

  // Open and clear the ST7789 240x240 IPS display.
  tft.init(SCR_WD, SCR_HT);
  tft.fillScreen(RGBto565(235, 46, 0));

}

void loop() {
  read_IR_controls();
  collect_Data();
  interface();
  change_menu_options();
  
  if(mq2){
    do{
      tft.setTextColor(RGBto565(0, 38, 153), WHITE);
      tft.setTextSize(4);
      tft.setCursor(75, 25);
      tft.println("MQ-2");
      if(IR_codeValue == ok){
        activated = true;
        tft.fillScreen(WHITE);
        while(activated){
          read_IR_controls();
          // Print data:
          collect_Data();
          tft.setCursor(75, 25);
          tft.setTextColor(BLACK, WHITE);
          tft.setTextSize(4);
          tft.print(F("MQ-2"));
          tft.drawImageF(30, 80, 40, 40, gas);
          tft.drawImageF(100, 80, 40, 40, lethal);
          tft.drawImageF(170, 80, 40, 40, toxic);
          tft.setCursor(60, 160);
          tft.setTextSize(7);
          tft.print(mq_2_val);
          // Check gas status:
          if(mq_2_val < 600){ adjustColor(0, 255, 0); }
          else if(mq_2_val >= 600 && mq_2_val < 700){ adjustColor(255, 255, 0); }
          else if(mq_2_val >= 700){ adjustColor(255, 0, 0); tone(buzzer, 500, 1000); }
          // Exit and Close:
          if(IR_codeValue == left){ activated = false; tft.fillScreen(RGBto565(235, 46, 0)); adjustColor(0, 0, 0); noTone(buzzer); }
        }
      }
    }while(!mq2);
  }

  if(mq3){
    do{
      tft.setTextColor(RGBto565(0, 38, 153), WHITE);
      tft.setTextSize(4);
      tft.setCursor(75, 65);
      tft.println("MQ-3");
      if(IR_codeValue == ok){
        activated = true;
        tft.fillScreen(WHITE);
        while(activated){
          read_IR_controls();
          // Print data:
          collect_Data();
          tft.setCursor(75, 25);
          tft.setTextColor(BLACK, WHITE);
          tft.setTextSize(4);
          tft.print(F("MQ-3"));
          tft.drawImageF(30, 80, 40, 40, gas);
          tft.drawImageF(100, 80, 40, 40, lethal);
          tft.drawImageF(170, 80, 40, 40, toxic);
          tft.setCursor(60, 160);
          tft.setTextSize(7);
          tft.print(mq_3_val);
          // Check gas status:
          if(mq_3_val < 650){ adjustColor(0, 255, 0); }
          else if(mq_3_val >= 650 && mq_3_val < 800){ adjustColor(255, 255, 0); }
          else if(mq_3_val >= 800){ adjustColor(255, 0, 0); tone(buzzer, 500, 1000); }
          // Exit and Close:
          if(IR_codeValue == left){ activated = false; tft.fillScreen(RGBto565(235, 46, 0)); adjustColor(0, 0, 0); noTone(buzzer); }
        }
      }
    }while(!mq3);
  }

  if(mq4){
    do{
      tft.setTextColor(RGBto565(0, 38, 153), WHITE);
      tft.setTextSize(4);
      tft.setCursor(75, 105);
      tft.println("MQ-4");
      if(IR_codeValue == ok){
        activated = true;
        tft.fillScreen(WHITE);
        while(activated){
          read_IR_controls();
          // Print data:
          collect_Data();
          tft.setCursor(75, 25);
          tft.setTextColor(BLACK, WHITE);
          tft.setTextSize(4);
          tft.print(F("MQ-4"));
          tft.drawImageF(30, 80, 40, 40, gas);
          tft.drawImageF(100, 80, 40, 40, lethal);
          tft.drawImageF(170, 80, 40, 40, toxic);
          tft.setCursor(60, 160);
          tft.setTextSize(7);
          tft.print(mq_4_val);
          // Check gas status:
          if(mq_4_val < 450){ adjustColor(0, 255, 0); }
          else if(mq_4_val >= 450 && mq_4_val < 600){ adjustColor(255, 255, 0); }
          else if(mq_4_val >= 600){ adjustColor(255, 0, 0); tone(buzzer, 500, 1000); }
          // Exit and Close:
          if(IR_codeValue == left){ activated = false; tft.fillScreen(RGBto565(235, 46, 0)); adjustColor(0, 0, 0); noTone(buzzer); }
        }
      }
    }while(!mq4);
  }

  if(mq6){
    do{
      tft.setTextColor(RGBto565(0, 38, 153), WHITE);
      tft.setTextSize(4);
      tft.setCursor(75, 145);
      tft.println("MQ-6");
      if(IR_codeValue == ok){
        activated = true;
        tft.fillScreen(WHITE);
        while(activated){
          read_IR_controls();
          // Print data:
          collect_Data();
          tft.setCursor(75, 25);
          tft.setTextColor(BLACK, WHITE);
          tft.setTextSize(4);
          tft.print(F("MQ-6"));
          tft.drawImageF(30, 80, 40, 40, gas);
          tft.drawImageF(100, 80, 40, 40, lethal);
          tft.drawImageF(170, 80, 40, 40, toxic);
          tft.setCursor(60, 160);
          tft.setTextSize(7);
          tft.print(mq_6_val);
          // Check gas status:
          if(mq_6_val < 500){ adjustColor(0, 255, 0); }
          else if(mq_6_val >= 500 && mq_6_val < 650){ adjustColor(255, 255, 0); }
          else if(mq_6_val >= 650){ adjustColor(255, 0, 0); tone(buzzer, 500, 1000); }
          // Exit and Close:
          if(IR_codeValue == left){ activated = false; tft.fillScreen(RGBto565(235, 46, 0)); adjustColor(0, 0, 0); noTone(buzzer); }
        }
      }
    }while(!mq6);
  }

  if(mq9){
    do{
      tft.setTextColor(RGBto565(0, 38, 153), WHITE);
      tft.setTextSize(4);
      tft.setCursor(75, 185);
      tft.println("MQ-9");
      if(IR_codeValue == ok){
        activated = true;
        tft.fillScreen(WHITE);
        while(activated){
          read_IR_controls();
          // Print data:
          collect_Data();
          tft.setCursor(75, 25);
          tft.setTextColor(BLACK, WHITE);
          tft.setTextSize(4);
          tft.print(F("MQ-9"));
          tft.drawImageF(30, 80, 40, 40, gas);
          tft.drawImageF(100, 80, 40, 40, lethal);
          tft.drawImageF(170, 80, 40, 40, toxic);
          tft.setCursor(60, 160);
          tft.setTextSize(7);
          tft.print(mq_9_val);
          // Check gas status:
          if(mq_9_val < 700){ adjustColor(0, 255, 0); }
          else if(mq_9_val >= 700 && mq_9_val < 850){ adjustColor(255, 255, 0); }
          else if(mq_9_val >= 850){ adjustColor(255, 0, 0); tone(buzzer, 500, 1000); }
          // Exit and Close:
          if(IR_codeValue == left){ activated = false; tft.fillScreen(RGBto565(235, 46, 0)); adjustColor(0, 0, 0); noTone(buzzer); }
        }
      }
    }while(!mq9);
  }

}

void read_IR_controls(){
  // Read received IR codes from the IR remote control.
  if(irrecv.decode(&results)){
    IR_codeValue = results.value;
    irrecv.resume();
    delay(500);
  }else{
    IR_codeValue = 0;
  }
}

void interface(){
  // Print interface with menu options.
  tft.setTextColor(RGBto565(0, 38, 153), RGBto565(235, 46, 0));
  tft.setTextSize(4);
  tft.setCursor(75, 25);
  tft.println("MQ-2");
  tft.setCursor(75, 65);
  tft.println("MQ-3");
  tft.setCursor(75, 105);
  tft.println("MQ-4");
  tft.setCursor(75, 145);
  tft.println("MQ-6");
  tft.setCursor(75, 185);
  tft.println("MQ-9");
}

void collect_Data(){
  // Get variables generated by the gas sensors.
  mq_2_val = analogRead(mq_2);
  mq_3_val = analogRead(mq_3);
  mq_4_val = analogRead(mq_4);
  mq_6_val = analogRead(mq_6);
  mq_9_val = analogRead(mq_9);
}

void change_menu_options(){
  // Increase or decrease the option number using the IR remote control buttons.
  if(IR_codeValue == up) selected--; 
  if(IR_codeValue == down) selected++; 
  if(selected < 0) selected = 5;
  if(selected > 5) selected = 1;
  delay(100);

  // Depending on the selected option number, change the boolean status.
  switch(selected){
    case 1:
      mq2 = true;
      mq3 = false;
      mq4 = false;
      mq6 = false;
      mq9 = false;
    break;
    case 2:     
      mq2 = false;
      mq3 = true;
      mq4 = false;
      mq6 = false;
      mq9 = false;
    break;
    case 3:
      mq2 = false;
      mq3 = false;
      mq4 = true;
      mq6 = false;
      mq9 = false;
    break;
    case 4:
      mq2 = false;
      mq3 = false;
      mq4 = false;
      mq6 = true;
      mq9 = false;
    break;
    case 5:
      mq2 = false;
      mq3 = false;
      mq4 = false;
      mq6 = false;
      mq9 = true;
    break;
  }
}

void adjustColor(int r, int g, int b){
  analogWrite(redPin, (255-r));
  analogWrite(greenPin, (255-g));
  analogWrite(bluePin, (255-b));
}
     


Schematics

project-image
Schematic - 65.1


project-image
Schematic - 65.2


project-image
Schematic - 65.3


project-image
Schematic - 65.4


project-image
Schematic - 65.5


project-image
Schematic - 65.6

Downloads

Gerber Files

Download


Fabrication Files

Download


gas.c

Download


lethal.c

Download


toxic.c

Download