edge lab LIVE! starts Tuesday in Munich. Grab a workshop seat and take home the board you build on. Code FRIEND-HACKSTER saves 20%. () Learn more!
Edwin Martin
Published © CC BY-SA

Self opening box

Hold you hand near the box and it will open automatically.

BeginnerShowcase (no instructions)2 hours4,595
Self opening box

Things used in this project

Hardware components

Espruino Pico
Espruino Pico
×1
Ultrasonic Sensor - HC-SR04
SparkFun Electronics Ultrasonic Sensor - HC-SR04
×1
Micro servo motor
×1

Software apps and online services

Espruino web IDE

Story

Read more

Schematics

Diagram

Fritzing scheme

Code

openbox.js

JavaScript
Source code for the Espruino.
var servo = require("servo").connect(B1);

var sensor = require("HC-SR04").connect(A6,A5,function(dist) {

var open = false;
servo.move(1);

 if (dist > 5 && dist < 20) {
   console.log("open ("+Math.round(dist)+")");
   servo.move(0);
 } else {
   console.log("close ("+Math.round(dist)+")");
 servo.move(1);
 }
});
setInterval(function() {
 sensor.trigger();
}, 2000);

Credits

Edwin Martin
6 projects • 4 followers
Frontend webdeveloper

Comments