This is a simple modification of the espruino motion detector tutorial to work with the espruino pico. The main difference is which pins things are hooked up to, and my not using the LED strips, which I don’t own (hint hint, Santa).
First off, using your espruino pico, set it up at the standard left-most position on the bread board.
Then wire up as follows:
HC-SR501 | Espruino |
---|---|
VCC | VBAT (5v) |
OUT | A7 |
GND | GND |
The main difference here is that we use A7
instead of A1
because on the pico, A1
doesn’t come with a pin soldered on, so you can’t just plug a jumper into the bread board.
The code is basically the same as the tutorial, with the updates of removing the LED strip code and updating A1
to A7
var timeout;
function lightsOn() {
digitalWrite(LED1, 1);
console.log('light on ' + (new Date().toString()));
}
function lightsOff() {
digitalWrite(LED1,0);
}
setWatch(function(e) {
if (timeout!==undefined)
clearTimeout(timeout);
else {
lightsOn();
}
timeout = setTimeout(function() {
timeout = undefined;
lightsOff();
}, 1500);
}, A7, { repeat:true, edge: "rising" });
This thing is so much fun to toy around with. I had fun putting together the pico piano project too.