Introduction: IoT Critter Trap
In this Instructable I'm going to show you how to build an "Internet of Things" (IoT) live animal trap.
Live animal traps are nice if you have pests to rid your home of but you don’t want to do it through a means of killing the animal.
The problem we are faced with is constant monitoring of the trap. If you forget to check back frequently (usually a couple times per day), you risk having the animal die in the cage simply due to shock or anxiety. As a result, you end up being more cruel to the animal than if you had just put it out of its misery to begin with!
It is this problem that spawned my “IoT Critter Trap”.
This trap will connect locally to a defined WiFi network and send an SMS message when the trap has been sprung. You can see what happens when the trap is sprung by viewing my demo video. This is a very simple solution requiring very minimal hardware and nearly all of the code is simply copy & paste.
My number one goal is simplicity so anyone can build their own with minimal experience or effort. I believe I have accomplished that, but you can be the judge.
Interested? Read on...
Step 1: Gather the Materials
- Havahart 1025 trap or any similar design (Amazon). This design will work with nearly any Havahart trap that has a slanted door. You can see more models and sizes at http://havahart.com.
- Electric Imp imp001 dev kit (Amazon)
- Tilt Switch (Amazon) - Only one needed but they come in a 5 pack
- 2AA Battery Holder - w/Wires and Switch (Amazon)
- 2 Alkaline AA Batteries
Step 2: Welcome the Electric Imp
Internet connected devices have really taken off over the last few years. What used to be very difficult for skilled engineers and hobbyists can now be done in a matter of minutes by any skill level.
For this project I could have chosen to use Raspberry Pi, Arduino, Intel Edison, ESP8266, or one of the many other options available to us today. I decided to go with the Electric Imp because it lines up well with my goal of making this project very easy for anyone to build and use.
With most devices you need to hard-code your WiFi details and use special shields or components in order to get them connected. Electric Imp has created a proprietary WiFi setup solution that allows you to securely connect or re-configure in seconds using a smartphone or tablet. This means you can lend your IoT trap to friends or family to use all the same functionality using their own phone to connect it to their network as needed.
The other nice thing about the Imp is that all code is hosted in the cloud (for free). You can continually add features to your project via code without ever having to touch the physical device.
One thing that confuses most people that first see the Imp (including myself) is that it has the same form-factor as a standard SD card. The Imp is not an SD card. Inside that little card is an ARM microcontroller and WiFi adaptor. As an oversimplification, think of the Imp as an Arduino but with WiFi already built in and all code stored in the cloud.
If this is over your head, don't worry. This is very easy to setup. I just wanted to provide additional detail for those that are interested.
Step 3: Electric Imp - Initial Setup
The people behind Electric Imp have done a fantastic job documenting the ten simple steps required to get your Imp online. Follow their well documented steps here.
This consists of:
- Signing up for a free developer account on the Electric Imp site.
- Downloading the Electric Imp "Blink Up" App which is available for iOS or Android.
- Inserting the imp001 card into the SD card slot on the development board.
- Plug the Mini USB cable into your computer.
- Plug the Mini USB cable into the Imp to power it up.
- Launching the "Blink Up" app and following instructions to choose a WiFi network that you want the Imp to connect to and sending the blink code to your Imp.
- Confirming the Imp is good to go by seeing Green light on the card.
- Logging into the Electric Imp IDE and confirming that your new Imp shows up under "Unassigned Devices".
- Creating a new "model" in the Imp IDE for your trap. A model is simply a project to house your code to be used with the Imp.
- Adding some sample "hello world" code just to confirm everything works.
After following these simple steps, your device will be connected to the Internet and you will be ready to begin coding in the cloud using the Electric Imp IDE.
Step 4: Configure Twilio
In order to send text messages, we need a service that gives us the ability to send SMS messages via the Internet. Thankfully there is a company called "Twilio" that does exactly that (and more). They seem to have become the tool of choice for those that want to send SMS messages via IoT connected devices.
A free trial account is all we need for this purpose and it only takes a few minutes to set up.
- Create a new Twilio developer account at: https://www.twilio.com
- Enter your mobile phone number so they can send you a code to verify you are a human.
- Click the red button that says "Get your first Twilio number" as shown in my pic.
- Click "Choose this Number" on the next screen if you are happy with the number they have given you. You can also pick another number if desired.
- Make note of your phone number because we need it later.
- Click on "Trial Account" in the top right corner of the screen, then click "Account" and gather the following information under "API Credentials":
AuthToken (click the little padlock to see your token)
We will be using the Phone Number, AccountSID, and AuthToken you just harvested in the next step as we setup the code for your trap.
Your Twilio setup is now complete!
Step 5: Electric Imp - the Code
Don't let this next part scare you which it may if you are not a developer. 99% of this step is simply "copy & paste"
Imp programs consist of two parts and all code lives in the cloud. It is edited via the Imp IDE (Integrated Development Environment).
The first part is the "agent" code, which in our case acts like a middle-tier of a three tier application.
The second part is the "device" code. This is code that runs behind the scenes on the back-end and in this case, on the Imp. This is much like code that runs on a server for processing commands that come from the agent.
All you have to do is visit the following two URLs and copy & paste the code into the Imp IDE as follows.
Open this code in your text editor of choice and copy it to the left "agent" side of your Imp IDE. The only section that you must edit are the four lines under the section that says: /* INFO YOU NEED FROM TWITTER */. There you will put in the info that you harvested earlier when creating the Twitter app.
Open this code in your text editor of choice and copy it to the right "device" side of your Imp IDE. Nothing needs to be edited in this code.
After you are done steps 1 & 2, click the button that says "Build and Run".
At this point your code is all set and ready to be downloaded to the device once we bring it online.
Step 6: Assemble Components
Putting the hardware together is very simple. Polarity doesn't matter on the ball switch and we only have three connections to solder. See the attached wiring diagram for details.
The key here is to have the ball switch horizontal to the Imp board. In this position it will be OFF which is what we want.
Once you have the wiring done, use a bit of hot glue to secure the Imp to the battery housing as shown in my photo, making sure the On/Off switch is facing up.
Now attach the device to your trap in the location shown in my pictures. You can use anything to attach, but I prefer velcro tape.
Step 7: What About Battery Life?
The beauty of this simple design is that the circuit is never complete until the trap is sprung. Because of this, the battery will last a VERY long time if you don't catch anything.
When the trap is sprung, I have programmatically implemented a special "deep sleep" function of the Electric Imp to have it disconnect from WiFi after sending a message, sleep for a defined amount of time (1 hour by default), and then wake up to send another message. It repeats this cycle until you check the trap and reset it. By doing this it extends the battery life tremendously, likely lasting much longer than the life of the caught animal.
With all that said, I do recommend using Lithium batteries as shown in the picture. They will last much longer than standard alkaline batteries. UPDATE - I have left this device running for nearly three days straight with standard alkaline batteries and it is still waking up to send messages every hour! With this I would recommend using just plain ole batteries. No need to spend the extra money on Lithium unless it is very cold where you will be putting the trap.
Step 8: Set It and Forget It!
Now comes the fun part. You set the trap with a decent bait that won't decompose quickly and basically forget about it until you get that text message saying you caught something! I have to admit, the first time I caught a chipmunk in my garage with this I was overjoyed like a little kid in a candy store because I had proven that my little invention works and was actually quite handy!
A few words of warning:
- Make sure you test your trap in the exact location that it will be set. This helps ensure that your WiFi range will be acceptable, and you won't end up missing a notification that it tries to send but can't.
- Although I say "set it and forget it", you should still check the trap when you have time. You never know if something might have gone wrong with your code, the WiFi connection was lost, etc.
- IMPORTANT - Be sure to check your local laws regarding trapping of animals. Use at your own risk.
Step 9: Taking It Further
What is good can always be made better.
Here are some ideas:
- Incorporate a GSM shield so it can connect via cellular network and send text messages directly. I have done this using Arduino and a GSM shield, but the goal of this Instructable was simplicity and low cost which ruled that design out.
- Use a 3D printer or Laser Cutter to create a waterproof housing so this could be used outdoors in the elements.
I hope you enjoyed this instructable as much as I did making it.
Participated in the
Full Spectrum Laser Contest 2016
Participated in the
Hack Your Day Contest
Participated in the
Pest Control Challenge