• Skip to primary navigation
  • Skip to main content

IoTmaker

사물인터넷에 대한 모든 것 여기서 해결하셔요!

  • 홈
  • 책:마이크로파이썬을 활용한 사물인터넷
  • 책:따라 하면서 배우는 사물인터넷
  • 온라인 교육 코스
  • 새로운 소식
  • 의견보내기
  • 내 수강정보
  • 로그인
  • 회원가입

온습도 센서 스니펫

책에서 사용하는 부품 구입하기 DHT12, SHT30와 MLX90614는I2C 방식으로 연결하여 사용합니다. DHT22와 DHT11은 핀을 지정하여야 합니다.

ds18b20은 OneWire 방식으로 연결되는 온도 전용 센서입니다. OneWire 방식으로는 하나의 데이터선에 여러 개의 센서를 연결할 수 있습니다. 이 때 데이터 핀은 4.7KΩ 저항으로 풀업해야 합니다.

기반이 되는 라이브러리 먼저 설치하기 20-12-17 추가
Adafruit_Sensor.h는 기반이 되는 아두이노 라이브러리입니다. 이 라이브러리는 GitHub에서 다운로드하여 설치합니다.
기본 정보
라이브러리
온도와 습도
Aims_dht22.h
21-02-02
아이콘

Aims_dht22.zip

1 파일 7.90 KB
다운로드
Aims_dht12.h
아이콘

Aims_dht12.zip

1 파일 9.51 KB
다운로드
Aims_dht11.h
21-02-02
아이콘

Aims_dht11.zip

1 파일 7.11 KB
다운로드
Aims_sht30.h
아이콘

Aims_sht30.zip

1 파일 2.45 KB
다운로드
온도
Aims_ds18b20.h
아이콘

Aims_ds18b20.zip

1 파일 25.54 KB
다운로드
Aims_MLX90614.zip.h
아이콘

Aims_MLX90614.zip

1 파일 2.45 KB
다운로드
생성자 Aims_dht22 dht; // 실드 사용할 때
Aims_dht22 dht(핀 번호);
Aims_dht22 dht(핀 번호,DHT22); // depreciated
Aims_dht12 dht;
Aims_dht11 dht; // 실드 사용할 때
Aims_dht11 dht(핀 번호);
Aims_dht11 dht(핀 번호,DHT11); // depreciated
Aims_sht30 dht;
Aims_ds18b20 dht(핀 번호);
Aims_MLX90614 mlx;
메소드 float getTemp();온도를 읽어 옴
float getTemp(인덱스);ds18b20의 경우 온도를 읽어 옴
(첫번 째 센서의 인덱스는 0, 인덱스 생략되면 기본값은 0)
float getHum();습도를 읽어 옴
float temp();최근 읽은 온도를 돌려줌
float hum();최근 읽은 습도를 돌려줌
예제 프로그램
temp-hum-dht22
// pin
#define DHT22_PIN    D4        

#include <AimTimer.h>

AimTimer timerTemp(10);
AimTimer timerHum(10);

// Aims
#include <Aims_dht22.h>

//Aims_dht22 dht(DHT22_PIN,DHT22); // depreciated
//Aims_dht22 dht;  // 실드 사용할 때
Aims_dht22 dht(DHT22_PIN);

void setup() {
  Serial.begin(115200);
  Serial.println();
}
void loop() {

  if (timerTemp.isOn()) {
    Serial.print("temp=");
    Serial.println(dht.getTemp());
  }
  else if (timerHum.isOn()) {
    Serial.print("hum=");
    Serial.println(dht.getHum());
  }
}
temp-hum-sht30
// pin
//#define DHT22_PIN    D4        

#include <AimTimer.h>

AimTimer timerTemp(10);
AimTimer timerHum(10);

// Aims
#include <Aims_sht30.h>

Aims_sht30 dht;

void setup() {
  Serial.begin(115200);
  Serial.println();
}
void loop() {

  if (timerTemp.isOn()) {
    Serial.print("temp=");
    Serial.println(dht.getTemp());
  }
  else if (timerHum.isOn()) {
    Serial.print("hum=");
    Serial.println(dht.getHum());
  }
}

Copyright © 2025 ·로그인