Arduino MKR1000とSamsung ARTIK Cloudによるリアルタイムプール監視
必要な部品と用品
| Arduino MKR1000 | ×1 |
| ジャンパーワイヤ | ×1 |
| DFRobot pHメーター | ×1 |
| 抵抗 4.75kΩ | ×1 |
| 温度プローブ(防水型DS18B20等) | ×1 |
使用するアプリとオンラインサービス
- Samsung ARTIK Cloud for IoT
- Arduino IDE
プロジェクト概要
I. 目的
本プロジェクトの主目的は、Samsung ARTIK Cloudを用いてプールのpH値と水温を監視することです。
II. ARTIK Cloudのセットアップ
Step 1: 新しいデバイスの作成
- ARTIK Cloudにサインアップし、開発者サイトで新しい「デバイスタイプ」を作成
- 表示名とユニーク名を入力
- 新しいマニフェストを作成し、フィールド名(ph、temp等)と説明を入力
- 「ACTIVE MANIFEST」ボタンをクリックして有効化
Step 2: アプリケーションの作成
- ARTIK CloudのApplicationsで「New Application」をクリック
- アプリ名と認証リダイレクトURLを入力(例: https://localhost/index/)
- 権限をRead/Writeに設定し、デバイスを選択して保存
Step 3: デバイスの接続
- 「My Devices」で「Connect Another Device」をクリック
- 作成したデバイスタイプを選び、「Connect Device」
- 接続されたデバイスの設定から、Device IDとDevice Tokenをメモ(プログラムで必要)
III. ハードウェア・センサーセットアップ
Step 1: 温度センサーとpHセンサーをMKR1000に接続
配線図:
- 温度センサー GND → MKR1000 GND
- 温度センサー OUT → MKR1000 デジタルピン1
- 温度センサー VCC → MKR1000 5V
- 4.7kΩ抵抗を温度センサーのVCCとOUT間に接続(プルアップ)
- pHセンサー GND → MKR1000 GND
- pHセンサー OUT → MKR1000 アナログピンA1
- pHセンサー VCC → MKR1000 5V
温度センサーには着脱容易なオーディオジャックを使用しています(任意)。
Step 2: 必要なソフトウェアの準備
- Arduino IDEでMKR1000ボードを追加(ボードマネージャで「mkr1000」検索→インストール)
- 以下のライブラリをインストール:
- ArduinoJson - ARTIK CloudへJSONデータ送信用
- ArduinoHttpClient - API接続用ホスト
- OneWire - 温度センサーからのデジタル入力読み取り用
- DallasTemperature - Dallas温度センサー用ライブラリ
Step 3: プログラムのアップロード
- MKR1000をPCに接続
- GitHubからコードをダウンロード
- 以下の情報を書き換え:
- WiFi SSIDとパスワード
- ARTIK CloudのDevice IDとDevice Token
- コードをアップロードして監視開始
注意: WiFi環境にインターネット接続が必要です。
IV. 実地テスト
プライベート、公立、学校のプールでテストを実施し、ハードウェアの能力を検証しました。
MKR1000とセンサーを防水ボックスに収め、プールに浮かべて使用します。水質を監視し、必要な薬剤投入で正常化できます。
今後、ボックスへの収納手順と実際のテスト映像のチュートリアルを公開予定です。
V. 結果と考察
このチュートリアルが、DIYプール水質監視デバイスの構築に役立てば幸いです。プールの水質劣化への意識向上につながり、リソースを無駄にせず効率的・効果的な水質検査の手段をコミュニティに提供できることを願っています。
Happy building! :)
コード
Arduino MKR1000 用コード (C/C++)
このコードをMKR1000にアップロードしてください。
GitHub: https://github.com/imjeffparedes/iot-water-quality-artik
/******************** Water Quality Device Monitoring ********************/
#include <WiFi101.h>
#include <WiFiClient.h>
#include <ArduinoJson.h>
#include <ArduinoHttpClient.h>
#include <SPI.h>
#include <OneWire.h>
#include <DallasTemperature.h>
/** Temperature Sensor **/
#define ONE_WIRE_BUS 1
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
/** ARTIK Cloud REST **/
char server[] = "api.artik.cloud";
int port = 443;
char buf[200];
String deviceID = "your_device_id";
String deviceToken = "your_device_token";
/** pH Meter **/
#define SensorPin A1
#define Offset 0.00
#define samplingInterval 20
#define ArrayLenth 40
int pHArray[ArrayLenth];
int pHArrayIndex = 0;
int status = -1;
unsigned long millis_start;
#define WIFI_AP "your_wifi_ssid"
#define WIFI_PWD "your_wifi_password"
WiFiSSLClient wifi;
HttpClient client = HttpClient(wifi, server, port);
void setup() {
millis_start = millis();
Serial.begin(9600);
startWifi();
}
void loop() {
// 温度取得
float celsius = 0;
sensors.requestTemperatures();
celsius = sensors.getTempCByIndex(0);
sensors.requestTemperatures();
celsius = sensors.getTempCByIndex(0);
// pH値取得
static unsigned long samplingTime = millis();
static unsigned long printTime = millis();
static float pHValue, voltage;
if (millis() - samplingTime > samplingInterval) {
pHArray[pHArrayIndex++] = analogRead(SensorPin);
if (pHArrayIndex == ArrayLenth) pHArrayIndex = 0;
voltage = avergearray(pHArray, ArrayLenth) * 5.0 / 1024;
pHValue = 3.5 * voltage + Offset;
samplingTime = millis();
}
// デバッグ出力
Serial.println("===========================================");
Serial.println("We will send these json data");
Serial.print("data: { ph: "); Serial.print(pHValue);
Serial.print(" , temp: "); Serial.print(celsius); Serial.println("} ");
Serial.println("Start sending data");
// ARTIK CloudへPOST
String contentType = "application/json";
String AuthorizationData = "Bearer " + deviceToken;
int len = loadBuffer(celsius, pHValue);
Serial.println("Sending temp: " + String(celsius) + " and ph: " + String(pHValue));
Serial.println("Send POST to ARTIK Cloud API");
client.beginRequest();
client.post("/v1.1/messages");
client.sendHeader("Authorization", AuthorizationData);
client.sendHeader("Content-Type", "application/json");
client.sendHeader("Content-Length", len);
client.endRequest();
client.print(buf);
int statusCode = client.responseStatusCode();
String response = client.responseBody();
Serial.print("Status code: "); Serial.println(statusCode);
Serial.print("Response: "); Serial.println(response);
delay(1000);
}
void startWifi() {
Serial.println("Connecting MKR1000 to network...");
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(WIFI_AP);
WiFi.begin(WIFI_AP, WIFI_PWD);
delay(10000);
status = WiFi.status();
}
}
// pHセンサー平均値計算(DFRobotライブラリ由来)
double avergearray(int* arr, int number) {
// ... 実装省略(元コード参照) ...
}
// JSONバッファ作成
int loadBuffer(float temp, float ph) {
StaticJsonBuffer<200> jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
root["sdid"] = deviceID;
root["type"] = "message";
JsonObject& dataPair = root.createNestedObject("data");
dataPair["temp"] = temp;
dataPair["ph"] = ph;
root.printTo(buf, sizeof(buf));
return root.measureLength();
}
回路図
MKR1000とセンサーのブレッドボード接続図
製造プロセス
- Raspberry PiとPythonでリモート温度センサーを構築 – ステップバイステップガイド
- ホームエナジーセンター:Raspberry PiとMoteinoで太陽光発電、ソーラー熱、室温を監視
- DIY自家醸造温度制御:Arduinoで監視・調節
- Raspberry Pi 3とPubNubでリモート気象監視
- スマート室内空気品質・廃棄物監視システム:Raspberry Pi/Arduino/NodeMCUでIOTA Tangle連携
- Arduinoとスマホで作るスマート電圧計 – 簡単DIYプロジェクト
- SaaSとクラウドをナビゲートする:なぜ綿密なデータ管理が重要なのか
- 広がるクラウドの地平:新ゾーン、コンテナ、マルチクラウド戦略
- クラウドアプリケーション監視の極意:ITリーダーが知るべき洞察
- Cloud Linuxが共有ホスティングのセキュリティ、安定性、パフォーマンスを向上させる理由
- ガス監視ソリューションが産業・自動車環境の安全性を高める仕組み