请选择 进入手机版 | 继续访问电脑版

基于arduino的温湿度显示器(DHT11,oled屏幕,7针spi接口)

[复制链接]
西门听雨 发表于 2020-12-31 20:29:46 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
基于arduino的温湿度显示器



一、准备

1、硬件准备

arduino uno开辟板

(此图片来自于网络)
  DHT 11温湿度传感器

(此图片来自于网络)
  OLED 屏幕(7针脚)

(此图片来自于网络)
2、软件准备

安装DHT库和u8glib库
3、位图准备

1、将图片转为bmp格式。

这里已经准备好了
2、打开PCtolcd2002

3、点击“选项”举行如下设置

4、打开图片

5、取模

6、复制
  1. const static unsigned char  logo0_glcd_bmp [] U8G_PROGMEM ={ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0xFF,0x80,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xE0,0x7E,0x00,0x0E,0x80,0x81,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x31,0xFE,0x00,0x04,0x80,0x81,0x00,0x40,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x02,0x13,0x82,0x00,0x00,0xFF,0x81,0x10,0x40,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x03,0x37,0x00,0x00,0x20,0x80,0x81,0x10,0x44,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x01,0xE6,0x00,0x00,0x10,0x80,0x81,0x7F,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x08,0xFF,0x81,0x10,0x44,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,0x01,0x10,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x10,0x00,0x01,0x1F,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x09,0xFF,0x81,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x09,0x24,0x81,0x7F,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x11,0x24,0x81,0x10,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x00,0x00,0x11,0x24,0x82,0x08,0x80,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0x11,0x24,0x82,0x07,0x00,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x82,0x00,0x21,0x24,0x82,0x0F,0x80,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xFE,0x00,0x23,0xFF,0xC6,0xF8,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0x00,0x10,0x00,0x02,0x40,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0xFF,0x80,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x80,0x81,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x03,0x00,0x08,0x80,0x81,0x00,0x40,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x0D,0x82,0x00,0x00,0xFF,0x81,0x10,0x40,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0xC4,0x00,0x20,0x80,0x81,0x10,0x44,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0xCC,0x00,0x70,0x80,0x81,0x7F,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0xC8,0x00,0x18,0xFF,0x81,0x10,0x44,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0xD8,0x00,0x00,0x24,0x01,0x10,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x93,0x80,0x00,0x24,0x41,0x1F,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D,0xB6,0xC0,0x0D,0x24,0x41,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x2C,0x60,0x09,0x24,0x81,0x7F,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6C,0x60,0x09,0x25,0x81,0x10,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x4C,0x60,0x10,0xA4,0x02,0x08,0x80,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x8C,0x60,0x10,0x24,0x02,0x07,0x00,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x8C,0x60,0x10,0x24,0x22,0x0F,0x80,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0xC0,0x23,0xFF,0xC6,0xF8,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x03,0x80,0x10,0x00,0x22,0x40,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};   //位图                                                                  
复制代码
二、连线

OLED屏幕
OLED屏幕针脚开辟板针脚GNDGNDVCC5/3.3VD03D14RES5DC6CS7DHT 11
  DHT 11Column 2VCC5/3.3VGNDGNDDAT8四、代码

  1. #include                           //引入头文件#include                             //引入头文件#include                          //引入Oled头文件U8GLIB_SSD1306_128X64 u8g(3,4,7,6,5);       //设置oled接口#define DHTPIN 8                            //湿度传感器OUT接8号口#define DHTTYPE DHT11                       //界说DHT11传感器DHT dht(DHTPIN, DHTTYPE);                   //界说湿度传感器OUT与8号口连接并且读取温湿度传感器的数值void setup(){  Serial.begin(9600);                       //串口波特率  dht.begin();                              //温湿度传感器初始化}const static unsigned char  logo0_glcd_bmp [] U8G_PROGMEM ={ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0xFF,0x80,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xE0,0x7E,0x00,0x0E,0x80,0x81,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x31,0xFE,0x00,0x04,0x80,0x81,0x00,0x40,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x02,0x13,0x82,0x00,0x00,0xFF,0x81,0x10,0x40,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x03,0x37,0x00,0x00,0x20,0x80,0x81,0x10,0x44,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x01,0xE6,0x00,0x00,0x10,0x80,0x81,0x7F,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x08,0xFF,0x81,0x10,0x44,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,0x01,0x10,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x10,0x00,0x01,0x1F,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x09,0xFF,0x81,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x09,0x24,0x81,0x7F,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x11,0x24,0x81,0x10,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x00,0x00,0x11,0x24,0x82,0x08,0x80,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0x11,0x24,0x82,0x07,0x00,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x82,0x00,0x21,0x24,0x82,0x0F,0x80,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xFE,0x00,0x23,0xFF,0xC6,0xF8,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0x00,0x10,0x00,0x02,0x40,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0xFF,0x80,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x80,0x81,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x03,0x00,0x08,0x80,0x81,0x00,0x40,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x0D,0x82,0x00,0x00,0xFF,0x81,0x10,0x40,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0xC4,0x00,0x20,0x80,0x81,0x10,0x44,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0xCC,0x00,0x70,0x80,0x81,0x7F,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0xC8,0x00,0x18,0xFF,0x81,0x10,0x44,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0xD8,0x00,0x00,0x24,0x01,0x10,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x93,0x80,0x00,0x24,0x41,0x1F,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D,0xB6,0xC0,0x0D,0x24,0x41,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x2C,0x60,0x09,0x24,0x81,0x7F,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6C,0x60,0x09,0x25,0x81,0x10,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x4C,0x60,0x10,0xA4,0x02,0x08,0x80,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x8C,0x60,0x10,0x24,0x02,0x07,0x00,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x8C,0x60,0x10,0x24,0x22,0x0F,0x80,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0xC0,0x23,0xFF,0xC6,0xF8,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x03,0x80,0x10,0x00,0x22,0x40,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};                                                                              //位图void dis_play()                            //OLED数据显示子函数{ float h = dht.readHumidity();    float t = dht.readTemperature();  u8g.firstPage();                         //  OLED首页  do  {          char c[1];    dtostrf(t,2,1,c);    Serial.println(c);                     //转换数据范例    u8g.setFont(u8g_font_gdr10r);          //设置字体    u8g.drawStr(60, 17, c);                //第17行60列显示温度数据    char k[1];     dtostrf(h,2,1,k);    Serial.println(k);                      //转换数据范例    u8g.setFont(u8g_font_gdr10r);           //设置字体    u8g.drawStr(60, 55,k);                  //第55行60列显示湿度数据    u8g.drawBitmapP(0,0,16,64,logo0_glcd_bmp);//显示位图  }   while (u8g.nextPage());                    //执行配置}void loop(){   dis_play();                                //oled显示数据子函数}
复制代码
五、制品

外壳为3D打印


来源:https://blog.csdn.net/m0_52433574/article/details/111937151
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则


专注素材教程免费分享
全国免费热线电话

18768367769

周一至周日9:00-23:00

反馈建议

27428564@qq.com 在线QQ咨询

扫描二维码关注我们

Powered by Discuz! X3.4© 2001-2013 Comsenz Inc.( 蜀ICP备2021001884号-1 )