Automated Toxic Fume Recirculator

Good day everyone, I tried making an Automated Toxic Fume Recirculator, but there is a problem with it; when i set the toxic fume level to 500 it supposedly automaticaly turn on and vacuum the fumes, but it turns out the opposite way, it automatically start at 500. When i try to blow air on the MQ2 the toxic fume level decreases, here is my sketch that ive made. Can you guys help pls :< SOS

Sketch:

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// I2C pins declaration
LiquidCrystal_I2C lcd(0x27, 16, 2); // 0x27 is the I2C address, 16 columns, and 2 rows

// Relay pin declaration
const int relayPin = 7;  // Set the pin number for the relay (change this if necessary)

// MQ-2 sensor pin declaration (Analog input)
const int mq2Pin = A0;  // MQ-2 analog output connected to A0

void setup() 
{
   Serial.begin(115200);
   lcd.begin(16, 2);  // Define LCD size
   lcd.backlight();   // Turn on the backlight

   lcd.setCursor(0, 0); 
   lcd.print("FUME TOXIN");
   lcd.setCursor(0, 1);
   lcd.print("Please wait. . . . ");
   delay(5000); 
   lcd.clear();  // Clear the LCD screen

   pinMode(relayPin, OUTPUT);  // Set relay pin as an output
   digitalWrite(relayPin, HIGH);  // Make sure the relay is off initially

   // Optionally, you can add initialization for the MQ-2 sensor if needed
}

void loop() 
{
    int mq2Value = analogRead(mq2Pin);  // Read the analog value from MQ-2 sensor (0-1023)
    
    // Convert the raw value to a meaningful range if needed (e.g., 0-100 or other)
    float voltage = mq2Value * (5.0 / 1023.0);  // Convert the analog value to voltage (0 to 5V)
    
    // Output the sensor value and voltage to the serial monitor (for debugging)
    Serial.print("MQ2 Raw Value: ");
    Serial.print(mq2Value);
    Serial.print("\t Voltage: ");
    Serial.println(voltage, 3);
    
    // Display the reading on the LCD screen
    lcd.setCursor(0, 0);
    lcd.print("Fume Level: ");
    lcd.print(mq2Value);  // Display raw value of MQ-2 sensor

    

    // If the fume level exceeds a certain threshold, turn on the relay (e.g., for an alarm)
    int threshold = 500;  // Adjust the threshold value based on your testing
    
    if (mq2Value > threshold) {
        digitalWrite(relayPin, LOW);  // Trigger relay (turn on alarm or fan, etc.)
        lcd.setCursor(0, 1);
        lcd.print("lcd.print(mq2Value);  // Display raw value of MQ-2 sensorF``umes detected");
    } else {
        digitalWrite(relayPin, HIGH);  // Turn off relay if no fumes are detected
    }
    
    delay(200);  // Delay to prevent flickering
}

Schematic Diagram:

1 Like

Maybe swapping the wire from NO to NC on the relay module will solve the issue?


Your topic does not indicate a problem with IDE 1.x and therefore has been moved to a more suitable location on the forum.

i tried swapping it, but the lcd is not showing indications anymore.

You shouldn't power arduino at 5V to VIN.
If you use 5V power source you need to wire it to 5V pin.
For VIN you need at least 7V.

Wouldn't you want to exhaust toxic fumes instead of recirculating them?

1 Like

I see several problems, here are a few. The relay coil should not be connected to the fan.

Vin requires at least 7 volts to be stable.

Your 12V can power the arduino via Vin and also the fan through the relay contacts. The relay requires a isolation from the Arduino pins. Many relays are available that have transistors to to the isolation. Even if the Arduino port has enough power the inductive kick back from the relay coil will fry it. You can buy relay modules that have the driver already mounted along with the relay and an opto coupler.

Your display will only light up at best it is missing several connections. This may help with the relay:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.