1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Arduinoの部品導通記録③~デジタル温湿度センサー + I2C液晶ディスプレイ

1
Posted at

デジタル温湿度センサーの読んだ温湿度を、液晶ディスプレイに表示する導通を行った

環境

HW/SW バージョン他
筐体 Arduino Uno R4 Minima
IDE Arduino IDE 2.3.7
部品① デジタル温度湿度センサー(DHT11) 部品詳細
部品② I2C液晶ディスプレイ(I2C 1602 LCD Display Module – Blue Backlight) 部品詳細
その他部品 ジャンパーワイアー、ブレッドボード

前準備

Arduino IDEで、「Sketch」→「Include Library」→「Manage Libraries」
image.png

→検索窓で、「LiquidCrystal_I2C」で検索し、INSTALLを行う
image.png

同じ要領で、「DHT.h」も検索し、INSTALLを行う

回路

テキスト回路図(デジタル温度湿度センサー(部品①)→Arduino)

DHT11                Arduino UNO
--------------       -------------------
VCC   --------------> 5V
DATA  --------------> D2
GND   --------------> GND

テキスト回路図(I2C液晶ディスプレイ(部品②)→Arduino)

I2C LCD              Arduino UNO
-------------        -------------------
VCC   --------------> 5V
GND   --------------> GND
SDA   --------------> A4
SCL   --------------> A5

プログラム仕様

・実行すると、液晶ディスプレイに温度と湿度が表示される(1秒ごとに表示が変更)

プログラムソース

I2CLCD_tempelature.ico
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>

#define DHTPIN 2       // DHT11 のデータピン
#define DHTTYPE DHT11  // センサーの種類

DHT dht(DHTPIN, DHTTYPE);

// LCD のアドレスとサイズ(16x2)
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {
  Serial.begin(9600);
  dht.begin();

  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("DHT11 Ready");
}

void loop() {
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  // 読み取り失敗時
  if (isnan(h) || isnan(t)) {
    lcd.setCursor(0, 0);
    lcd.print("Read Error     ");
    lcd.setCursor(0, 1);
    lcd.print("               ");
    delay(1000);
    return;
  }

  lcd.setCursor(0, 0);
  lcd.print("Temp: ");
  lcd.print(t);
  lcd.print(" C   ");

  lcd.setCursor(0, 1);
  lcd.print("Humi: ");
  lcd.print(h);
  lcd.print(" %   ");

  delay(1000);
}

実行結果

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?