실시간 아두이노 날씨 시계: OLED 디스플레이로 시간, 날짜, 온도 표시
부품 및 소모품
| 부품 |
수량 |
| 아두이노 우노 |
1 |
| 아다프루트 DS3231 RTC 모듈 |
1 |
| 디질렌트 Pmod OLED (SSD1306) |
1 |
| TI LM35 온도 센서 |
1 |
| 점퍼 와이어 |
1 |
| 브레드보드 |
1 |
프로젝트 소개
시간, 날짜, 온도를 알려주는 아두이노 날씨 시계를 만듭니다. LM35 센서로 온도, DS3231 RTC로 날짜와 시간, OLED로 모두 표시합니다.
필수 부품
- 아두이노
- DS3231 (실시간 클록 모듈)
- OLED 디스플레이 (여기선 SSD1306 사용)
- SSD1306 데이터시트
- LM35
- 연결 와이어
- 브레드보드
회로도
OLED 연결 (SPI 통신)
OLED는 SPI와 I2C 모두 지원하나 여기선 SPI 사용. 아두이노 SPI 핀: 8, 9, 10, 11, 13
- OLED CS → 아두이노 핀 10
- OLED DC → 아두이노 핀 9
- OLED RES → 아두이노 핀 8
- OLED D1 (MOSI) → 아두이노 핀 11
- OLED D0 (SCK) → 아두이노 핀 13
- OLED VCC → 아두이노 5V
- OLED GND → 아두이노 GND
DS3231 연결 (I2C 통신)
아두이노 I2C 핀: SDA (A4), SCL (A5)
- DS3231 GND → 아두이노 GND
- DS3231 VCC → 아두이노 5V
- DS3231 SDA → 아두이노 A4
- DS3231 SCL → 아두이노 A5
LM35 연결
- LM35 좌측 핀 (VCC) → 아두이노 5V
- LM35 중앙 핀 (출력) → 아두이노 A0
- LM35 우측 핀 (GND) → 아두이노 GND

전체 크기 회로도: 여기
코드 설명
DS3231 모듈과 OLED용 라이브러리 추가. 아다프루트 OLED 라이브러리가 기능이 더 풍부합니다.
#include <DS3231.h>
#include <Adafruit_SSD1306.h>
핀 정의 및 변수 초기화:
DS3231 rtc(SDA, SCL);
#define OLED_MOSI 11
#define OLED_CLK 13
#define OLED_DC 9
#define OLED_CS 10
#define OLED_RESET 8
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
const int sensor_pin = A0;
float temp;
float output;
setup() 함수에서 LM35 핀을 입력으로 설정, DS3231과 OLED 통신 시작:
pinMode(sensor_pin, INPUT);
rtc.begin();
display.begin(SSD1306_SWITCHCAPVCC);
DS3231 최초 사용 시 요일, 날짜, 시간 설정용 코드 (주석 처리됨). 최초 사용 시 주석 해제 후 설정:
// rtc.setDOW(WEDNESDAY); // 요일 설정
// rtc.setTime(19, 02, 0); // 시간 설정 (24시간제)
// rtc.setDate(7, 12, 2017); // 날짜 설정
OLED에 "Weather Clock" 5초간 표시:
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(0,0);
display.print(" Weather ");
display.setCursor(0,17);
display.print(" Clock ");
display.display();
delay(5000);
loop() 함수에서 LM35 읽고 온도 계산, 시간/날짜/온도 OLED 출력:
output = analogRead(sensor_pin);
temp = (output * 500) / 1023;
display.clearDisplay();
display.setTextSize(2);
display.setCursor(20,0);
display.print(rtc.getTimeStr());
display.setTextSize(1);
display.setCursor(0,15);
display.print(rtc.getDateStr());
display.setTextSize(1);
display.setCursor(70,15);
display.print(rtc.getDOWStr());
display.setTextSize(1);
display.setCursor(20,25);
display.print("Temp: ");
display.print(temp);
display.print("C");
display.display();
delay(1000);
전체 아두이노 코드
#include <DS3231.h>
#include <Adafruit_SSD1306.h>
DS3231 rtc(SDA, SCL);
#define OLED_MOSI 11
#define OLED_CLK 13
#define OLED_DC 9
#define OLED_CS 10
#define OLED_RESET 8
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
const int sensor_pin = A0;
float temp;
float output;
void setup() {
pinMode(sensor_pin, INPUT);
rtc.begin();
display.begin(SSD1306_SWITCHCAPVCC);
// rtc.setDOW(WEDNESDAY);
// rtc.setTime(19, 02, 0);
// rtc.setDate(7, 12, 2017);
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(0,0);
display.print(" Weather ");
display.setCursor(0,17);
display.print(" Clock ");
display.display();
delay(5000);
}
void loop() {
output = analogRead(sensor_pin);
temp = (output * 500) / 1023;
display.clearDisplay();
display.setTextSize(2);
display.setCursor(20,0);
display.print(rtc.getTimeStr());
display.setTextSize(1);
display.setCursor(0,15);
display.print(rtc.getDateStr());
display.setTextSize(1);
display.setCursor(70,15);
display.print(rtc.getDOWStr());
display.setTextSize(1);
display.setCursor(20,25);
display.print("Temp: ");
display.print(temp);
display.print("C");
display.display();
delay(1000);
}
코드 스니펫
초기 화면 표시
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(0,0);
display.print(" Weather ");
display.setCursor(0,17);
display.print(" Clock ");
display.display();
delay(5000);
루프 내부 주요 로직
output = analogRead(sensor_pin);
temp = (output * 500) / 1023;
display.clearDisplay();
display.setTextSize(2);
display.setCursor(20,0);
display.print(rtc.getTimeStr());
display.setTextSize(1);
display.setCursor(0,15);
display.print(rtc.getDateStr());
display.setTextSize(1);
display.setCursor(70,15);
display.print(rtc.getDOWStr());
회로도
