Saturday, October 13, 2018

Arduino : Intermediate - OLED I2C with DHT11 Temperature Sensor

Description
Demonstrates the use of 128x64 I2C OLED display and DHT 11 Temperature Sensor. You can download OLED I2C and DHT 11 library at Rinky-Dink Electronic and Adafruit DHT sensor library.

List Item
  1. Arduino Uno 
  2. 128x64 I2C OLED
  3. DHT 11 Sensor
  4. Wire Jumper

Wiring Diagram


Video

Coding

  #include <OLED_I2C.h>
  #include "DHT.h"

  #define DHTPIN 2
  #define DHTTYPE DHT11


  OLED  myOLED(SDA, SCL, 8);
  DHT dht(DHTPIN, DHTTYPE);

  extern uint8_t SmallFont[];
  extern uint8_t MediumNumbers[];


  void setup()
  {
    myOLED.begin();      //Initialize the display and screen buffer
    dht.begin();
  }

  void loop()
  {
    delay(500);
    float h = dht.readHumidity();
    float t = dht.readTemperature();
    float f = dht.readTemperature(true);
    float hif = dht.computeHeatIndex(f, h);
    float hic = dht.computeHeatIndex(t, h, false);
 
    myOLED.clrScr();                       // clear the screen buffer
    myOLED.setFont(SmallFont);
    myOLED.print("Humidity %", CENTER, 0); // print a string at the specified coordinate in the screen buffer
    myOLED.setFont(MediumNumbers);
    myOLED.printNumF(h,0, CENTER, 35);
    myOLED.update();                       // send to screen buffer 

    delay (1000);
    myOLED.clrScr();                       // clear the screen buffer
    myOLED.setFont(SmallFont);
    myOLED.print("Temperature *C", CENTER, 0); // print a string at the specified coordinate in the screen buffer
    myOLED.setFont(MediumNumbers);
    myOLED.printNumF(t,0, CENTER, 35);
    myOLED.update();                       // send to screen buffer 

    delay (1000);
    myOLED.clrScr();                       // clear the screen buffer
    myOLED.setFont(SmallFont);
    myOLED.print("Temperature *F", CENTER, 0); // print a string at the specified coordinate in the screen buffer
    myOLED.setFont(MediumNumbers);
    myOLED.printNumF(f,0, CENTER, 35);
    myOLED.update();                       // send to screen buffer

    delay (1000);
    myOLED.clrScr();                       // clear the screen buffer
    myOLED.setFont(SmallFont);
    myOLED.print("Heat Index *C", CENTER, 0); // print a string at the specified coordinate in the screen buffer
    myOLED.setFont(MediumNumbers);
    myOLED.printNumF(hic,0, CENTER, 35);
    myOLED.update();                       // send to screen buffer

    delay (1000);
    myOLED.clrScr();                       // clear the screen buffer
    myOLED.setFont(SmallFont);
    myOLED.print("Heat Index *F", CENTER, 0); // print a string at the specified coordinate in the screen buffer
    myOLED.setFont(MediumNumbers);
    myOLED.printNumF(hif,0, CENTER, 35);
    myOLED.update();                       // send to screen buffer


  }

No comments:

Post a Comment