Safely catching mice is a better way of fixing a problem, and using Raspberry Pi means it needs less supervision. In the new issue of The MagPi magazine, Rob Zwetsloot takes a look with the maker, Andrew Taylor.
With some IoT projects, it’s the little things that help. For example, take Andrew Taylor, who did the good thing of setting up a humane mousetrap. However, checking it to see if any mice had been caught in it, while necessary, was getting a little boring.
“If a mouse had gone in and I did not check it, the mouse would quickly run out of food and water!” Andrew tells us. “Having been interested in Raspberry Pi for a couple of years and having recently begun learning Python using the Enviro+ environment sensors, I figured a Raspberry Pi with a motion sensor would be an ideal way to check.”
It’s a fairly simple setup, one commonly used in CCTV builds and some fun ‘parent detectors’ on the Raspberry Pi Foundation’s projects site.
“I came across a couple of automated mousetraps that people had made from scratch, but wanting to keep it simple and cheap,” Andrew explains. “I wanted to use off-the-shelf parts where possible and keep costs down. The Pi Hut had a tutorial for a DIY burglar alarm utilising a PIR sensor, IFTTT, and Pushbullet, which seemed like an ideal starting point.”
IFTTT – If This Then That – is an online service popular with IoT folks. It’s great for small things like cross-posting images on social media services, or sending a push notification when motion is detected in a mousetrap.
“I have only had one mouse since, but it worked!” Andrew says. “I was averaging about 800 detections a day and suddenly got well over a 1000. Sure enough, there was a mouse in the trap which I released shortly afterwards. I do tend to notice that the values fluctuate a bit, so it is always worth checking over the previous day’s results to see if it is notably higher.”
You might think that 800 push notifications a day is far worse than just occasionally checking your garage, and you’d be right, so Andrew tweaked the code a bit: “The code examples I found sent a notification for each movement detection – which I knew would be rather annoying, considering how randomly PIR sensors sometimes seem to trigger. My script instead logs any hits at a max of 1 per 30 seconds and then triggers a notification once every 24 hours, meaning I just get one notification a day.”
Beat a path
There’s always room for improvement, as Andrew explains: “I intend to improve the code so that it can record running averages and give an indication as to whether it believes there has been a significant spike that might necessitate me checking it out.”
Whilst the aim of the project was to keep costs down, Andrew is tempted to experiment by adding a camera, and possibly a light, so he can have a peek remotely when there has been a spike in the readings and to see if it is a false alarm. Which, as he admits, is “a new height in laziness!”
The MagPi #108 out NOW!
You can grab the brand-new issue right now from the Raspberry Pi Press store, or via our app on Android or iOS. You can also pick it up from supermarkets and newsagents. There’s also a free PDF you can download.