🔒 Closed Program code

Status
Not open for further replies.
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.
 
Status
Not open for further replies.

About this Thread

  • 1
    Replies
  • 390
    Views
  • 1
    Participants
Last reply from:
Unknown user

Trending Topics

Online now

Members online
1,390
Guests online
3,534
Total visitors
4,924

Forum statistics

Threads
2,337,547
Posts
29,298,514
Members
1,127,603
Latest member
jdalaguan10
Back
Top