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

Arduino UNO-Based Smart Home Monitoring System with Temperature, Humidity, Gas Detection, and Door Status Alert

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Smart Home Monitoring System with Temperature, Humidity, Gas Detection, and Door Status Alert

Circuit Documentation

Summary

This circuit is designed to monitor environmental conditions using various sensors and an Arduino UNO microcontroller. It includes an NTC thermistor for temperature measurement, a DHT11 sensor for humidity, an MQ-2 sensor for gas detection, and a reed switch for door status monitoring. The circuit also includes LEDs for visual indication and a buzzer for audible alerts. The Arduino UNO processes the sensor data and controls the LEDs and buzzer based on predefined thresholds.

Component List

  1. Analog Temperature Sensor (NTC) (Wokwi Compatible)

    • Pins: GND, VCC, OUT
    • Description: Measures temperature using a negative temperature coefficient thermistor.
  2. MQ-2

    • Pins: GND, VCC, ANALOG, Digital
    • Description: Gas sensor for detecting various gases including LPG, smoke, alcohol, propane, hydrogen, methane, and carbon monoxide.
  3. Door MC-38

    • Pins: S, GND
    • Description: Magnetic reed switch used for detecting door open/close status.
  4. LED: Two Pin (red)

    • Pins: cathode, anode
    • Description: Red LED for visual indication.
  5. Arduino UNO

    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
    • Description: Microcontroller board based on the ATmega328P.
  6. Buzzer

    • Pins: PIN, GND
    • Description: Buzzer for audible alerts.
  7. DHT11

    • Pins: DATA, GND, VCC
    • Description: Digital temperature and humidity sensor.

Wiring Details

Analog Temperature Sensor (NTC) (Wokwi Compatible)

MQ-2

Door MC-38

LED: Two Pin (red) (1)

LED: Two Pin (red) (2)

LED: Two Pin (red) (3)

Arduino UNO

Buzzer

DHT11

Documented Code

#include <DHT.h>
#include <math.h>
#include <SoftwareSerial.h>

SoftwareSerial espSerial(10, 11);

// NTC Thermistor setup
const int ntcPin = A0;
const int ntcLedPin = 13;
const float thresholdTemp = 25.0;
const float BETA = 3950;
const float ROOM_TEMP_RESISTANCE = 10000;
const float ROOM_TEMP = 298.15;

// DHT11 setup
#define DHTPIN A1
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
const int dhtLedPin = 3;
const float thresholdHumidity = 55.0;

// MQ2 Gas Sensor setup
const int mq2Pin = A2;
const int mq2LedPin = 6;
const int gasThreshold = 400;

// Reed Switch & Buzzer setup
const int reedPin = 7;
const int buzzerPin = 8;

// Function to read temperature from NTC thermistor
float readTemperature() {
    int adcValue = analogRead(ntcPin);
    float resistance = (1023.0 / adcValue - 1) * ROOM_TEMP_RESISTANCE;
    float temperatureKelvin = 1 / (1 / ROOM_TEMP + log(resistance / ROOM_TEMP_RESISTANCE) / BETA);
    return temperatureKelvin - 273.15;
}

void setup() {
    pinMode(ntcLedPin, OUTPUT);
    pinMode(dhtLedPin, OUTPUT);
    pinMode(mq2LedPin, OUTPUT);
    pinMode(reedPin, INPUT_PULLUP);
    pinMode(buzzerPin, OUTPUT);

    dht.begin();
    Serial.begin(9600);
    espSerial.begin(9600);
}

void loop() {
    // NTC Temperature check
    float temperature = readTemperature();
    Serial.print("Temperature: ");
    Serial.print(temperature);
    Serial.println(" °C");
    digitalWrite(ntcLedPin, temperature > thresholdTemp ? HIGH : LOW);

    // DHT11 Humidity check
    float humidity = dht.readHumidity();
    if (!isnan(humidity)) {
        Serial.print("Humidity: ");
        Serial.print(humidity);
        Serial.println(" %");
        digitalWrite(dhtLedPin, humidity > thresholdHumidity ? HIGH : LOW);
    } else {
        Serial.println("Failed to read from DHT sensor!");
    }

    // MQ2 Gas sensor check
    int gasLevel = analogRead(mq2Pin);
    Serial.print("Gas Level: ");
    Serial.println(gasLevel);
    digitalWrite(mq2LedPin, gasLevel > gasThreshold ? HIGH : LOW);

    // Reed Switch and Buzzer
    int reedState = digitalRead(reedPin);
    if (reedState == 1) { // Door is open
        tone(buzzerPin, 500); // Lower frequency
        Serial.println("Door is open! Buzzer ON.");
    } else {
        noTone(buzzerPin); // Turn off buzzer
        Serial.println("Door is closed. Buzzer OFF.");
    }
    espSerial.println();
    espSerial.print(temperature);
    espSerial.print(",");
    espSerial.print(humidity);
    espSerial.print(",");
    espSerial.print(gasLevel);
    espSerial.print(",");
    espSerial.print(reedState);
    espSerial.println();
    delay(1000); // Wait 1 second
}

This code initializes the sensors and components, reads data from the sensors, and controls the LEDs and buzzer based on the sensor readings. The data is also sent to a serial monitor and an external device via SoftwareSerial.