Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

Monitoring Environmental Conditions with Arduino Environmental Sensors

Environmental sensors are crucial for monitoring various environmental parameters such as temperature, humidity, air quality, and more. These sensors provide valuable data for applications ranging from home automation to industrial monitoring and environmental research. Integrating these sensors with an Arduino microcontroller allows for real-time data collection and processing, making it accessible for hobbyists and professionals alike. This article will guide you through setting up a project to monitor environmental conditions using an Arduino and various sensors, providing practical code examples and a comprehensive list of required components.

Project: The goal of this project is to create an environmental monitoring system using an Arduino. The system will measure temperature, humidity, and air quality, displaying the data on an LCD screen. The project aims to demonstrate how to interface multiple sensors with an Arduino, process the sensor data, and present it in a user-friendly manner.

Components List:

  1. Arduino Uno (1)
  2. DHT22 Temperature and Humidity Sensor (1)
  3. MQ-135 Air Quality Sensor (1)
  4. 16x2 LCD Display with I2C Module (1)
  5. Breadboard (1)
  6. Jumper Wires (various)
  7. 10k Ohm Resistor (1)

Examples:

  1. Wiring the Components:

    • Connect the DHT22 sensor to the Arduino:
      • VCC to 5V
      • GND to GND
      • Data pin to digital pin 2
    • Connect the MQ-135 sensor to the Arduino:
      • VCC to 5V
      • GND to GND
      • Analog output to analog pin A0
    • Connect the 16x2 LCD with I2C to the Arduino:
      • SDA to A4
      • SCL to A5
      • VCC to 5V
      • GND to GND
  2. Arduino Code:

    // Include necessary libraries
    #include <Wire.h>
    #include <LiquidCrystal_I2C.h>
    #include <DHT.h>
    
    // Define constants and initialize objects
    #define DHTPIN 2
    #define DHTTYPE DHT22
    DHT dht(DHTPIN, DHTTYPE);
    LiquidCrystal_I2C lcd(0x27, 16, 2);
    
    void setup() {
     // Initialize the LCD
     lcd.begin();
     lcd.backlight();
     lcd.print("Initializing...");
    
     // Initialize the DHT sensor
     dht.begin();
    
     // Initialize serial communication
     Serial.begin(9600);
     lcd.clear();
    }
    
    void loop() {
     // Read temperature and humidity from DHT22
     float temperature = dht.readTemperature();
     float humidity = dht.readHumidity();
    
     // Read air quality from MQ-135
     int airQuality = analogRead(A0);
    
     // Check if any reads failed and exit early (to try again)
     if (isnan(temperature) || isnan(humidity)) {
       lcd.setCursor(0, 0);
       lcd.print("Sensor Error");
       return;
     }
    
     // Print values to the LCD
     lcd.setCursor(0, 0);
     lcd.print("Temp: ");
     lcd.print(temperature);
     lcd.print(" C");
    
     lcd.setCursor(0, 1);
     lcd.print("Hum: ");
     lcd.print(humidity);
     lcd.print(" %");
    
     delay(2000); // Wait for 2 seconds before updating
    
     lcd.clear();
     lcd.setCursor(0, 0);
     lcd.print("Air Quality: ");
     lcd.print(airQuality);
    
     delay(2000); // Wait for 2 seconds before updating
    
     lcd.clear();
    }

    Explanation of the Code:

    • The #include directives import necessary libraries for the LCD display and DHT sensor.
    • Constants and objects are defined to interface with the sensors and LCD.
    • The setup function initializes the LCD, DHT sensor, and serial communication.
    • The loop function reads data from the sensors, checks for errors, and displays the data on the LCD.

    Common Challenges:

    • Ensure all connections are secure and correct.
    • Verify the correct I2C address for the LCD module.
    • Handle potential sensor read errors gracefully.

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.