obniz developer team
Published

Lavatory Vacant/Occupied Sign ~Human Detection Sensor~

Let's make lavatory vacant/occupied sign to check whether it is available or not!

BeginnerFull instructions provided934

Things used in this project

Hardware components

obniz
Cambrian Robotics obniz
×1
EKMC1601111
×1
battery or USB adaptor & cable
×1

Story

Read more

Code

untitled_file.html

HTML
<!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8">
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
 <script  src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="  crossorigin="anonymous"></script>
 <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
 <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
 <script src="https://unpkg.com/obniz@1.9.1/obniz.js"></script>
</head>
<body>
<div id="obniz-debug"></div>
<br>
<div class="text-center">
 <h1> Lavatory Signal </h1>
</div>
<div id="a"><img src="https://www.dropbox.com/s/e7nqlug3wz4ku5v/in_notuse.jpg?raw=1" id="image" width="100%"></div>
<h1 id="print"></h1>
<div id="sens1"></div>
<script>
var sensorAdd = 0;
/* This will be over written on obniz.io webapp page */
var obniz = new Obniz("OBNIZ_ID_HERE");
obniz.onconnect = async function () {
 var sensor = obniz.wired("PaPIRsVZ", {gnd:0, signal:1, vcc:2});
 sensor.onchange = function(val){
   if (val) {
     sensorAdd += 1;
     $("#sens1").text("sensorAdd:"+sensorAdd);
   }
 }
 function update() {
   if (sensorAdd == 0) {
     $("#print").text("Empty");
     $("#image").attr("src", "https://www.dropbox.com/s/e7nqlug3wz4ku5v/in_notuse.jpg?raw=1");
   } else if (sensorAdd != 0) {
     $("#print").text("Occupied");
     $("#image").attr("src", "https://www.dropbox.com/s/x5wlr6kwmq15mrp/in_use.jpg?raw=1");
   }
   sensorAdd = 0;
   $("#sens1").text("sensorAdd:"+sensorAdd);
 }
 setInterval(update, 2000) 
}
</script>
</body>
</html> 

Credits

obniz developer team

obniz developer team

80 projects • 32 followers
Development board "obniz" is controlled via the internet.

Comments