안녕하세요~ 인투피온입니다.
오늘은 DS18B20 사용법에 대해서 알아보겠습니다.
회로도
저항은 4.7K옴을 사용해주시면 됩니다.
라이브러리 추가하기
먼저 코딩하기전에 라이브러리 관리( Ctrl + Shift + I )를
열어서 아래 그림의 라이브러리를 설치해주세요.
DallasTemperature.h 라이브러리 설치
OneWire.h 라이브러리 설치
코딩하기
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 | #include <OneWire.h> #include <DallasTemperature.h> #define ONE_WIRE_BUS 2 // D2핀에서 데이터 읽기 OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); void setup(void) { Serial.begin(9600); sensors.begin(); } void loop(void){ sensors.requestTemperatures(); Serial.print("C : "); // 섭씨온도 Serial.print(sensors.getTempCByIndex(0)); Serial.print(" - F : "); //화씨온도 Serial.println(sensors.getTempFByIndex(0)); delay(1000); } | cs |
업로드 후 시리얼 모니터를 보시면 섭씨, 화씨 온도가 출력 되는것을 볼 수 있어요.
아두이노 arduino 코딩 코딩예제 예제 code coding 온도 온도센서 센서 ds18b20 temp. temperature 인투피온 intopion