Wemos OLED temperature project

This example will take the previous Wemos OLED shield example and make something slightly more useful with it. In this case we used a DHT11 shield and are going to display the temperature and humidity on the display.

Setup

This was a picture of my initial setup with the temperature and humidity displayed, as you can see the OLED shield is the top board, under is the DHT11 shield and at the bottom is the Wemos mini

wemos dht and oled

Code

Basically for a project like this you are taking a DHT11 example and merging with an OLED example

It requires the Adafruit library for the OLED display from https://github.com/mcauser/Adafruit_SSD1306 library and https://github.com/adafruit/DHT-sensor-library

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "DHT.h"
 
 
#define OLED_RESET 0  // GPIO0
Adafruit_SSD1306 display(OLED_RESET);
 
#define DHTPIN D4
#define DHTTYPE DHT11  
DHT dht(DHTPIN, DHTTYPE);
 
void setup()   
{
  Serial.begin(9600);
  dht.begin();
  // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 64x48)
  display.display();
}
 
 
void loop() 
{
  delay(2000);
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float f = dht.readTemperature(true);
  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) 
  {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  //temp in c
  display.println("temp");
  display.print(t);
  display.println(" c");
  display.println("humidity");
  display.print(h);
  display.println(" %");
  display.display();
 
}

 

Links
 
D1 Mini WeMos DHT11 Single Bus Digital Temperature Humidity Sensor Shield Module

2 COMMENTS

  1. why am i getting this error

    Archiving built core (caching) in: C:\Users\mshaz\AppData\Local\Temp\arduino_cache_12937\core\core_esp8266_esp8266_d1_mini_CpuFrequency_80,UploadSpeed_115200,FlashSize_4M3M_3cb4b9215516f03bedec8702387c2c80.a
    sketch\temp.ino.cpp.o:(.text.setup+0x10): undefined reference to `DHT::begin()’

    sketch\temp.ino.cpp.o: In function `HardwareSerial::begin(unsigned long)’:

    C:\Users\mshaz\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/HardwareSerial.h:75: undefined reference to `DHT::begin()’

    sketch\temp.ino.cpp.o:(.text.loop+0x14): undefined reference to `DHT::readHumidity(bool)’

    sketch\temp.ino.cpp.o:(.text.loop+0x18): undefined reference to `DHT::readTemperature(bool, bool)’

    sketch\temp.ino.cpp.o:(.text.loop+0x59): undefined reference to `DHT::readHumidity(bool)’

    sketch\temp.ino.cpp.o:(.text.loop+0x69): undefined reference to `DHT::readTemperature(bool, bool)’

    sketch\temp.ino.cpp.o: In function `loop’:

    C:\Users\mshaz\Documents\Arduino\temp/temp.ino:27: undefined reference to `DHT::readTemperature(bool, bool)’

    C:\Users\mshaz\Documents\Arduino\temp/temp.ino:38: undefined reference to `DHT::DHT(unsigned char, unsigned char, unsigned char)’

    sketch\temp.ino.cpp.o: In function `_GLOBAL__sub_I_display’:

    C:\Users\mshaz\Documents\Arduino\temp/temp.ino:44: undefined reference to `DHT::DHT(unsigned char, unsigned char, unsigned char)’

    collect2.exe: error: ld returned 1 exit status

    exit status 1
    Error compiling for board WeMos D1 R2 & mini.

    • I’ve seen a similar issue before, if memory serves me correct it was related to the importing of libraries. I manually put it the wrong place. So I’d double check that first and also import using the Sketch > Import Library method.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

*