Human detect and time record lamp

このエントリーをはてなブックマークに追加

What's this

Home IoT Kit Example

This makes your room lamp smarter.
It turn on automatically when it detect human. And It also record the time at a file on Dropbox.

Materials

  • obniz
  • Power supply for obniz
  • PIR sensor (of IoT Home Kit)
  • Servo Motor (of IoT Home Kit)

Steps

First, Attach a servo motor to a switch on the wall.

The way you attach depends on your switch.

And connect a PIR sensor and a servo motor to an obniz. Then connect to a power.

Write and Run a program.
This example program has a manual method.
Turn a switch to the left, Your servo will move.
Tune the value on the example program to work correctly.

And Please specify dropbox API key. You can see how to on Lessons.

Let's test.

Your servo will move when you close to a sensor.
And you will see a file which contain the time on your dropbox.

This time I use HTML But nodejs will work more sufficiently. It works persistently.

Also you might want to turn off automatically or record more information to a file. It seems fun

Program

<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css">
  <script src="https://obniz.io/js/jquery-3.2.1.min.js"></script>

  <script src="https://unpkg.com/obniz@2.0.2/obniz.js"></script>
  <script src="https://unpkg.com/dropbox@4.0.3/dist/Dropbox-sdk.min.js"></script>
  
</head>
<body>

<div id="obniz-debug"></div>

<script>

var dbx = new Dropbox.Dropbox({ accessToken: '<YOUR ACCESS TOKEN HERE>' });
  
var obniz = new Obniz("OBNIZ_ID_HERE");

obniz.onconnect = async function () {
  
  var servo = obniz.wired("ServoMotor", {signal:2, vcc:1, gnd:0});
  servo.angle(90.0);
  
  var sensor = obniz.wired("HC-SR505", { vcc:11, signal:10, gnd:9});
  sensor.onchange = function(detected){
    if (detected) {
      turnon();
    }
  }
  
  obniz.switch.onchange = function(state) {
    if (state === "left") {
      turnon();
    }
  }
  
  async function turnon() {
    await obniz.wait(500);
    servo.angle(40.0);
    await obniz.wait(500);
    servo.angle(90.0);
    
    dbx.filesUpload({path: '/obniz.txt', contents: "[ON] " + new Date() + "\n", mode: 'overwrite' })
    .catch(function(error) {
      alert(error);
    });
  }
}

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

You will Get in Few Days

Circuit for Starter “obniz Board” is available on Amazon and other online stores.
You can get it at below

Our products and resellers

Forum

Visit our developer’s forum to discuss and discover technologies.

Forum

Contact

Feel free to contact out support and technical team.

Contact us