Arduino articles 06- raise the temperature and humidity OLED display

OLED display temperature and humidity
Benpian DHT11 combined temperature and humidity sensor and the OLED, the collected temperature and humidity displayed on the OLED screen.

Part DHT11 use "DHT sensor library" described libraries, OLED use U8g2 library, the library installation please refer to the previous article describes.

1. Experimental Materials

  • Uno R3 Development Board
  • Supporting USB data cable
  • Bread plate and supporting cables
  • OLED display
  • DHT11 sensor module

2. Experimental Procedure

1. The schematic circuit diagram of a building.

VCC OLED screen and GND are connected to boards of 3.3V and GND, OLED screens are connected to the SDA and SCL boards A4 and A5. DHT11 module VCC, GND are connected to the development board 5V, GND, DATA pin is connected to digital block pin boards 2.

Principle is shown below:

FIG circuit connection

Physical connection is shown below:

Physical connection diagram

2. Create a new sketch, the following code replacement copies of the automatically generated code and save it.

#include <Arduino.h>
#include <U8g2lib.h>
#include <Wire.h>
#include "DHT.h"

#define DHTPIN  2
#define DHTTYPE DHT11

//iic驱动方式
U8G2_SSD1306_128X64_NONAME_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  u8g2.begin();
  dht.begin();
}

char h_str[3];
char t_str[3];
float h;
float t;

void loop() {

  h = dht.readHumidity();//读湿度
  t = dht.readTemperature();//读温度(摄氏度)
  strcpy(h_str, u8x8_u8toa(h, 2));    /* convert m to a string with two digits */
  strcpy(t_str, u8x8_u8toa(t, 2));    /* convert m to a string with two digits */

  u8g2.firstPage();
  do {
    u8g2.setFont(u8g2_font_fur20_tf);
    u8g2.drawStr(0, 23, "T");
    u8g2.drawStr(20, 23, ":");
    u8g2.drawStr(40, 23, t_str);
    u8g2.drawStr(90, 23, "C");

    u8g2.drawStr(0, 63, "H");
    u8g2.drawStr(20, 63, ":");
    u8g2.drawStr(40, 63, h_str);
    u8g2.drawStr(90, 63, "%");
  } while ( u8g2.nextPage() );
  delay(1000);
}

3. Development Board connector, and set the port number corresponding to the type of boards, for download.

Download

3. experimental results

OLED screen to refresh the display of temperature and humidity.

Experimental phenomena

Focus on micro-channel public number: TonyCode
the Arduino learning exchange group: 868 283 450

More, I welcome the attention of the public number. Sweep the micro-channel to follow the Fanger Wei code:
Micro channel scan code added public number: TonyCode

Published 63 original articles · won praise 250 · Views 230,000 +

Guess you like

Origin blog.csdn.net/TonyIOT/article/details/103117990