Introduction: Better Smarter Mousetrap

About: I love home automation. I hate home automation.

Ralph Waldo Emerson once said "build a better mousetrap, and the world will beat a path to your door." Perhaps that’s what motivated Tom to keep trying to catch Jerry using ever more elaborate Rube Goldberg-esq traps that ultimately failed. Few things can be said to be inspired by both Ralph Waldo Emerson and the Tom & Jerry cartoon, but the better mousetrap is one of them. With a smattering of technology and peanut butter, we can make that better mousetrap a reality.

With winter fast upon us, I’ve already been victim to the annual rodent indoor migration. I happened across one of them in the basement while looking for something. Scared the crap out of me. Instead of waiting for signs of mice, I thought it might be a good idea to set up a semi-permanent trap.

Just because we don’t like having Mrs. Frisby in our house doesn’t mean we have to use a death trap. I wanted to build a trap that doesn’t kill. Imagine a semi-permanent trap that’s set out in basement, garage, or attic. I don’t want to have to go to the basement or attic to check the trap everyday. And I don’t want the little critters to die of starvation while they’re detained. So I need the trap to notify me via email the moment a mouse is captured. Since the traps are also located in dark places, I also want an LED as an easy line-of-sight indicator.

Interesting thing about mice is that they’re territorial. If you have a couple of mice in close quarters with no where to go, things might deteriorate into a battle royale. Could get pretty nasty, and defeats the goal of a humane trap. The best solution for catching multiple mice is to have more than one trap, and make each trap only let in a single mouse.

With those things in mind, these are my design goals for making a real smart mousetrap.

1) Easy to build, escape proof, live and let live
2) Notifies me the moment a mouse is caught, via email and audible notification
3) Trap only lets in one mouse at a time
4) Simple LED indicator to tell you if there's a mouse in the trap

First the video demo, then the steps for the build.

See next step for parts list.

Step 1: Parts List & Wiring

Parts List:

1. Spark Core ($39) or the Photon shipping in 2015 ($19)

2. Bucket ($5)

3. Large piece of cardboard

4. PIR Motion Sensor ($3, cheaper on ebay)

5. DHT11 Tempearture/Humidity Sensor ($2, cheaper on ebay)

6. Hobby Servo ($3)

7. Pieces of plastic or sheet metal, whatever you have laying around.

8. Resistors, 220 Ohm and 10k Ohm

9. Dupont male-female cables

Wire up the Spark Core breadboard circuit following this wiring diagram. Click to enlarge.

Your circuit should look something like this.

I included a temperature sensor in the circuit because they're so inexpensive.

Step 2: Assemble Trap Arm

Next, we need to assemble the trap arm using the servo. The trap arm is what moves the "occupied" door in and out of position, and prevents more than one mouse in the trap. I'll show you the end result of this step, and then detail how I made it. You may take liberties with the supplies you have available.

This video is looking at the underside of the card board top. You can see how the arm moves the door into position, and latches it in place.

Cut the card bard into shape (with a hole big enough for a mouse to fall through). Cut some pieces for an arm and a door and attach to the arm of the servo. For the parts, I used left over vinyl siding material. You can use sheet metal or any other flat, stiff material that you can cut to shape. It should look something like the following series of pictures.

Cut a hole roughly the shape of the servo motor. Poke the servo through the card board. The servo should rest on the extra plastic protrusions and not fall through.

Create a sort of slanted latch for the door, so that the door gets "locked" into place and the latch helps hold it in, in case mice from above want to get in.

Step 3: Assemble Motion Sensor

Cut a hole on top of the card board just big enough to poke the motion sensor's globe through. This is what will tell us when a mouse falls into the trap.

Step 4: Programming

There are two software pieces to program. The Spark Core uses MQTT to talk to the home automation server called OpenHAB. The MQTT broker I'm using is called Mosquitto. Aside from programming the Spark Core, you'll have to decide where OpenHAB and Mosquitto will be installed. They can be installed on a Raspberry Pi (Linux) or a Windows or Mac PC. It's up to you, and it really doesn't make much of a difference other than power consumption. The configuration is the same.

Download the attached Spark Core program to your Spark Core. If you need help, follow the Spark Core's getting-started-guide.

Install Mosquitto using this download link.

Install OpenHAB using this wiki. Familiarize yourself with the configuration files like items, sitemap, and rules. Follow the OpenHAB configuration to set up the OpenHAB interface.


Switch itm_mousetrap_basement_trap_sta "Basement Trap Status" <mymouse>
DateTime itm_mousetrap_basement_time "Trap Time [%1$tA, %1$tm/%1$td, %1$tI:%1$tM %1$tp]"
DateTime itm_mousetrap_heartbeat "Heartbeat Time [%1$tA, %1$tm/%1$td, %1$tI:%1$tM %1$tp]"
Number itm_mousetrap_basement_temp "Temp [%.1f °F]" <temperature> (All) {mqtt="<[mymosquitto:mouse_basement_temp:state:default]"}
Switch itm_mousetrap_basement_be_lonely "Lonely Mouse Mode"  {mqtt=">[mymosquitto:9996:command:ON:1],>[mymosquitto:9995:command:OFF:0]"}
Number itm_mousetrap_basement_trap_mqtt "trap mqtt" (ALL) {mqtt="<[mymosquitto:mouse_basement_trap_mouse:state:default]"}
Switch itm_mouse_basement_man_rst_mqtt "Mouse Basement mqtt ahhh" <blank> {mqtt=">[mymosquitto:9997:command:ON:1],>[mymosquitto:9997:command:OFF:0]"

Text label="Mouse Traps" icon="firstfloor"
	Frame label=""
		Switch item=itm_mousetrap_vacation
	Frame label="Basement Mouse Traps"
                Switch item=itm_mousetrap_basement_trap_sta mappings=[OFF="Reset"]
                Text item=itm_mousetrap_basement_time
                Text item=itm_mousetrap_basement_temp
                Switch item=itm_mousetrap_basement_be_lonely  
	} //Basement Mouse Traps
}//end frame

rule "Mouse Trap Basement Mouse Detected"
		Item itm_mousetrap_basement_trap_mqtt received update
		if (itm_mousetrap_basement_trap_mqtt.state == 1)
			sendCommand(itm_mousetrap_basement_trap_sta, ON)
			postUpdate(itm_mousetrap_basement_time, new DateTimeType())
			sendMail("", "subject mouse trap" , "a mouse in trap!")
			say("mouse in trap!")
		else	//reset
			sendCommand(itm_mousetrap_basement_trap_sta, OFF)
end //Mouse Trap Basement Mouse Detected

rule "Mouse Trap Basement Reset"
		Item itm_mousetrap_basement_trap_sta received update
		if (itm_mousetrap_basement_trap_sta.state == OFF)
			sendCommand(itm_mouse_basement_man_rst_mqtt, ON)
end //mouse trap basement reset

Open the openhab.cfg file, edit the email settings like this:

######################## Mail Action configuration ####################################
# The SMTP server hostname, e.g. ""

# the SMTP port to use (optional, defaults to 25 (resp. 587 for TLS))

# the username and password if the SMTP server requires authentication, no

# The email address to use for sending mails

# set to "true", if TLS should be used for the connection
# (optional, defaults to false)

That's it.

Step 5: Mouse

Here's a mouse that was caught with the trap. At the time, I didn't have the smarts built yet, but the trap itself works pretty well.

Step 6: More Than Just a Mouse Trap

This mousetrap project utilizes sensor inputs and actuator outputs on a wifi-connected Spark Core. It interfaces with a sophisticated home automation system called OpenHAB. The techniques used in this project can be easily ported over to other home automation projects. For example, this Home Automation project can be adapted to use Spark Core instead of pure Arduino.

The Spark Core can be used for various wifi-connected sensor and actuator nodes, all controlled and monitored via the OpenHAB app.

Enchanted Objects

Participated in the
Enchanted Objects

Formlabs Contest

Participated in the
Formlabs Contest

Winterize Challenge

Participated in the
Winterize Challenge