2

I'm building a better mousetrap.

I want to add two wires to a traditional mousetrap: one on the metal bar that snaps when the trap is triggered, and one on the trigger bar that holds the trap in "armed" position until a mouse touches the bait.

The idea being: as long as the trap is set, that circuit will be closed (the cross bar and trigger bar will be touching).

When the trap is tripped, the bar and the trigger bar will no longer be touching, so that will open the circuit.

So, all I have to do is write a Python script that monitors when the GPIO pins find an open circuit, and email me to let me know the trap has been tripped.

Here's the question:

Is this possible to do without adding any other electrical components? Do I need to wire up anything else into the circuit to make this work? From a programming side, I have this handled. From the electricity side, I need guidance.

UPDATE Seems I might be able to do this by treating the mousetrap like a button? https://www.raspberrypi.org/documentation/usage/gpio/python/README.md

Button would always be in a pressed state until the trap is tripped, then it would be released?

2

You need to configure a GPIO to be an input with internal pull-up enabled or a resistor added to 3.3v near the Pi, see schematic. Connect this to one side of your mousetrap. The other side goes to one of the ground pins on the GPIO header.

When your trap is "set" the GPIO will be FALSE because the path-of-least-resistance is to ground. The GPIO will change to TRUE when the trap is sprung because now the only path is to 3.3v through the pull-up resistor. In your code you can either poll the pin in a loop or set up an event to be triggered when a rising edge is detected on the pin.

schematic

simulate this circuit – Schematic created using CircuitLab

I've shown a 4.7kOhm resistor here but if the mousetrap is a fair distance away and/or the contact resistance on the trap is a poor you may need a different value so that the path-of-least-resistance is through the mousetrap to gorund. If the mousetrap is a long way away or has a really bad contact then the Pi won't be able to drive enough current through the wires so you'll need look at alternative methods to buffer or transmit the signal from the mousetrap.

  • How do I calculate out the resistor that I need here? (I have a multi-meter, so I can measure out what the resistance of the mousetrap is...). – DrDamnit Jan 22 at 17:21
  • 1
    It needs to be more than the resistance between the two wires connected to the trap when it's set (measured from the Pi end, but not connected to the Pi) plus some room for error and drift. I'd not go lower than 1kOhm though to keep the current draw down: I = V/R. See also the answer from @Seamus that has some more details. – Roger Jones Jan 22 at 21:30
2

Good question (+1)... You've got the right idea in thinking of the bar and trigger as contacts in a switch/button. @RogerJones' answer may achieve your objective, but only if the bar and trigger have near zero resistance when the trap is "set".

To check that condition is met, you should measure the resistance between the bar and the trigger when they are in contact. Even if these two parts may are metal, they will not necessarily conduct electricity! Magnet wire is an example of this... the wire itself is copper (conductive), but there is a thin layer of varnish that serves to insulate the wire.

If you don't have, or can't borrow, a volt-ohm meter to measure the resistance, you can rig up something with batteries, a resistor and an LED. If you can light the LED by connecting the battery(ies) through the bar and trigger, then you're in business. If not, you might try scraping any insulation off the bar and trigger, and trying again.

You will also need to consider how you will make the connection from the bar and trigger to your Raspberry Pi's GPIO pins. Soldering sounds like a reasonable approach, if the bar and trigger are copper (or at least a base metal). Again soldering will require removal of any varnish or coating that may be applied to the bar and trigger. If you're not familiar with soldering, there are lots of videos available for the cost of a Google search. Otherwise, if you have other questions, feel free to follow up here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.