아두이노 나노로 만드는 신뢰할 수 있는 LCD 스톱워치 - 가변저항 불필요
부품 및 소모품
| 부품 |
수량 |
| 브레드보드 (일반) |
1 |
| 아두이노 나노 R3 |
1 |
| Adafruit 표준 LCD - 16x2 백색/청색 |
1 |
| SparkFun 푸시버튼 스위치 12mm |
3 |
| 저항 10k 옴 |
5 |
| 저항 221 옴 |
1 |
| 점퍼 와이어 (일반) |
26 |
프로젝트 소개
안녕하세요! 이 프로젝트는 LCD를 처음 접하는 분들을 위한 간단한 학습 프로젝트입니다. 아두이노 나노와 LCD QUAPASS 1602A 16x2를 사용하여 시간, 분, 초를 카운트하는 스톱워치를 만들었습니다. LCD 밝기 조절 기능도 포함되어 있습니다.
코드를 약간 수정하면 1/100초 단위까지 카운트할 수 있지만, 제 LCD는 화면 주사율이 따라가지 못해 제대로 작동하지 않았습니다.
제 스톱워치는 거의 완벽한 타이밍으로 설정되어 있습니다(약 15% 오차: 실제 10분 경과 시 스톱워치에는 10분 2초로 표시). stopwatch 서브루틴 내의 start 부분을 수정할 경우, 아두이노의 코드 실행 시간 때문에 타이밍 값도 함께 조정해야 합니다.
1단계: 배선
회로도(Schematics 섹션 참조)를 보고 아두이노와 LCD를 연결하세요.
2단계: 코드 업로드
아래 코드를 아두이노 IDE에 복사하여 붙여넣고, 아두이노를 USB에 연결한 뒤 업로드 버튼을 누르세요.
3단계: 즐기기
직접 만든 간편한 LCD 스톱워치를 즐겨보세요. 궁금한 점이 있으면 댓글로 남겨주세요.
코드
/* 심플 LCD 스톱워치 프로그램: 시작, 정지, 리셋, 랩 버튼 포함 */
#include <LiquidCrystal.h>
// LCD 핀 설정 (RS, E, D4, D5, D6, D7)
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int h = 0, m = 0, s = 0, ms = 0;
const int start_pin = 8;
const int stop_pin = 9;
const int reset_pin = 10;
int start = 0, stop1 = 0, reset = 0;
int brightness_pin = 6;
int brightness = 100; // 밝기 조절 값 (0-255)
void setup() {
analogWrite(brightness_pin, brightness);
lcd.begin(16, 2);
pinMode(start_pin, INPUT);
pinMode(stop_pin, INPUT);
pinMode(reset_pin, INPUT);
pinMode(brightness_pin, OUTPUT);
}
void loop() {
lcd.setCursor(0, 1);
lcd.print("STOPWATCH");
lcd.setCursor(0, 0);
lcd.print("TIME:");
lcd.print(h); lcd.print(":"); lcd.print(m); lcd.print(":"); lcd.print(s);
start = digitalRead(start_pin);
if (start == HIGH) {
stopwatch();
}
}
void stopwatch() {
lcd.setCursor(0, 0);
lcd.print("TIME:");
lcd.print(h); lcd.print(":"); lcd.print(m); lcd.print(":"); lcd.print(s);
ms += 10;
delay(10);
if (ms == 590) lcd.clear();
if (ms == 590) { ms = 0; s++; }
if (s == 60) { s = 0; m++; }
if (m == 60) { m = 0; h++; }
lcd.setCursor(0, 1);
lcd.print("STOPWATCH");
stop1 = digitalRead(stop_pin);
if (stop1 == HIGH) {
stopwatch_stop();
} else {
stopwatch(); // 재귀 호출로 지속적 갱신
}
}
void stopwatch_stop() {
lcd.setCursor(0, 0);
lcd.print("TIME:");
lcd.print(h); lcd.print(":"); lcd.print(m); lcd.print(":"); lcd.print(s);
lcd.setCursor(0, 1);
lcd.print("STOPWATCH");
start = digitalRead(start_pin);
if (start == HIGH) stopwatch();
reset = digitalRead(reset_pin);
if (reset == HIGH) stopwatch_reset();
else stopwatch_stop();
}
void stopwatch_reset() {
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("STOPWATCH");
h = 0; m = 0; s = 0;
return;
}
라이브러리
LiquidCrystal 라이브러리가 필요합니다: GitHub 링크
회로도
회로도 이미지는 Schematics 섹션을 참조하세요.