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

Arduino UNO-Based Environmental Monitoring System with Gas and Temperature Sensors

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Environmental Monitoring System with Gas and Temperature Sensors

Circuit Documentation

Summary

This circuit is designed to monitor environmental conditions using a Gas Sensor (MQ-5) and a DHT11 Humidity and Temperature Sensor. The data from these sensors is processed by an Arduino UNO, which controls a Servo motor based on the sensor readings. The system can detect high temperature, humidity, and gas levels, and respond by moving the servo motor.

Component List

Gas Sensor MQ-5

DHT11 Humidity and Temperature Sensor

Arduino UNO

Servo

Wiring Details

Gas Sensor MQ-5

DHT11 Humidity and Temperature Sensor

Arduino UNO

Servo

Code Documentation

#include <Servo.h>
#include <DHT.h>

// Define DHT11 settings
#define DHTPIN 2 // Digital pin for DHT11
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

// Define MQ-5 Gas Sensor pins
#define GAS_SENSOR_ANALOG_PIN A0
#define GAS_SENSOR_DIGITAL_PIN 3

// Servo settings
Servo myServo;
#define SERVO_PIN 9

// Thresholds
const float TEMP_THRESHOLD = 30.0; // Adjust as needed
const float HUMIDITY_THRESHOLD = 70.0; // Adjust as needed
const int GAS_THRESHOLD = 400; // Adjust based on analog gas sensor readings

void setup() {
  Serial.begin(9600);
  dht.begin();
  myServo.attach(SERVO_PIN);
  myServo.write(0); // Start at 0 degrees
  pinMode(GAS_SENSOR_DIGITAL_PIN, INPUT);
}

void loop() {
  // Read DHT11 values
  float temp = dht.readTemperature();
  float humidity = dht.readHumidity();

  // Check if temperature and humidity are high
  if (temp >= TEMP_THRESHOLD || humidity >= HUMIDITY_THRESHOLD) {
    Serial.println("High Temp/Humidity detected!");
    myServo.write(180); // Move servo to 180 degrees
  } else {
    myServo.write(0); // Reset servo
  }

  // Read analog gas sensor value
  int gasValue = analogRead(GAS_SENSOR_ANALOG_PIN);
  Serial.print("Gas Value (Analog): ");
  Serial.println(gasValue);

  // Check if analog gas concentration is high
  if (gasValue >= GAS_THRESHOLD) {
    Serial.println("High Gas Level detected (Analog)!");
    myServo.write(180); // Move servo to 180 degrees
  }

  // Read digital gas sensor value
  int gasDigital = digitalRead(GAS_SENSOR_DIGITAL_PIN);
  if (gasDigital == HIGH) {
    Serial.println("High Gas Level detected (Digital)!");
    myServo.write(180); // Move servo to 180 degrees
  }

  delay(1000); // Delay for stability
}

This code initializes the DHT11 sensor, MQ-5 gas sensor, and the servo motor. It continuously reads the temperature, humidity, and gas levels, and moves the servo motor to 180 degrees if any of the readings exceed their respective thresholds. The servo motor is reset to 0 degrees if the readings are below the thresholds.