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

How to Implement Automatic Control with Arduino

Automatic control systems are integral to modern engineering, enabling devices to operate autonomously and efficiently. In the Arduino environment, automatic control can be implemented to manage various systems, such as temperature regulation, motor speed control, or lighting systems. This article will guide you through creating a simple automatic control system using an Arduino board.

Examples:

Let's consider a practical example of controlling the temperature of a room using an Arduino, a temperature sensor, and a fan. The goal is to maintain the room temperature within a specific range automatically.

Components Required:

  1. Arduino Uno
  2. DHT22 Temperature and Humidity Sensor
  3. Relay Module
  4. DC Fan
  5. Jumper Wires
  6. Breadboard

Step-by-Step Instructions:

  1. Set Up the Hardware:

    • Connect the DHT22 sensor to the Arduino:

      • VCC to 5V
      • GND to GND
      • Data Pin to Digital Pin 2
    • Connect the Relay Module to the Arduino:

      • VCC to 5V
      • GND to GND
      • IN to Digital Pin 8
    • Connect the DC Fan to the Relay Module.

  2. Install the Required Libraries:

    You need to install the DHT sensor library. You can do this via the Arduino IDE:

    • Go to Sketch > Include Library > Manage Libraries
    • Search for "DHT sensor library" and install it.
  3. Write the Arduino Code:

    #include <DHT.h>
    
    #define DHTPIN 2     // Digital pin connected to the DHT sensor
    #define DHTTYPE DHT22   // DHT 22 (AM2302)
    #define RELAY_PIN 8  // Pin where the relay is connected
    
    DHT dht(DHTPIN, DHTTYPE);
    
    void setup() {
     Serial.begin(9600);
     dht.begin();
     pinMode(RELAY_PIN, OUTPUT);
    }
    
    void loop() {
     float temperature = dht.readTemperature();
    
     if (isnan(temperature)) {
       Serial.println("Failed to read from DHT sensor!");
       return;
     }
    
     Serial.print("Temperature: ");
     Serial.print(temperature);
     Serial.println(" *C");
    
     // Automatic control logic
     if (temperature > 25.0) {
       digitalWrite(RELAY_PIN, HIGH); // Turn on the fan
       Serial.println("Fan ON");
     } else {
       digitalWrite(RELAY_PIN, LOW); // Turn off the fan
       Serial.println("Fan OFF");
     }
    
     delay(2000); // Wait a few seconds between readings
    }
  4. Upload the Code:

    • Connect your Arduino to your computer using a USB cable.
    • Open the Arduino IDE and select the correct board and port.
    • Upload the code to the Arduino.
  5. Test the System:

    • Once the code is uploaded, the system will automatically control the fan based on the room temperature. If the temperature exceeds 25°C, the fan will turn on. Otherwise, it will remain off.

This simple automatic control system demonstrates how Arduino can be used to create autonomous systems that respond to environmental changes.

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.