Arduino 101で作る万歩計:DHT11温湿度センサー&LCD表示付き
必要な部品と材料
| 部品 | 詳細 | 数量 |
|---|---|---|
| Arduino 101 (Intel Curie搭載) | 内蔵IMUで歩数検出可能 | 1 |
| DHT11 温湿度センサー (4ピン) | 1 | |
| Adafruit 16×2 LCD (白文字/青背景) | 1 | |
| ロータリーポテンショメータ | LCDコントラスト調整用 | 1 |
| ジャンパーワイヤー | 多数 | |
| 9V電池 | 1 | |
| 9V電池スナップ | 1 |
必要な工具
- 3Dプリンター(ケース製作用)
使用ツール
- Arduino IDE
このプロジェクトについて
「私の体、私の世界」をテーマにした科学フェア向けに製作。個人の身体パフォーマンスを測定するデバイスで、歩数・移動距離・消費カロリー・気温・湿度を計測・表示します。歩数検出はArduino 101内蔵IMU(CurieIMUライブラリ)を使用し、距離・カロリーは数式で算出。ケースは3Dプリント、9V電池駆動です。
なぜ作ったか
現代人の多くは運動不足。身体活動は代謝正常化と疾病リスク低減に不可欠です。日々のデータを可視化することで、自分の体を理解し、運動習慣改善の動機付けになると考えました。
コード
// Frank, the living dead, made this code.
// Chapecó, Brazil - 2017 Science Fair project
// Thanks: Adafruit, Intel, Filipeflop, Keyes
#include <DHT.h>
#include <DHT_U.h>
#include <LiquidCrystal.h>
#include "CurieIMU.h"
#include <SoftwareSerial.h>
#include <Adafruit_Sensor.h>
#define DHTPIN 8
#define DHTTYPE DHT11
LiquidCrystal lcd(12, 10, 5, 4, 3, 2);
int state = LOW, lastState = LOW;
const int ledPin = 13;
boolean stepEventsEnabled = true;
long lastStepCount = 0;
boolean blinkState = false;
float strideLength;
float calories = 0;
float weight = 57; // kg
float height = 168; // cm
float calPerKm;
float caloriesBurned;
float distance;
float stepsPerMile;
float speed;
char option;
float t;
DHT_Unified dht(DHTPIN, DHTTYPE);
uint32_t delayMS;
void setup() {
lcd.begin(16, 2);
dht.begin();
strideLength = 0.30 * height; // 歩幅推定(cm)
calPerKm = (0.57 * weight * 1.6) / 0.453; // 1kmあたり消費kcal
stepsPerMile = 160000.0 / strideLength; // 1マイル(160000cm)あたり歩数
lcd.clear();
lcd.setCursor(0, 0); lcd.print("Pedometer");
lcd.setCursor(0, 1); lcd.print("Made by Frank :P");
delay(3000);
CurieIMU.begin();
CurieIMU.setStepDetectionMode(CURIE_IMU_STEP_MODE_NORMAL);
CurieIMU.setStepCountEnabled(true);
if (stepEventsEnabled) {
CurieIMU.attachInterrupt(eventCallback);
CurieIMU.interrupts(CURIE_IMU_STEP);
}
}
static void updateStepCount() {
int stepCount = CurieIMU.getStepCount();
if (stepCount != lastStepCount) lastStepCount = stepCount;
}
static void eventCallback(void) {
if (CurieIMU.stepsDetected()) updateStepCount();
}
void loop() {
if (!stepEventsEnabled) updateStepCount();
// 歩数表示
lcd.clear();
lcd.setCursor(0, 0); lcd.print("Steps: ");
lcd.setCursor(0, 1); lcd.print(lastStepCount);
delay(4000);
// 消費カロリー表示
caloriesBurned = lastStepCount * (lastStepCount / stepsPerMile);
lcd.clear();
lcd.setCursor(0, 0); lcd.print("Calories B.: ");
lcd.setCursor(0, 1); lcd.print(caloriesBurned); lcd.print(" Kcal");
delay(4000);
// 距離表示
distance = (strideLength * lastStepCount) / 100; // メートル
lcd.clear();
lcd.setCursor(0, 0); lcd.print("Distance: ");
lcd.setCursor(0, 1); lcd.print(distance); lcd.print(" Meters");
delay(4000);
// 温度表示
delay(delayMS);
sensors_event_t event;
dht.temperature().getEvent(&event);
if (isnan(event.temperature)) {
Serial.println("Error - Temp");
} else {
lcd.clear();
lcd.setCursor(0, 0); lcd.print("Temperature: ");
lcd.setCursor(0, 1); lcd.print(event.temperature); lcd.print(" C");
delay(3000);
}
// 湿度表示
dht.humidity().getEvent(&event);
if (isnan(event.relative_humidity)) {
Serial.println("Error - Humi");
} else {
lcd.clear();
lcd.setCursor(0, 0); lcd.print("Humidity: ");
lcd.setCursor(0, 1); lcd.print(event.relative_humidity); lcd.print("%");
delay(3000);
}
lastState = state;
digitalWrite(13, blinkState);
blinkState = !blinkState;
delay(300);
}
回路図
LCD接続は標準的。ポテンショメータでコントラスト調整。詳細配線図を参照してください。
製造プロセス
- Arduinoデジタルダイス: LCD表示の乱数ジェネレーター自作
- Arduinoでアイアンマンを自作:部品・センサー・手順ガイド
- ArduinoとBluetoothで作るスマート紛失防止タグ「Find Me」
- Arduino駆動3Dプリントロボットアームの製作:ステップバイステップガイド
- DIY Arduino加湿器コントローラー:リレーを用いた安全な高電圧制御
- 非接触温度スクリーニングゲート:Arduino MKR1000で迅速・高精度な検温
- PiBot:Arduino駆動の精密ピアノ演奏ロボット
- Arduino Nanoで作るNeoPixelマトリックス版Pongゲーム
- ArduinoとThingSpeakで作るリアルタイム気象モニタリングシステム
- ゲーム用カスタムArduinoジョイスティックハンドルの製作
- ArduinoとTEA5767で作る高性能FMラジオ受信機