1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

obniz で熱中症予防(温度変化をブザー音とLED信号で知らせる)

Last updated at Posted at 2021-10-13

生活の中で、何か役に立つものが作れたら良いなと考えています。
部屋が暑かったので、室温を図る、さらに熱中症の予防ができるものがあれば良いと考え作ってみました。
検証しやすくする為に、温度センサーの設定を、31℃以下を平温、31-32℃をやや高温、32℃以上を高温としています。

下準備
① obnizスターターキットの用意
② obnizの端子にパーツを接続
   ブザー:signal:0, vcc:1, gnd:2
   LEDライト:gnd:8, green:7, yellow:6, red:5 (逆さまに装着)
   温度センサー:signal:9, vcc:10, gnd:11

実行
 obniz HTMLエディタを開き、以下のコードを入力。

    <html>
      <head>
        <script src="https://unpkg.com/obniz@3.x/obniz.js"></script>
      </head>
      <body>
    <script>
      var obniz = new Obniz("OBNIZ_ID_HERE"); // ここに自身のobniz IDを入力する

      obniz.onconnect = async function () { 
        var speaker = obniz.wired("Keyestudio_Buzzer", {signal:0, vcc:1, gnd:2});
        var light = obniz.wired("Keyestudio_TrafficLight", {gnd:8, green:7, yellow:6, red:5});
        var tempsens = obniz.wired("Keyestudio_TemperatureSensor", {signal:9, vcc:10, gnd:11});

        let i =0;
        while(true){
          i++;

          if (i > 3600) {
            speaker.stop();
            break;
          }

          const temp = await tempsens.getWait(); // awaitを利用
          console.log(temp);

          if (temp < 31) { // 31℃未満(平温の設定)
            light.single("green"); // green
            await obniz.wait(100);
            light.green.off();
            await obniz.wait(900);
            continue;

          } else if (temp < 32) { // 31-32℃(やや高温の設定)
            speaker.play(130.813) // 130.813 Hz;「ド」
            light.single("yellow"); // yellow
            await obniz.wait(200);
            speaker.stop();
            light.yellow.off();
            await obniz.wait(800);
            continue;

          } else { // 32℃以上(高温の設定)
            speaker.play(261.626) // 261.626 Hz;「次のド」
            light.single("red"); // red
            await obniz.wait(200);
            speaker.stop();
            light.red.off();
            await obniz.wait(200);
            continue;

        }
      }
      }
    </script>
      </body>
    </html>

工夫を要した箇所
 ①3つのパーツがあるので、各パーツの配置を少し工夫した。
 ②警報音を分かりやすくするため、
   やや高温の時は低温の「ド」を長く少なく鳴らす設定
   高温の時は1音階上の「ド」を短く頻回に鳴らす設定 にした。
 ③その他
  「かえるのうた 歌詞付き」を作るときに、端子の番号の小さい方へ刺さっている
   パーツから順番にコードを書くことが必要であったので、今回は順番を意識し、
   エラーは出なかった。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?