• connect pin Vcc to 5V and try again.

    Hint: Some use a voltage divider for the Echo pin and some don't, check this Google search

    used code

    /* ESP8266 */
    var sensor = require("HC-SR04").connect(NodeMCU.D1,NodeMCU.D2,function(dist) {
            console.log(dist+" cm away");
    });
    
    
    /* PICO 
    var sensor = require("HC-SR04").connect(B3,B4,function(dist) {
            console.log(dist+" cm away");
    });
    */
    setInterval(function() {
            sensor.trigger(); // send pulse
    }, 500);
    

    distance HC-SR04 to

    • room ceiling 168.57866655316 cm
    • hand on top 10.12233265659 cm



About

Avatar for MaBe @MaBe started