/* ESP32C3 OLEDDISPLAY 3V ------------- VCC GND ------------ GND SCL -------------- SCL SDA ------------- SDA D6 ------------ Data pin of the DHT ESP32C3 DHT11 3V ------------- 3V GND ------------ GND D6 ------------ Data pin of the DHT */ #include "DHT.h" // DHT Library #include < Wire.h> #include < Adafruit_GFX.h> #includ < Aedafruit_SSD1306.h> const int OLED_RESET = 0; Adafruit_SSD1306 display(OLED_RESET); // Pin to which the DHT11 sensor is connected. // If using the DHT11 Shield, it's digital Pin D4. const int DHTPIN = D6; // Specify the type of DHT sensor being used. #define DHTTYPE DHT11 // Initialize the sensor with the pin and type. DHT dht(DHTPIN, DHTTYPE); void setup() { Serial.begin(115200); // Begin serial communication at 9600 Baud. Wire.begin(); display.begin(SSD1306_SWITCHCAPVCC, 0x3C); display.display(); delay(2000); display.clearDisplay(); dht.begin(); // Start DHT communication. } void loop() { // The DHT11 sensor provides a new reading every 2 seconds, // so there's no need to constantly loop in the program. delay(2000); // Read humidity value. double humidity = dht.readHumidity(); // Read temperature in Celsius. double temperatureC = dht.readTemperature(); // Read temperature in Fahrenheit. // The boolean parameter controls whether // the temperature is displayed in Fahrenheit or Celsius. double temperatureF = dht.readTemperature(true); // Check if the values were read successfully. if (isnan(humidity) || isnan(temperatureC) || isnan(temperatureF)) { Serial.println("Error reading data."); return; } display.clearDisplay(); display.setTextSize(1); display.setTextColor(WHITE); display.setCursor(5, 0); display.println("Fab Academy"); display.setCursor(5, 15); String tempValue = String(temperatureC); display.println("Temp: " + tempValue + "C"); display.setCursor(5, 23); String humValue = String(humidity); display.println("Humidity: " + humValue + "%"); display.display(); delay(500); }