코드 검색

Arduino RJT43을 사용한 7-세그먼트 디스플레이의 DHT22 온도 및 습도

Arduino RJT43을 사용한 7-세그먼트 디스플레이의 DHT22 온도 및 습도

이 프로젝트는 Arduino를 사용하여 7-세그먼트 디스플레이에 온도와 습도 수치를 표시하는 간단하면서도 효과적인 시스템을 구축하는 방법을 보여줍니다. 이 설정은 환경 조건 모니터링이 중요한 다양한 응용 분야에 유용합니다. 이 프로젝트는 DHT22 온습도 센서와 TM1637 7-세그먼트 디스플레이를 결합하여 명확하고 읽기 쉬운 출력을 제공합니다.

DHT22 sensor with PCB-1
Arduino wriing DHT11 PCB module  module with TM1637

프로젝트 아이디어:

  • 최적의 쾌적함을 위해 가정 환경 모니터링.
  • 온실이나 테라리움의 조건 추적.
  • 기본 기상 관측소 구축.
  • 데이터 로깅 프로젝트에서 온도와 습도 표시.

하드웨어/부품

이 프로젝트를 구축하려면 다음 부품이 필요합니다:

  • Arduino Uno (또는 호환 보드)
  • DHT22 온습도 센서
  • TM1637 7-세그먼트 디스플레이
  • 연결 와이어
  • 브레드보드 (선택 사항이지만 권장됨)

배선 가이드

Arduino wriing DHT11 PCB module  module with TM1637
Arduino wriing DHT11 PCB module module with TM1637
Arduino wriing DHT11 bare module  module with TM1637
Arduino wriing DHT11 bare module module with TM1637
Arduino wriing DHT11 bare module  module with TM1637
Arduino wriing DHT11 bare module module with TM1637

배선은 간단합니다. 시각적 가이드는 비디오(비디오 01:51)를 참조하세요. 주요 연결은 다음과 같습니다:

  • TM1637 디스플레이: VCC를 5V에, GND를 GND에, CLK를 Arduino 핀 2에, DIO를 Arduino 핀 3에 연결 (비디오 02:00).
  • DHT22 센서: VCC를 5V에, GND를 GND에, DATA를 Arduino 핀 9에 연결 (비디오 02:20). 비디오에서는 Arduino 핀 8을 사용하여 센서에 5V를 공급합니다 (비디오 02:41).

코드 설명

Arduino 코드는 두 개의 라이브러리를 사용합니다: 7-세그먼트 디스플레이용 TM1637Display와 DHT22 센서용 DHT입니다. 코드의 구성 가능한 매개변수는 주로 시작 부분에 있습니다:


// 모듈 연결 핀 (디지털 핀)
#define CLK 2
#define DIO 3
#define DHTPIN 9     // DHT22 데이터 핀
#define DHTTYPE DHT22   // DHT 센서 유형

이 줄들은 디스플레이와 DHT22 센서에 연결된 Arduino 핀을 정의합니다. 다른 핀을 사용하는 경우 이를 조정해야 할 수 있습니다. getTemp() 함수 (비디오 07:03)는 중요합니다. 문자열 인수를 전달하여 DHT22 센서에서 다양한 값을 검색할 수 있습니다:


float getTemp(String req) {
  // ... (센서 읽기 코드) ...
  if(req =="c"){ return t; } // 섭씨
  else if(req =="f"){ return f; } // 화씨
  // ... (켈빈, 습도, 열지수에 대한 기타 옵션) ...
}

이 함수는 센서에서 다양한 데이터(섭씨, 화씨, 습도, 열지수)를 읽는 것을 단순화합니다. 메인 루프는 이 함수를 사용하여 데이터를 가져와 7-세그먼트 디스플레이에 표시하며, 표시 목적으로 부동 소수점 값을 정수로 반올림합니다 (비디오 07:14).

라이브 프로젝트/데모

비디오 (비디오 00:32)는 프로젝트의 라이브 데모를 보여줍니다. 7-세그먼트 디스플레이에 화씨 온도가 명확하게 표시됩니다. 비디오는 또한 코드를 수정하여 섭씨, 켈빈, 습도 및 열지수 값을 표시하는 방법을 보여줍니다 (비디오 08:21).

챕터

  • [00:06] 소개 및 프로젝트 개요
  • [00:53] 시작 및 부품 개요
  • [01:51] TM1637 디스플레이 배선
  • [02:20] DHT22 센서 배선
  • [03:14] 코드 설명: TM1637 설정
  • [04:00] 코드 설명: DHT22 설정
  • [05:54] 코드 설명: 메인 루프 및 표시 함수
  • [07:03] 코드 설명: getTemp() 함수
  • [08:21] 데모 및 다양한 출력 옵션

