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.


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


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


  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="">
  <script src=""></script>

  <script src=""></script>
  <script src=""></script>

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


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});
  var sensor = obniz.wired("HC-SR505", { vcc:11, signal:10, gnd:9});
  sensor.onchange = function(detected){
    if (detected) {
  obniz.switch.onchange = function(state) {
    if (state === "left") {
  async function turnon() {
    await obniz.wait(500);
    await obniz.wait(500);
    dbx.filesUpload({path: '/obniz.txt', contents: "[ON] " + new Date() + "\n", mode: 'overwrite' })
    .catch(function(error) {