아두이노 - 온도 센서 - OLED | Arduino - Temperature Sensor - OLED

이 튜토리얼에서는 DS18B20 원-와이어 센서에서 온도를 읽어서 OLED에 표시하는 방법을 배워볼 예정입니다.

준비물

1×Arduino Uno Amazon
1×USB 2.0 cable type A/B 쿠팡 | Amazon
1×SSD1306 I2C OLED Display 128x64 Amazon
1×DS18B20 Temperature Sensor (WITH Adapter) 쿠팡 | Amazon
1×DS18B20 Temperature Sensor (WITHOUT Adapter) Amazon
1×Breadboard 쿠팡 | Amazon
1×Jumper Wires Amazon
1×(Optional) 9V Power Adapter for Arduino Amazon
1×(Recommended) Screw Terminal Block Shield for Arduino Uno 쿠팡 | Amazon
1×(Optional) Transparent Acrylic Enclosure For Arduino Uno Amazon
공개: 이 섹션에서 제공된 링크 중 일부는 제휴 링크입니다. 이 링크를 통해 구매한 경우 추가 비용없이 수수료를 받을 수 있습니다. 지원해 주셔서 감사합니다.

Buy Note: Many DS18B20 sensors available in the market are unreliable. We strongly recommend buying the sensor from the DIYables brand using the link provided above. We tested it, and it worked reliably.

OLED 및 DS18B20 온도 센서에 대하여

OLED와 DS18B20 온도 센서(핀배열, 작동 원리, 프로그래밍 방법 등)에 대해 잘 모른다면, 다음 튜토리얼에서 배워보세요:

선연결

Arduino DS18B20 Temperature Sensor OLED Wiring Diagram

이 이미지는 Fritzing을 사용하여 만들어졌습니다. 이미지를 확대하려면 클릭하세요.

쉬운 연결을 위해 배선 어댑터가 포함된 DS18B20 센서를 구입할 것을 제안합니다. 어댑터에는 내장된 저항기가 있어 배선에서 별도의 저항기가 필요 없습니다.

아두이노 코드 - DS18B20 온도 센서에서 온도를 측정하고 OLED에 표시하기

/* * 이 Arduino 코드는 newbiely.kr 에서 개발되었습니다 * 이 Arduino 코드는 어떠한 제한 없이 공개 사용을 위해 제공됩니다. * 상세한 지침 및 연결도에 대해서는 다음을 방문하세요: * https://newbiely.kr/tutorials/arduino/arduino-temperature-sensor-oled */ #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #include <OneWire.h> #include <DallasTemperature.h> #define SCREEN_WIDTH 128 // OLED 디스플레이 너비, 픽셀 단위 #define SCREEN_HEIGHT 64 // OLED 디스플레이 높이, 픽셀 단위 #define SENSOR_PIN 2 // DS18B20 센서의 DQ 핀에 연결된 아두이노 핀 Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); // I2C에 연결된 SSD1306 디스플레이 객체 생성 OneWire oneWire(SENSOR_PIN); // oneWire 인스턴스 설정 DallasTemperature tempSensor(&oneWire); // oneWire를 DallasTemperature 라이브러리에 전달 String tempString; void setup() { Serial.begin(9600); // 128x64에 대한 주소 0x3C에서 OLED 디스플레이 초기화 if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { Serial.println(F("SSD1306 allocation failed")); while (true); } delay(2000); // 초기화를 위해 기다림 oled.clearDisplay(); // 디스플레이 클리어 oled.setTextSize(2); // 텍스트 크기 oled.setTextColor(WHITE); // 텍스트 색상 oled.setCursor(0, 10); // 디스플레이에 표시할 위치 tempSensor.begin(); // 센서 초기화 tempString.reserve(10); // String 사용시 메모리 단편화를 방지하기 위해 } void loop() { tempSensor.requestTemperatures(); // 온도를 얻기 위한 명령어 보냄 float tempCelsius = tempSensor.getTempCByIndex(0); // 섭씨 온도 읽기 tempString = String(tempCelsius, 2); // 소수점 두 자리 tempString += "°C"; Serial.println(tempString); // 시리얼 모니터에 섭씨 온도 출력 oledDisplayCenter(tempString); } void oledDisplayCenter(String text) { int16_t x1; int16_t y1; uint16_t width; uint16_t height; oled.getTextBounds(text, 0, 0, &x1, &y1, &width, &height); // 가로 및 세로 중앙에 표시 oled.clearDisplay(); // 디스플레이 클리어 oled.setCursor((SCREEN_WIDTH - width) / 2, (SCREEN_HEIGHT - height) / 2); oled.println(text); // 표시할 텍스트 oled.display(); }

사용 방법

  • PC에서 Arduino IDE를 실행하세요.
  • Arduino IDE의 왼쪽 바에 있는 Libraries 아이콘으로 이동하세요.
  • “SSD1306”을 검색한 다음, Adafruit의 SSD1306 라이브러리를 찾으세요.
  • 라이브러리를 설치하려면 Install 버튼을 클릭하세요.
Arduino OLED library

다른 라이브러리 종속성을 설치하라는 요청을 받게 됩니다.

모든 라이브러리 종속성을 설치하려면 Install All 버튼을 클릭하세요.

Arduino Adafruit GFX sensor library
  • “DallasTemperature”을 검색한 다음, Miles Burton의 DallasTemperature 라이브러리를 찾으세요.
  • DallasTemperature 라이브러리를 설치하려면 Install 버튼을 클릭하세요.
Arduino Dallas Temperature library
  • 라이브러리 종속성을 설치하라는 요청을 받게 될 것입니다.
  • OneWire 라이브러리를 설치하려면 Install All 버튼을 클릭하세요.
Arduino onewire library
  • 위의 코드를 복사하고 Arduino IDE로 열기
  • Arduino IDE에서 Upload 버튼을 클릭하여 코드를 Arduino에 업로드하기
  • 센서를 뜨거운 물과 차가운 물에 넣거나, 손으로 센서를 쥐기
  • OLED에서 결과 보기

※ NOTE THAT:

이 코드는 OLED 디스플레이에서 텍스트를 자동으로 수평 및 수직 중앙 정렬합니다.

동영상

비디오 제작은 시간이 많이 걸리는 작업입니다. 비디오 튜토리얼이 학습에 도움이 되었다면, YouTube 채널 을 구독하여 알려 주시기 바랍니다. 비디오에 대한 높은 수요가 있다면, 비디오를 만들기 위해 노력하겠습니다.

※ OUR MESSAGES

  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!