Arduino Libraries

when you use the "#include" before the void setup is that library you list automatically added? because when i used #include<Adafruit_SSD1306.h> and #include <Adafruit_GFX.h> there is no issue but when i used #include <DHT.h> it says there is no directory for it. what did I do wrong?

#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <DHT.h>

#define DHTPIN 2
#define DHTTYPE DHT11

#define SREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define SCREEN_I2C_ADDRESS 0x3c
#define OLED_RESET_PIN -1

DHT dht(DHTPIN, DHTTYPE);
Adafruit_SSD1306 screen(SREEN_WIDTH, SCREEN_HEIGHT, &Wire,OLED_RESET_PIN);

void setup() {
  dht.begin();
  screen.begin(SSD1306_SWITCHCAPVCC, SCREEN_I2C_ADDRESS);
}

void loop() {
  delay(2000);
  float t = dht.readTemperature();
  float n = dht.readHumidity();

screen.clearDisplay();
  screen.setTextSize(1);
  screen.setTextColor(WHITE);
  screen.setCursor(0,0);
  screen.print("Temperature:");

  screen.setCursor(0, 35);
  screen.print("Humidity:");

  if(isnan(h) || isnan(t)){
    screen.setCursor(0, 32);
    screen.print("Failed to read from DHT sensor!");
    screen.dsiplay();
    return;
  }
  screen.setCursor(0, 12);
  screen.setTextSize(2);
  screen.print(t);
  screen.print((char)247);
  screen.display("C");

  screen.setCursor(0, 47);
  screen.print(h);
  screen.print(" %");

  screen.display();
}

i'm currently following a humidity sensor oled display tutorial and i've gotten stuck,
thanks in advance

You have to install the library first, using the Library Manager in the Tools menu is the usual procedure.

It means that you have a Adafruit_SSD1306.h and Adafruit_GFX.h on your PC, but not a DHT.h library. You have to install it first. See the tutorial
https://docs.arduino.cc/software/ide-v1/tutorials/installing-libraries/

Just ensure it is in the same folder as all the other libraries. It really is that simple, BUT then restart the IDE so that it can find the new library.

  • When using library manager in the IDE, that is not necessary.
  • When adding a ZIP using the IDE, that is not necessary.
  • It might be necessary if you unzip a zipped library and manually move it to the libraries directory. I'm too lazy to test :wink:

The sketch compilation system can find it even without a restart. However, the manually installed library's entries in the File > Examples and Sketch > Include Library menus won't be populated until after restart.

1 Like

Thanks for the help guys, that (https://docs.arduino.cc/software/ide-v1/tutorials/installing-libraries/) tutorial explains what I need

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.