Skip to content

Instantly share code, notes, and snippets.

@hsinghao
Last active September 1, 2017 06:52
模組介紹 : faya溫濕度感應器
// 2017/7/27
// Faya-Nugget 範例程式 (DHT11_1.ino)
// 單元: 模組介紹:faya溫濕度感應模組
// 網址: https://fayalab.blogspot.com/2017/07/DHT11.html
// 目標: (1) LCD模組第一行顯示目前溫度
// (2) LCD模組第二行顯示目前濕度
// 接線: Arduino ==> faya模組
// A4 ==> SDA (串列LCD模組)
// A5 ==> SCL (串列LCD模組)
// 5 ==> Data(溫濕度感應模組)
#include <Wire.h> //I2C函式庫
#include <LiquidCrystal_I2C.h> //串列lcd函式庫
#include <dht.h> //dht11函式庫
//定義LCD的位址與參數
LiquidCrystal_I2C lcd(0x20,16,2); // LCD位址:0x20 ; LCD規格:16x2
//定義DHT11的腳位
#define _dhtpin 5 // 數位5腳接到DHT11
//建構物件名稱
dht faya_dht11;
int read_temp = 0; //溫度變數
int read_humd = 0; //濕度變數
void setup()
{
lcd.init(); // 初始化LCD
lcd.backlight(); // 啟動背光
}
void loop()
{
int chk = faya_dht11.read11(_dhtpin); // 讀取並儲存溫濕度資料
read_temp = faya_dht11.temperature; //取出溫度變數
read_humd = faya_dht11.humidity; //取出濕度變數
lcd.setCursor(0,0); //LCD游標位置 第1列第1行
lcd.print("Temp = "); // 秀溫度
lcd.print(read_temp);
lcd.print("\337C"); //溫度符號 \337
lcd.setCursor(0,1); //LCD游標位置 第2列第1行
lcd.print("Humidity = "); // 秀濕度
lcd.print(read_humd);
lcd.print("%"); //每2秒更新一次
delay(2000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment