A Better Livetrap

by buteomont in Circuits > Gadgets

25 Views, 0 Favorites, 0 Comments

A Better Livetrap

Mouse in trap.jpg

A Better Mouse Trap


We live out in the country. Living in the country is wonderful, but there are some things that are a lot less “wonderful” than others. One of these things is that mice sometimes get into the house. So, what to do about it? Catch them and relocate them!

Being an animal lover, I can’t just kill the mice. They’re just trying to live, just like I am. When I tell folks this, I usually get comments like:

  1. “It’s more humane to snap their neck”
  2. “Mice carry diseases and should be drowned”
  3. “It’s inhumane to relocate them; they’ll starve to death or be eaten by a hawk”
  4. “Unless you release them at least 5 miles away they’ll just come back”


Well, I can tell you from experience that none of these are true. But that’s not what this instructable is about. It’s about a live trap for mice and other small animals. And this live trap has a special feature – it will tell you when it has caught something!

Supplies

  1. About 3 ft2 of ¼” hardware cloth
  2. A wire coat hanger
  3. A flat piece of plastic about 5 inches square (for the trigger)
  4. A flat piece of sheet metal, like an old license plate (for the door)
  5. Some plastic scrap (for the bell crank and mount)
  6. An ESP8266-01s or similar processor
  7. Two AAA batteries and a holder
  8. A microswitch
  9. Two 10K resistors
  10. Two capacitors, one 10µF and one 1µF
  11. A USB to ESP01 adapter (for programming the processor)
  12. Fine solder and an equally fine-tipped soldering iron
  13. About an inch of wire-wrap wire

Theory of Operation

action.png
schematic.png

Refer to the diagram. The trap is essentially a wire cage with a top-hinged door on one end that is held open by a pin. The pin is connected by way of a bell crank to a treadle in the back of the cage. When the mouse (1) enters the cage to eat the delicious peanut butter (2) in the back, it steps on the treadle (3), which rotates the bell crank (4) and pulls the pin that is holding the door up (5), causing it to swing down (6) and block the mouse’s escape. A wire latch also swings down (7) to prevent the mouse from pulling the door back open and absconding.

When the door swings down, it releases the lever on a microswitch (8), causing the reset pin of the ESP8266 to momentarily go low through C2 (see schematic). This wakes the processor, which then checks to see the status of the switch. If the switch is closed, that means that the trap has been triggered and it likely contains a rascally rodent.

The processor is also programmed to wake up after a set period of time (30 minutes on mine), just to prove that it’s still working. In either case, it connects to the WiFi, contacts the MQTT broker, and sends the status information. This is a good thing to do for several reasons:

  1. If a mouse is in the trap and you miss the first message (or forget to deal with it), it will continue to report the trap as triggered. It would be cruel to leave the little guy in there too long without water or food.
  2. If you don’t receive any messages for a time longer than the sleep period, there must be a problem (batteries gone flat?) and you should fix it or disable the trap. You really don’t want to leave the trap set without the notifications working unless it is in a place where you can check on it often.
  3. There may be a glitch in your wifi that prevents the processor from contacting the broker when the trap is tripped. Regular status updates will prevent the tripped status from getting lost or ignored.

Downloads

The Hardware

Mousetrap1.jpg
MousetrapNotifier-closeup.jpg

The trap itself is not much more than a ¼” hardware cloth cage with a top-hinged door on one end. I used ½” hardware cloth on the first one, but found out that the smaller beasts can squeeze through it.1 I wound up covering the entire cage with a smaller screen to keep the little buggers in.

The door should be heavy enough to swing closed quickly, but not so heavy that it will hurt your “guest” if it hits him. Use small rings of stiff wire to hinge it at the top. It must swing freely and cover the opening completely. A triangular bail should be fashioned from a wire coat hanger and affixed where it will swing freely from the top of the cage, perpendicular to the door. This will swing down when the door closes and prevent the crafty critter from pulling it open.

