Check if sliding door is closed

Posted on
  • Hey guys!

    I want to check if the sliding door of my terrarium is closed using the Puck.js (light green LED if it is closed, else light red LED). I found a cool tutorial, where I can see how to do this using a magnet.

    But I think a better solution would be to attach 2 wires to the Puck.js and then put a metal plate on the side of the door. If the door is closed, the circuits is also closed and otherwise it's open.

    I'm not very familiar with the Puck.js so far, so I have two questions for this idea:

    1. To which pins should I connect the two wires?
    2. How can I determine, if the two wires are connected or not?

    Thanks for your help!

  • Sat 2017.04.15

    Although my experience is with the Pico, my guess is that any GPIO pin will work. The software function you are after is digitalRead()­bal_digitalRead

    Use this tutorial to garner insight. Wire Loop Game

    One wire to ground. The other through a 10K to the GPIO pin. Or rely on the internal pull-up.

  • Hi Robin

    Thanks for you response! It works using pinMode(PIN, "input_pullup") and digitalRead :-)

  • Great! Glad you got it sorted! You can also use setWatch if you want a function to be called when the pin changes state.

    Only think to watch out for is that if the door is normally closed (and so the contacts are normally closed) then pullup will be wasting some power (as it's like a 40k resistor is across the battery all the time) so your battery may not last too long.

    You could use pinMode(...pullup);digitalRead();pinMode­("input") to use the pullup resistor only when you're reading the state of the door, and not at other times

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

Check if sliding door is closed

Posted by Avatar for Tineler @Tineler