아두이노 101로 만보기 만들기: DHT11 센서와 LCD 디스플레이 활용
부품 및 소모품
| 아두이노 101 (Arduino 101 / Curie 모듈 탑재) |
× |
1 |
| DHT11 온습도 센서 (4핀) |
× |
1 |
| Adafruit 16×2 LCD (흰색 글자, 파란 배경) |
× |
1 |
| 로터리 포텐셔미터 (범용, LCD 대비 조절용) |
× |
1 |
| 점퍼 와이어 (범용) |
× |
1 |
| 9V 배터리 |
× |
1 |
| 9V 배터리 클립 |
× |
1 |
필수 도구
앱 및 온라인 서비스
프로젝트 소개
작년 도시 과학 박람회 주제 "내 몸, 내 세상" 출품작입니다. 개인의 신체 활동을 측정하는 기기로, 걸음 수, 이동 거리, 소모 칼로리, 주변 온도, 습도를 표시합니다. 대부분의 데이터는 아두이노 101 내장 라이브러리(걸음 수)로부터 얻고, 나머지는 수식으로 계산합니다. 케이스는 3D 프린터로 출력, 9V 배터리로 구동.
왜 만들었나?
현대인은 좌식 생활로 신체 활동 부족, 대사 질환 위험 증가. 신체 활동을 모니터링하면 동기 부여가 되고, 자신의 몸을 이해하며 매일 실천을 개선할 수 있습니다. 이 프로토타입이 그런 데이터를 수집·표시해 줍니다.
질문은 댓글이나 이메일로 주세요.
코드 (C/C++)
// Frank, 2017년 과학 박람회용 첫 프로젝트 (브라질 샤페코)
// 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 stepEventsEnabeled = true;
long lastStepCount = 0;
boolean blinkState = false;
float stride_length, calories = 0, weight = 57, height = 168;
float cal_per_km, calories_burned, distance, steps_per_mile, speed;
char option;
float t;
DHT_Unified dht(DHTPIN, DHTTYPE);
uint32_t delayMS;
void setup() {
lcd.begin(16, 2);
dht.begin();
stride_length = 0.30 * height; // 보폭 추정(cm)
cal_per_km = (0.57 * weight * 1.6) / 0.453; // km당 칼로리
steps_per_mile = 160000.0 / stride_length; // 1마일(160,000cm) 당 걸음 수
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 (stepEventsEnabeled) {
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 (!stepEventsEnabeled) updateStepCount();
// 걸음 수 표시
lcd.clear(); lcd.setCursor(0,0); lcd.print("Steps: ");
lcd.setCursor(0,1); lcd.print(lastStepCount); delay(4000);
// 소모 칼로리 계산 및 표시
calories_burned = lastStepCount * (lastStepCount / steps_per_mile);
lcd.clear(); lcd.setCursor(0,0); lcd.print("Calories B.: ");
lcd.setCursor(0,1); lcd.print(calories_burned); lcd.print(" Kcal"); delay(4000);
// 이동 거리 계산 및 표시
distance = (stride_length * lastStepCount) / 100.0; // 미터
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 연결은 간단합니다.