LoginSignup
4
2

More than 5 years have passed since last update.

IoTブレーカー(Obniz+サーボモーターで遠隔地からブレーカーを落とす)

Posted at

概要

玄関にあるブレーカーを遠隔操作で落とせるようにしました。

スマホ/スマートスピーカー>obniz>サーボ>球を落とす>ブレーカーが落ちる

LINE_MOVIE_1536745529745_ME-convert-180924.gif
仕組みは単純で、サーボモーターでボールを押し出しているだけです。
KIMG3705.JPG

材料

・Obniz
・サーボモーター
・重りになるボール(今回はテスト用としてガチャガチャのカプセルを使っています)
・紐
・L字金具

コード

IoTBreaker.html
<!-- HTML Example -->
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <script src="https://obniz.io/js/jquery-3.2.1.min.js"></script>
  <script src="https://unpkg.com/obniz@1.10.0/obniz.js"></script>
</head>
<body>

<div id="obniz-debug"></div>
<h1>ServoMotor</h1>
<input id="slider" type="range"  min="0" max="180" /><br>
  <button id="on">ON</button>
<button id="off">OFF</button>

<script>
var obniz = new Obniz("OBNIZ_ID_HERE");
obniz.onconnect = async function () {
  var servo = obniz.wired("ServoMotor", {gnd:0, vcc:1, signal:2});
      servo.angle(45.0); // half position
        await obniz.wait(1000);
      servo.angle(180.0); // 180 position


    $("#on").on("click",function(){
      servo.angle(45.0); // half position
    });


    $("#off").on("click",function(){
      servo.angle(180.0); // 180 position
    });
};

obniz.onclose = async function(){
   $("#slider").off('input');
};
</script>
</body>
</html>
4
2
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
4
2