이미지

DHT22 sensor with PCB-1
DHT22 sensor with PCB-1
DHT22 with PCB red
DHT22 with PCB red
DHT22 sensor no PCB
DHT22 sensor no PCB
Arduino wriing DHT11 PCB module  module with TM1637
Arduino wriing DHT11 PCB module module with TM1637
Arduino wriing DHT11 PCB module  module with TM1637
Arduino wriing DHT11 PCB module module with TM1637
Arduino wriing DHT11 bare module  module with TM1637
Arduino wriing DHT11 bare module module with TM1637
Arduino wriing DHT11 bare module  module with TM1637
Arduino wriing DHT11 bare module module with TM1637
56-Arduino code and video for a DHT12 Temperature and Humidity Sensor with TM1637 Display
언어: C++
/*
 * Original code from TM1637 https://github.com/avishorp/TM1637
 * Original code and library for DHT22 https://github.com/adafruit/DHT-sensor-library
 * Modified for Robojax video on January 7, 2018
 * by Ahmad Shamshiri, in Ajax, Ontario, Canada
 * Watch the video for this code https://youtu.be/z_FvRm6Te78
 * Other Arduino library and videos https://robojax.com
 * Get this code and other Arduino codes from Robojax.com
Learn Arduino step by step in a structured course with all material, wiring diagrams, and libraries
all in one place. 

If you found this tutorial helpful, please support me so I can continue creating 
content like this. 

or make a donation using PayPal http://robojax.com/L/?id=64

 *  * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.* 
 * This code has been downloaded from Robojax.com
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>. 
 */
 
// ****** Start of TM1637 Display code 
#include <Arduino.h>
#include <TM1637Display.h>
// Module connection pins (Digital Pins)
#define CLK 2
#define DIO 3
// The amount of time (in milliseconds) between tests
#define TEST_DELAY   1000
TM1637Display display(CLK, DIO);
// ****** end of TM1637 Display code 

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain


// ****** Start of DHT code 
#include "DHT.h"
#define DHTPIN 9     // what digital pin we're connected to
// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
//#define DHTTYPE DHT21   // DHT 21 (AM2301)
DHT dht(DHTPIN, DHTTYPE);
// ********** end of DHT22 code

void setup()
{
  Serial.begin(9600);
  Serial.println("DHT22 Robojax Test with Display");
  pinMode(8,OUTPUT);
  digitalWrite(8,HIGH);// gives 5v for DHT22
  dht.begin();  
}

void loop()
{
  delay(TEST_DELAY);// wait
  // **** TM1637 code start
  display.setBrightness(0x0f);// set brightness
  uint8_t data[] = { 0x0, 0x0, 0x0, 0x0 };// clear display values
  display.setSegments(data);//clear display
  // **** TM1637 code end
  

  // Robojax.com test video
  Serial.println(getTemp("h"));

  int temp = round(getTemp("h"));
  
  display.showNumberDec(temp, false, 3,1);



}// loop end


/*
 * getTemp(String req)
 * returns the temperature related parameters
 * req is string request
 * This code can display temperature in:
 * getTemp("c") is used to get Celsius
 * getTemp("f") is used to get Fahrenheit
 * getTemp("k") is used for Kelvin
 * getTemp("hif") is used to get Fahrenheit
 * getTemp("hic") is used to get Celsius
 * getTemp("h") is used to get humidity 
 * written by Ahmad Shamshiri for Robojax.com on January 7, 2018
 * in Ajax, Ontario, Canada
 */
float getTemp(String req)
{

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (it's a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);

  // Compute heat index in Fahrenheit (the default)
  float hif = dht.computeHeatIndex(f, h);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return 0.0; //return 0.0 instead of nothing.
  }
  // Compute heat index in Kelvin 
  float k = t + 273.15;
  if(req =="c"){
    return t;//return Celsius
  }else if(req =="f"){
    return f;// return Fahrenheit
  }else if(req =="h"){
    return h;// return humidity
  }else if(req =="hif"){
    return hif;// return heat index in Fahrenheit
  }else if(req =="hic"){
    return hic;// return heat index in Celsius
  }else if(req =="k"){
    return k;// return temperature in Kelvin
  }else{
    return 0.000;// if no request found, return 0.000
  }
 
}

자원 및 참고자료

아직 자원이 없습니다.

파일📁

아두이노 라이브러리 (zip)

프리징 파일

사용자 매뉴얼