티스토리 뷰
[온습도 센서 예시]
- IC : AM2302
- 센서 모델 : DHT22

[예제 코드]
// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain
#include "DHT.h"
#define DHTPIN 2 // what pin we're connected to
// Uncomment whatever type you're using!
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
Serial.println("DHTxx test!");
dht.begin();
}
void loop() {
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
float t = dht.readTemperature();
// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t) || isnan(h)) {
Serial.println("Failed to read from DHT");
} else {
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" *C");
}
}
반응형
'HWDesk > HardwareControl' 카테고리의 다른 글
DRV88245, ULN2003, MPU60506, AM2302 연결 방법 (0) | 2025.04.27 |
---|---|
스테핑 모터 제어 방법 비교 (0) | 2025.04.26 |
스텝 모터 제어 시 모드 비교(모드 1 ~ 모드 4) (0) | 2025.04.13 |
스텝 모터(NEMA 17) 제어 예제 (0) | 2025.04.12 |
스텝 모터 제어 예제 (1) | 2025.04.06 |
반응형
250x250
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 전압전류모니터링
- 치매
- 아두이노
- image
- 치매방지
- BSC
- 빌리언트
- Innovations&Hurdles
- 혁신
- DYOV
- 절연형
- Video
- Hurdles
- Innovation&Hurdles
- 심심풀이
- 전류
- arduino
- 전압
- badp
- 티스토리챌린지
- 심심풀이치매방지기
- 혁신과허들
- 둎
- 배프
- Innovations
- Decorator
- ServantClock
- 허들
- 오블완
- bilient
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
글 보관함