Reading from sensor

Posted on
  • Hi. I'm trying to read from a PIR sensor. I'm aware that the sensor requires 5V, so I'm using a separate power supply for now. The problem is that as soon as I switch connect the power, the signal constantly detected by the pin. Even if I just touch a screwdriver to the pin, instead of using the sensor, a signal is detected.

    Am I doing something wrong?

    setWatch(function() {
      console.log("Movement detected");
    }, D1, {repeat:true, edge:"rising"});
    

    Thanks.

  • Have you also connected Ground on the sensor to ground on Puck.js? If you haven't, doing so would help a lot.

    Also, it depends on your sensor, but you might need a pull-down resistor. You can turn Espruino's built-in ones on just by adding pinMode(D1,"input_pulldown")

  • Hey. Thanks. I didn't know about the built-in pull-down resistors. I've given that a go.

    I found this page with a load of information.

    http://henrysbench.capnfatz.com/henrys-bench/arduino-sensors-and-input/arduino-hc-sr501-motion-sensor-tutorial/

    It says "the device requires nearly a minute to initialize". So that may have been part of the problem.

    I think it's working now. Thanks.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Reading from sensor

Posted by Avatar for jjok @jjok

Actions