As you can see in the schematic diagram, the circuitry is very simple. So simple, in fact, that a printed circuit board is not needed – you can just use point-to-point wiring right on the microswitch terminals. How you mount it on top of the trap is up to you. I 3D printed a simple housing for mine that houses the switch and battery holder; the FreeCAD and STL files are on github in the resources directory if you want to duplicate it.

The Software

bodge1.jpg
bodge2.jpg

The program used in the ESP8266 is a generic one that I wrote to use in many other projects, and you can download it from my github repository. It has a configuration web page that allows you to customize it with your particular details.

The first time you run the program after downloading it to the processor, it will set up its own WiFi network with the SSID of “monitor” and a password of “password”. Connect to this network with your computer and access the web server at 192.168.4.1. The settings are self-explanatory.

If you don’t want to use the web page, you can leave the ESP device plugged into the USB port and configure it through a serial monitor2. Or, if it has already been set up and you just want to change a setting, you can do it by sending it an MQTT message3. This is not nearly as easy as using the web page, though.

Downloading the firmware to the processor is explained in other instructables and will not be repeated here. I used PlatformIO to write the program, but it should work in the Arduino IDE if you copy the files to the right directory and rename main.cpp to something like mousetrap.ino.

IMPORTANT! This project uses the wake-on-timer feature of the ESP8266. You must connect I/O port D0 (gpio3 on the ESP8266-01s) to the reset pin! If you don’t do this, it won’t wake up to give you the periodic status reports. If you’re using a processor other than the ESP8266-01(s), that should be a piece of cake. However, this particular processor doesn’t present that pin to the connector, so you have to do a little micro-soldering to do it. See the photos above – it’s the last pin on the top left of the processor chip. It takes a good magnifying glass and a steady hand, but you can do it! Wire-wrap wire works best.

Home Assistant

Of course, once a notification from the trap gets to the MQTT broker, you can do a multitude of things with it. For example, you could have another ESP processor listen for it and turn on a light or sound a buzzer. I set up my Home Assistant smart home software to watch for the message and announce “There’s a mouse in the mousetrap!” over the speakers that I have sprinkled throughout the house. My Home Assistant also monitors how often a message comes in from the trap, and will send a notice to my phone telling me to check the batteries if one is not received in a timely manner. Under normal usage, two AAA batteries should last for at least a couple of months.

Here is my YAML to tell Home Assistant to watch for a “tripped” message from the trap. You will of course need to customize it for your installation. The script.announce bit is a script for sending text-to-speech messages to my speakers, which you will need to write for your particular setup if that’s what you want it to do. How to set up speakers in Home Assistant is beyond the scope of this instructable.

alias: Announce Mouse Trap Tripped
description: >-
Repeats announcement every time the mouse trap sends in a status update of
"tripped" to remind us if we miss or ignore the first one.
triggers:
- trigger: mqtt
topic: mousetrap/status
payload: tripped
conditions: []
actions:
- action: script.announce
metadata: {}
data:
message: There is a mouse in the mouse trap.
attention_sound: one beep.mp3
loop_count: 2
mode: single




Summary

This has been a fun and useful project, and is a natural extension of my Home Assistant installation. I hope that you too will enjoy building it. Be nice to your furry friends. You may be bigger, stronger, and smarter than they are, but they were put on this planet just like you were and, like you, just want to survive!

Oh, and that old saying that says “Build a better mouse trap and the world will beat a path to your door”? Turns out that’s not true!

Downloads

Notes

1. Well, halfway through it, anyway. I found one that had become stuck while trying to squeeze through the mesh. I had to cut the wire to get him loose, but he was OK.

2. This is very rudimentary. Sending a carriage return on a line by itself (just pressing enter) will list the possible settings. Changing a setting is done by entering name/value pairs (name=value), with no spaces or with the value in quotes. Backspaces are not supported; if you make a mistake while typing just press enter and start over.

3. Be sure to set the “retain” flag. Remember that the processor is asleep most of the time. Also remember to remove the message from the broker after the processor wakes up and sees it, or else it will continue to make your change every time it wakes up. If you’re in a hurry, you can always just trip the switch to wake it up immediately.