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

Arduino UNO Humidity-Based LED Indicator with DHT11 Sensor

View and Edit Project In Cirkit DesignerImage of Arduino UNO Humidity-Based LED Indicator with DHT11 Sensor

Circuit Documentation

Summary

This circuit is designed to read humidity levels using a DHT11 sensor and display the humidity level using four red LEDs. The LEDs are controlled by an Arduino UNO, which reads the humidity data from the DHT11 sensor and lights up a corresponding number of LEDs based on the humidity level.

Component List

LED: Two Pin (red)

DHT11 Humidity and Temperature Sensor

Arduino UNO

Resistor

Wiring Details

LED: Two Pin (red)

DHT11 Humidity and Temperature Sensor

Arduino UNO

Resistor

Code Documentation

#include <DHT.h>

#define DHTPIN A0
#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

const int ledPins[] = {2, 3, 4, 5};

void setup() {
    for (int i = 0; i < 4; i++) {
        pinMode(ledPins[i], OUTPUT);
    }
    dht.begin();
}

void loop() {
    float humidity = dht.readHumidity();
    int numLeds = map(humidity, 0, 100, 0, 4);

    for (int i = 0; i < 4; i++) {
        if (i < numLeds) {
            digitalWrite(ledPins[i], HIGH);
        } else {
            digitalWrite(ledPins[i], LOW);
        }
    }

    delay(2000);
}

This code initializes the DHT11 sensor and sets up the LED pins as outputs. In the main loop, it reads the humidity value from the DHT11 sensor and maps it to a number between 0 and 4. It then lights up the corresponding number of LEDs based on the humidity level. The loop runs every 2 seconds.