logo

MineGuard

Home Final Project About Me

Week 16 Documentation

System Integration

  • Packaging file download
  • Wowki page
  • Information on mq2 is from this source. DAC pins are analog output.

    The mq2 will need a 5v, gnd, and an analog output pin for my application. The 2 ESP32 pins that are analog output are GPIO 25 & 26 (info on pinout from here).

    Basic gas sensor code:

            
              #define MQ2pin 25 // or 26, either is fine
    
              float sensorValue;  //variable to store sensor value
              
              void setup() {
                Serial.begin(9600);  // sets the serial port to 9600
                Serial.println("MQ2 warming up!");
                delay(20000);  // allow the MQ2 to warm up
              }
              
              void loop() {
                sensorValue = analogRead(MQ2pin);  // read analog input pin 0
              
                Serial.print("Sensor Value: ");
                Serial.println(sensorValue);
              
                delay(2000);  // wait 2s for next reading
              }
            
          

    Basic buzzer code. All the buzzer needs is a random pin for power (any PWM pin, which means any pin except 34-39) and a GND pin.

            
              #define Buzzer 4 // (can be any except 34-39)
    
    void setup(){
        Serial.begin(115200);
        Serial.println("Hello Buzz!");
        pinMode(Buzzer, OUTPUT);
    }
    
    void loop(){
        delay(1000);
        digitalWrite(Buzzer, HIGH);
        delay(1000);
        digitalWrite(Buzzer, LOW);
    }
            
          

    Both code integrated to buzz when a high value is reached (for immediate danger):

            
              #define MQ2pin 25 // or 26, either is fine
    #define Buzzer 4 // can be any
    
    float sensorValue;  //variable to store sensor value
    int dangerValue = 800; // arbitrary
              
    void setup() {
        Serial.begin(9600);  // sets the serial port to 9600
        Serial.println("MQ2 warming up!");
        pinMode(Buzzer, OUTPUT);
        delay(20000);  // allow the MQ2 to warm up
    }
              
    void loop() {
        sensorValue = analogRead(MQ2pin);  // read analog input pin 0
              
        Serial.print("Sensor Value: ");
        Serial.println(sensorValue);
        if (sensorValue >= dangerValue ) {
          digitalWrite(Buzzer, HIGH); // buzzer on 
          delay(20000); // buzzer on for 20 s to allow the miner to react
        }
              
        delay(2000);  // wait 2s for next reading
    }
    
    
            
          

    Wowki wiring diagram:

    Schematic