Arduino Nanoで作る信頼性の高いLCDストップウォッチ – ポテンショメータ不要
必要な部品と材料
| 部品 | 数量 |
|---|---|
| ブレッドボード(汎用) | 1 |
| Arduino Nano R3 | 1 |
| Adafruit標準LCD - 16x2 白文字/青背景 | 1 |
| SparkFun プッシュボタンスイッチ 12mm | 3 |
| 抵抗 10kΩ | 5 |
| 抵抗 221Ω | 1 |
| ジャンパーワイヤー(汎用) | 26 |
プロジェクト概要
こんにちは!このプロジェクトはLCDの基本を学ぶためのシンプルな学習用プロジェクトです。Arduino NanoとLCD(QUAPASS 1602A 16x2)を使用して、時・分・秒をカウントするストップウォッチを作ります。LCDの輝度調整機能も搭載しています。
コードを少し変更すれば100分の1秒単位までカウント可能ですが、私のLCDではリフレッシュレートが追いつかず正常に動作しませんでした。
タイミングはほぼ完璧に調整済みです(実測で約15%の誤差:実際の10分に対してストップウォッチでは10分2秒を表示)。stopwatchサブプログラム内のstart部分を変更する場合は、Arduinoのコード実行時間の影響を考慮してタイミング調整が必要になります。
手順1:配線
回路図(Schematicsを参照)に従ってArduinoとLCDをブレッドボード上で配線してください。
手順2:コードのアップロード
下記のコードをArduino IDEにコピー&ペーストし、Arduinoを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;
const 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);
if (digitalRead(start_pin) == 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");
if (digitalRead(stop_pin) == 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");
if (digitalRead(start_pin) == HIGH) {
stopwatch();
}
if (digitalRead(reset_pin) == HIGH) {
stopwatch_reset();
} else {
stopwatch_stop();
}
}
void stopwatch_reset() {
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("STOPWATCH");
h = m = s = 0;
return;
}
使用ライブラリ
LiquidCrystalライブラリ(Arduino標準ライブラリに含まれます)
回路図

製造プロセス
- Arduino Nanoで20kHzオシロスコープを自作:Nokia 5110 LCD搭載・簡易DIYガイド
- スマートブラインド:Arduinoとソーラー電源で実現する自動光制御
- Arduinoでアイアンマンを自作:部品・センサー・手順ガイド
- Arduinoでシンプルな障害物センサーを自作 – IR LEDとフォトダイオード入門
- ArduinoとBluetoothで作るスマート紛失防止タグ「Find Me」
- DIY Arduino加湿器コントローラー:リレーを用いた安全な高電圧制御
- Arduino Nanoで自作オシロスコープ(10Hz〜50kHz)128×64 LCD搭載
- ゲーム用カスタムArduinoジョイスティックハンドルの製作
- Arduino 101で作る万歩計:DHT11温湿度センサー&LCD表示付き
- Arduino RGBカラーミキサーの製作 - ステップバイステップチュートリアル
- AI搭載LCDコンパニオンを自作: インタラクティブな相棒