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,082
Self opening box

Things used in this project

Hardware components

Espruino Pico
Espruino Pico
×1
Ultrasonic Sensor - HC-SR04
SparkFun 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

Edwin Martin

2 projects • 3 followers
Frontend webdeveloper

Comments