D7S-A0001とM5STACKでお化け探知機作ってみた


概要

 M5STACKと感振センサーで、お化け探知機作ってみた!!!

デバイス

 今回こちらをご紹介します。

こちら。オムロン製D7S-A0001が搭載されており、Groveケーブルにて楽勝で使えます。M5STACK,ラズベリーパイ、Arduinoであれば、ドライバやサンプルがダウンロードできるので非常に楽です。

本デバイスはこちらで購入可能です。
テックシェア
購入ページ
スイッチサイエンス
購入ページ
マルツエレテック
購入ページ

通常の加速度センサーとは違い、純粋に揺れの大きさを検知します。震度とも非常に関連性の高いSI値を測定することが可能なセンサーです。

今回はこれを使用して、ポルターガイスト現象をとらえることが可能なガジェットを作成してみました。ポルターガイスト現象が発生すると、当然机などが揺れ動くことが予想できます。それをとらえて、wed経由で通知するわけです。

構成

今回IFTTTというサービスを使用しました。M5STACKであれば、容易にWI-FI経由でWEBに接続できるため、センサーが揺れを検知したら、WEB経由でLINE通知してもらいます。

プログラム

/**
   D7S用お化け検出プログラム
**/
#include <M5Stack.h>
#include <D7S.h>
#include <WiFi.h>
#include <HTTPClient.h>

// URL関連
// https://maker.ifttt.com/trigger/[EventName]/with/key/[Key]
// [EventName]はIFTTTのAppletのEventName
// [Key]はIFTTTのWebhooksの設定のURLのhttps://maker.ifttt.com/use/XXXのXXX


// 情報通知用(Value1=SI値,Value2=PGAとなるようAppletを作っておく)
#define INFO_URL "https://maker.ifttt.com/trigger/obake/with/key/ddoHtC0QcgYk7A2vfFH-1P"

// Wifi関連
const char* ssid       = "*****"; // WiFi SSID
const char* password   = "******";  // WiFi PW

void setup() {
  // M5Stack 初期化
  M5.begin();
  Serial.begin(9600);
  M5.Lcd.fillScreen(BLACK);
  M5.Lcd.setTextColor(WHITE);
  M5.Lcd.setTextSize(2);

  // D7S 初期化
  D7S.begin();
  D7S.setAxis(SWITCH_AT_INSTALLATION);
  //start the initial installation procedure
  D7S.initialize();

  // Wifi 初期化
  M5.Lcd.print("Wifi Init");
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    M5.Lcd.print(".");
  }
  M5.Lcd.println("\nWifi Initialized");

  M5.Lcd.print("D7S Init");
  //wait until the D7S is ready (the initializing process is ended)
  while (!D7S.isReady()) {
    M5.Lcd.print(".");
    delay(500);
  }
  M5.Lcd.println("\nD7S Initialized");

  // 表示更新
  delay(500);
  M5.Lcd.clear();
  printData(0, 0);
}


/**
   ゆれ情報のBodyを生成する
*/
String makeInfoBody(float si, float pga) {
  return "{ \"value1\" : \""
         + String(si, 2)
         + String(pga, 2)

         + "\"}";
}

/**
   ゆれ開始のPOSTを送信する
*/
void postInfo(float si, float pga) {
  HTTPClient http;
  String requestBody = makeInfoBody(si, pga);
  Serial.println(requestBody);

  http.begin(INFO_URL);
  http.addHeader("Content-Type", "application/json");
  int httpCode = http.POST(requestBody);
  delay(200);
  http.end();
}

/**
   データをLCDに出力する
*/
void printData(float si, float pga) {
  M5.Lcd.fillRect(0, 0, 320, 40, BLACK);
  M5.Lcd.setCursor(0, 0);
  M5.Lcd.print("SI:");
  M5.Lcd.print(si);
  M5.Lcd.println("[m/s]");
  M5.Lcd.print("PGA:");
  M5.Lcd.print(pga);
  M5.Lcd.print("[m/s2]");
}

void loop() {
  static float oldSi = 0.0f;
  static float oldPGA = 0.0f;

  //checking if there is an earthquake occuring right now
  if (D7S.isEarthquakeOccuring()) {
    float si = D7S.getInstantaneusSI();
    float pga = D7S.getInstantaneusPGA();

    // 値が0から変化した際、ポルターガイスト検知を送信
    if (oldSi == 0.0f && oldPGA == 0.0f && (si > 0.0f || pga > 0.0f)) {
      postInfo(si, pga);
    }

    // 情報に変化があったら表示更新
    if (oldSi != si || oldPGA != pga) {
      printData(si, pga);
    }

    oldSi = si;
    oldPGA = pga;
  }
  delay(200);
}

IFTTT側

IFTTT側はこんな感じ
揺れ情報をうけとったら、LINEでケータイに通知します。

試験環境


こんな感じで置いてみる。ちなみにここはwi-fiがつながるため、試験には抜群の環境です。

実行結果


あくまでも手で揺らしてみた結果です。本当にお化けが出たわけではありませんよ。そのうち一晩放置して実験します。