当前位置:网站首页>4. esp8266 displays DHT11 temperature and humidity parameters in real time through OLED
4. esp8266 displays DHT11 temperature and humidity parameters in real time through OLED
2022-06-21 22:57:00 【Zhang San programming sharing】
List of articles
Hardware environment
1、ESP8266 Development board

2、OLED display
This screen is displayed by I2C Control by , A resolution of 128*65, The driver chip is SSD1306 0.96 Inch .
Pins are defined as follows :
| Pin number | Definition | describe |
|---|---|---|
| 1 | GND | Access the development board GND |
| 2 | VDD | Access the development board VCC(3.3V–5V) |
| 3 | SCK(SCL) | Access the development board I2C Of SCL |
| 4 | SDA | Access the development board I2C Of SDA |
3、DHT11 Temperature and humidity sensor
DHT11 It is a temperature and humidity sensor , Can pass 2 Foot's Singal(out) Transmit the detected ambient temperature to in real time ESP8266.
Pins are defined as follows :
| Pin number | Definition | describe |
|---|---|---|
| 1 | VCC | Access the development board VCC(3.3V) |
| 2 | Singal(out) | Access the development board D5(GPIO14) |
| 3 | NC | It's empty |
| 4 | GND | Access the development board GND |
4、 Wiring way
fritzing Sketch Map :

Connection physical drawing :
Software environment
1、 Online installation DHT sensor library for ESPx
Click on Tools --> Management of the library Search for DHT11, Choose to install DHT sensor library for ESPx.
2、 Experiment source code
/************************************************************************************** ESP8266 NodeMCU interfacing with SSD1306 OLED and DHT11 sensor This is a free software with NO WARRANTY. http://simple-circuit.com/ ***************************************************************************************/
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <DHT.h> // Include DHT library code
#define OLED_RESET 5 // define SSD1306 OLED reset at ESP8266 GPIO5 (NodeMCU D1)
Adafruit_SSD1306 display(OLED_RESET);
#define DHTPIN 14 // DHT11 data pin is connected to ESP8266 GPIO14 (NodeMCU D5)
#define DHTTYPE DHT11 // DHT11 sensor is used
DHT dht(DHTPIN, DHTTYPE); // Configure DHT library
char temperature[] = "00.0 C";
char humidity[] = "00.0 %";
void setup(void)
{
Serial.begin(9600);
delay(1000);
Wire.begin(4, 0); // set I2C pins [SDA = GPIO4 (D2), SCL = GPIO0 (D3)], default clock is 100kHz
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
display.begin(SSD1306_SWITCHCAPVCC, 0x3D); // initialize with the I2C addr 0x3D (for the 128x64)
// init done
dht.begin(); // Initialize the DHT library
// Clear the display buffer.
display.clearDisplay();
display.drawFastHLine(0, 32, SSD1306_LCDWIDTH, WHITE);
display.setTextSize(1);
display.setTextColor(WHITE, BLACK);
display.setCursor(10, 5);
display.print("DHT11 TEMPERATURE:");
display.setCursor(19, 37);
display.print("DHT11 HUMIDITY:");
display.display();
}
void loop()
{
// Read humidity
byte RH = dht.readHumidity();
//Read temperature in degree Celsius
byte Temp = dht.readTemperature();
temperature[0] = Temp / 10 + '0';
temperature[1] = Temp % 10 + '0';
humidity[0] = RH / 10 + '0';
humidity[1] = RH % 10 + '0';
// print data on serial monitor
Serial.printf("Temperature = %02u°C\r\n", Temp);
Serial.printf("Humidity = %02u %%\r\n\r\n", RH);
// print data on the SSD1306 display
display.setCursor(46, 20);
display.print(temperature);
display.setCursor(46, 52);
display.print(humidity);
display.drawRect(71, 20, 3, 3, WHITE); // Put degree symbol ( ° )
display.display();
delay(1000);
}
Temperature and humidity display experiment
Effect display video
ESP8266 Development version passed OLED real-time display DHT11 Temperature and humidity parameters
边栏推荐
- WPF tablet
- Uwp tablet inkcanvas
- 分布式数据库使用逻辑卷管理存储之扩容
- Fedora 36 compiling and installing opencv 4.6.0 -- the road to building a dream
- Analysis of 43 cases of MATLAB neural network: Chapter 19 handwritten font recognition based on SVM
- Resolve the invalidation of OpenCV code prompt in pycharm
- 深入浅出讲解 JS 的微任务与宏任务
- C WindowFromPoint is invalid in 64 bit programs
- Explain JS micro task and macro task in simple terms
- 微信小程序获取网络状态
猜你喜欢

Readjustment of move protocol beta to expand the total prize pool

并查集练习题1:朋友圈

UWP 阴影效果

Better manage all kinds of music, professional DJ music management software pioneer DJ rekordbox

STM32 cannot download the program again after downloading it once, and the program cannot run.

软件测试 答疑篇

uniapp微信授权之 有个别用户 无法正常授权

WPF 依赖属性

Electronic bidding procurement mall system: optimize traditional procurement business and speed up enterprise digital upgrading

If you spend 200W to buy traffic, it is better to start at 0 cost and make an independent station with high private domain operation income!
随机推荐
Buckle 75: color split
If you spend 200W to buy traffic, it is better to start at 0 cost and make an independent station with high private domain operation income!
Migration of stm32f407 program to stm32f429
Speech breakpoint detection (short time improved subband spectral entropy)
《MATLAB 神经网络43个案例分析》:第19章 基于SVM的手写字体识别
mvn deploy多个模块的bat文件
WPF 路由
必讀書籍
大佬们, 2.2.1 的 StarRocks 主键模型的部分字段更新依旧不支持 sql 的方式是么?
Better manage all kinds of music, professional DJ music management software pioneer DJ rekordbox
WSL 2 的安装过程(以及介绍)
Pychart can run normally, and pyinstaller package software reports fatal error
多进程和多线程的概念
电脑屏幕分辨率怎么调?电脑屏幕修改分辨率SwitchResX
pyenv安装anaconda修改清华源
项目流程管理工具OmniPlan Pro 4
个人的股票交易经验
牛客月賽-環上食蟲
postgis 如何用米制单位 buffer
【电子方案设计】酒精测试仪PCBA解决方案