/*
* This ESP32 code is created by esp32io.com
*
* This ESP32 code is released in the public domain
*
* For more detail (instruction and wiring diagram), visit https://esp32io.com/tutorials/esp32-dht11
*/
#include <DHT.h>
#define DHT11_PIN 21 // ESP32 pin GPIO21 connected to DHT11 sensor
DHT dht11(DHT11_PIN, DHT22);
#include <FastLED.h>
#define NUM_LEDS 5
#define DATA_PIN 22
#define CLOCK_PIN 13
CRGB leds[NUM_LEDS];
void setup() {
Serial.begin(9600);
dht11.begin(); // initialize the DHT11 sensor
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
}
void loop() {
// read humidity
float humi = dht11.readHumidity();
// read temperature in Celsius
float tempC = dht11.readTemperature();
// read temperature in Fahrenheit
float tempF = dht11.readTemperature(true);
// check whether the reading is successful or not
if ( isnan(tempC) || isnan(tempF) || isnan(humi)) {
Serial.println("Failed to read from DHT11 sensor!");
} else {
Serial.print("Humidity: ");
Serial.print(humi);
Serial.print("%");
Serial.print(" | ");
Serial.print("Temperature: ");
Serial.print(tempC);
Serial.print("°C ~ ");
Serial.print(tempF);
Serial.println("°F");
}
// wait a 2 seconds between readings
delay(2000);
// Turn the LED on, then pause
leds[0] = CRGB::Red;
FastLED.show();
delay(500);
// Now turn the LED off, then pause
leds[0] = CRGB::Black;
FastLED.show();
delay(500);
// Turn the LED on, then pause
leds[1] = CRGB(241, 237, 12);
FastLED.show();
delay(500);
// Now turn the LED off, then pause
leds[1] = CRGB::Black;
FastLED.show();
delay(500);
// Turn the LED on, then pause
leds[2] = CRGB(10, 233, 95);
FastLED.show();
delay(500);
// Now turn the LED off, then pause
leds[2] = CRGB::Black;
FastLED.show();
delay(500);
// Move a single white led
for(int whiteLed = 0; whiteLed < NUM_LEDS; whiteLed = whiteLed + 1) {
// Turn our current led on to white, then show the leds
leds[whiteLed] = CRGB::White;
// Show the leds (only one of which is set to white, from above)
FastLED.show();
// Wait a little bit
delay(100);
// Turn our current led back to black for the next loop around
leds[whiteLed] = CRGB::Black;
}
FPS: 0
Power: 0.00W
Power: 0.00W