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

Arduino UNO Controlled RGB LED and DHT11 Temperature Sensor Circuit

View and Edit Project In Cirkit DesignerImage of Arduino UNO Controlled RGB LED and DHT11 Temperature Sensor Circuit

Circuit Documentation

Summary

This circuit is designed to interface an RGB LED and a DHT11 temperature and humidity sensor with an Arduino UNO microcontroller. The Arduino UNO controls the RGB LED color based on the temperature readings from the DHT11 sensor. The circuit uses resistors to limit the current to the RGB LED. The DHT11 sensor provides the ambient temperature and humidity data to the Arduino, which then adjusts the color of the RGB LED accordingly.

Component List

Resistor

RGB LED

Arduino UNO

DHT11

Wiring Details

Resistor (220 Ohms)

RGB LED

Arduino UNO

DHT11

Documented Code

#include <DHT.h>

#define DHTPIN 2     // Digital pin connected to the DHT sensor
#define DHTTYPE DHT11   // DHT 11

DHT dht(DHTPIN, DHTTYPE);

#define RED_PIN 9
#define GREEN_PIN 10
#define BLUE_PIN 11

void setup() {
  Serial.begin(9600);
  dht.begin();
  pinMode(RED_PIN, OUTPUT);
  pinMode(GREEN_PIN, OUTPUT);
  pinMode(BLUE_PIN, OUTPUT);
}

void loop() {
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.println(" *C");

  // Change LED color based on the temperature
  if (t > 30) { // High temperature
    setColor(255, 0, 0); // Red
  } else if (t >= 20 && t <= 30) { // Moderate temperature
    setColor(0, 255, 0); // Green
  } else { // Low temperature
    setColor(255, 255, 0); // Yellow
  }

  delay(2000); // Wait for two seconds before the next reading
}

void setColor(int red, int green, int blue) {
  analogWrite(RED_PIN, red);
  analogWrite(GREEN_PIN, green);
  analogWrite(BLUE_PIN, blue);
}

The code initializes the DHT11 sensor and configures the RGB LED pins as outputs. In the main loop, it reads the temperature and humidity from the DHT11 sensor. Depending on the temperature value, it sets the RGB LED to red, green, or yellow. The setColor function uses PWM to set the color of the RGB LED.