Arduino學習入門
  • Introduction
  • 基本介紹
    • 簡介
    • 0.相關名詞
    • 1.準備工作
    • 2.開發流程
    • 3.認識 I/O接腳
    • 4.上傳程式
    • 5.程式碼解說
    • 6.常用指令介紹
    • 7.線上學習資源
  • 程式實作
    • 1.液晶螢幕顯示溫濕度
    • 2.藍芽APP之RGB燈泡控制
Powered by GitBook
On this page

Was this helpful?

  1. 程式實作

1.液晶螢幕顯示溫濕度

本實驗使用Arduino Nano*1,液晶螢幕*1,溫濕度感測器*1

功能:透過感測器,將溫濕度數值顯示在液晶螢幕中

#include <LiquidCrystal_I2C_AvrI2C.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C_AvrI2C lcd(0x27, 16, 2);
#include <dht.h>
#define dht_dpin 3 //定義訊號要從Pin D3 進來
dht DHT;
byte easy [8] = {
B00000,
B01010,
B11111,
B11111,
B01110,
B00100,
B00000,
};
void setup() {
lcd.begin();
lcd.backlight();
delay(250);
lcd.noBacklight(); // 關閉背光
delay(250);
lcd.backlight();
delay(250);
lcd.noBacklight(); // 關閉背光
delay(250);
lcd.backlight();
lcd.print("Hello");
lcd.setCursor(0, 1);  //游標移到左上角
lcd.print("Wecome");
lcd.createChar(1, easy);
Serial.begin(9600);
delay(300);             //Let system settle
Serial.println("Humidity and temperature\n\n");
delay(700);             //Wait rest of 1000ms recommended delay before
//accessing sensor
}
void loop() {
DHT.read11(dht_dpin);   //去library裡面找DHT.read11
lcd.clear();  //清除螢幕
lcd.setCursor(0, 0);  //游標移到左上角
lcd.print("Humidit=");
float H = DHT.humidity;
float T = DHT.temperature;
lcd.print(H);
lcd.print("% ");
lcd.write(byte(1));
lcd.setCursor(0, 1);  //游標移到左上角
lcd.print("Temperature=");
lcd.print(T);
lcd.println("C");
delay(1000);            //每1000ms更新一次
}
Previous7.線上學習資源Next2.藍芽APP之RGB燈泡控制

Last updated 5 years ago

Was this helpful?