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

ESP32 and Arduino UNO Based Temperature-Responsive Servo Control

View and Edit Project In Cirkit DesignerImage of ESP32 and Arduino UNO Based Temperature-Responsive Servo Control

Circuit Documentation

Summary of the Circuit

This circuit integrates an Arduino UNO microcontroller with an ESP32 (30-pin variant), a DHT11 temperature and humidity sensor, and a servo motor. The Arduino UNO serves as the primary controller, interfacing with the DHT11 sensor to read environmental data and controlling the servo motor based on the temperature readings. The ESP32 is included in the circuit and may serve as a secondary controller or for wireless communication capabilities, although its specific role is not defined in the provided code. The DHT11 sensor provides temperature and humidity readings, and the servo motor is actuated based on the temperature data.

Component List

Arduino UNO

ESP32 (30 pin)

DHT11

Servo

Wiring Details

Arduino UNO

ESP32 (30 pin)

DHT11

Servo

Documented Code

Arduino UNO Code

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

// Define pins
#define DHTPIN 4       // GPIO pin connected to the DHT11 sensor
#define DHTTYPE DHT11  // DHT11 sensor type
#define SERVOPIN 5     // GPIO pin connected to the servo motor

// Initialize DHT sensor
DHT dht(DHTPIN, DHTTYPE);

// Initialize servo motor
Servo myservo;

void setup() {
  // Start serial communication
  Serial.begin(115200);

  // Initialize DHT sensor
  dht.begin();

  // Attach the servo motor to the servo pin
  myservo.attach(SERVOPIN);
}

void loop() {
  // Read temperature as Celsius
  float temperature = dht.readTemperature();

  // Read humidity
  float humidity = dht.readHumidity();

  // Check if any reads failed
  if (isnan(temperature) || isnan(humidity)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Print temperature and humidity to the Serial Monitor
  Serial.print("Temperature: ");
  Serial.print(temperature);
  Serial.print("°C  |  Humidity: ");
  Serial.print(humidity);
  Serial.println("%");

  // Example logic: Move the servo based on the temperature
  if (temperature > 30.0) {
    myservo.write(90);  // Move the servo to 90 degrees
    Serial.println("Servo moved to 90 degrees");
  } else {
    myservo.write(0);   // Move the servo to 0 degrees
    Serial.println("Servo moved to 0 degrees");
  }

  // Wait a few seconds between measurements
  delay(2000);
}

ESP32 Code

The provided code for the ESP32 is identical to the Arduino UNO code. This could indicate that the ESP32 is intended to perform the same functions as the Arduino UNO, or it may be a placeholder for future development. The actual implementation in the circuit should be verified, and the code should be adjusted to reflect the ESP32's specific role and pin assignments.

// The code for ESP32 is identical to the Arduino UNO code provided above.
// Please refer to the Arduino UNO code section.

Note: The actual pin definitions for the ESP32 should be verified as the code provided uses Arduino pin definitions. Adjustments may be necessary to match the ESP32's pinout.