What's new
Here's an example program code that should work with your setup. This program reads the humidity data from the sensor and displays it on the OLED display:

Code:
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>

#define DHTPIN 2     // Digital pin for DHT sensor
#define DHTTYPE DHT11  // DHT 11

DHT dht(DHTPIN, DHTTYPE);

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

void setup() {
  Serial.begin(9600);
  dht.begin();
  
  // Initialize display
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println("Humidity Sensor");

  display.display();
  delay(2000);
}

void loop() {
  delay(2000);
  float h = dht.readHumidity();
  
  // Display humidity on OLED screen
  display.clearDisplay();
  display.setCursor(0,0);
  display.println("Humidity: ");
  display.print(h);
  display.print("%");
  display.display();
}

You'll need to install the necessary libraries for this code to work. You can find instructions on how to do that in the library documentation.

This is just a simple example to get you started. Depending on what you want to do with the humidity data, you may need to modify the code to suit your needs.
 

Similar threads

Back
Top