๐Ÿ”’ 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
  • 394
    Views
  • 1
    Participants
Last reply from:
Unknown user

Online now

Members online
659
Guests online
4,614
Total visitors
5,273

Forum statistics

Threads
2,348,643
Posts
29,358,208
Members
1,094,612
Latest member
scubmonksb14
Back
Top