Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino Nano Gas and Temperature Monitoring System with Buzzer and LED Alerts

View and Edit Project In Cirkit DesignerImage of Arduino Nano Gas and Temperature Monitoring System with Buzzer and LED Alerts

Circuit Documentation

Summary

This circuit is designed to monitor gas levels, temperature, and humidity using an MQ-2 gas sensor and a DHT11 humidity and temperature sensor. The circuit includes an Arduino Nano microcontroller, a red LED, a buzzer, and a resistor. The system triggers the buzzer and LED when gas levels, temperature, or humidity exceed predefined thresholds.

Component List

  1. LED: Two Pin (red)

    • Pins: Cathode, Anode
    • Description: A red LED used to indicate when thresholds are exceeded.
  2. Arduino Nano

    • Pins: D1/TX, D0/RX, RESET, GND, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11/MOSI, D12/MISO, VIN, 5V, A7, A6, A5, A4, A3, A2, A1, A0, AREF, 3V3, D13/SCK
    • Description: The main microcontroller used to read sensor data and control the LED and buzzer.
  3. MQ-2

    • Pins: GND, VCC, ANALOG, Digital
    • Description: A gas sensor used to detect gas levels.
  4. DHT11 Humidity and Temperature Sensor

    • Pins: VDD, DATA, NULL, GND
    • Description: A sensor used to measure humidity and temperature.
  5. Buzzer

    • Pins: PIN, GND
    • Description: A buzzer used to provide an audible alert when thresholds are exceeded.
  6. Resistor

    • Pins: Pin1, Pin2
    • Description: A 220 Ohm resistor used to limit current to the LED.
    • Properties:
      • Resistance: 220 Ohms

Wiring Details

LED: Two Pin (red)

Arduino Nano

MQ-2

DHT11 Humidity and Temperature Sensor

Buzzer

Resistor

Documented Code

Arduino Nano Code

#include <DHT.h>

#define GAS_SENSOR_PIN A0
#define BUZZER_PIN 9
#define LED_PIN 8
#define DHT_PIN 7           // DHT sensor connected to pin 7
#define GAS_THRESHOLD 400    // Gas threshold value
#define TEMP_THRESHOLD 45.0  // Temperature threshold in Celsius (example)
#define HUMIDITY_THRESHOLD 80.0  // Humidity threshold in percentage

// Initialize DHT sensor
DHT dht(DHT_PIN, DHT11);  // DHT11 sensor type

void setup() {
  pinMode(GAS_SENSOR_PIN, INPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(LED_PIN, OUTPUT);
  Serial.begin(9600);
  
  // Initialize DHT sensor
  dht.begin();
}

void loop() {
  // Read gas level from MQ-2 sensor
  int gasLevel = analogRead(GAS_SENSOR_PIN);

  // Read temperature and humidity from DHT11 sensor
  float humidity = dht.readHumidity();
  float temperature = dht.readTemperature();  // Temperature in Celsius

  // Check if readings are valid
  if (isnan(humidity) || isnan(temperature)) {
    Serial.println("Failed to read from DHT sensor!");
    return;  // Stop if there's an error in reading from the sensor
  }

  // Print sensor readings to Serial Monitor
  Serial.print("Gas Level: ");
  Serial.println(gasLevel);
  Serial.print("Temperature: ");
  Serial.print(temperature);
  Serial.print(" °C, Humidity: ");
  Serial.print(humidity);
  Serial.println(" %");

  // Check if gas level exceeds threshold
  if (gasLevel > GAS_THRESHOLD || temperature > TEMP_THRESHOLD || humidity > HUMIDITY_THRESHOLD) {
    Serial.println("Gas or temperature/humidity threshold exceeded! Triggering buzzer and LED...");
    tone(BUZZER_PIN, 1000);  // Trigger buzzer with 1kHz tone
    digitalWrite(LED_PIN, HIGH);  // Turn on LED
  } else {
    noTone(BUZZER_PIN);  // Turn off buzzer
    digitalWrite(LED_PIN, LOW);  // Turn off LED
  }

  delay(500);  // Delay to make readings easier to observe
}

Additional Code for Arduino Nano

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

This documentation provides a comprehensive overview of the circuit, including a summary, detailed component list, wiring details, and the code used in the microcontroller.