Sending a text

First, I am really enjoying this group. I have looked through 187 projects and tons of posts, but still feel lost. I am not a programmer or a hardware guy. I bought an Imp to do one thing, send a text message when I have a bird. I assist with bird banding to track migration and design bird traps. As an input to the Imp I can have either a switch closure or a +5V signal coming from the trap relay. Not sure which is best or which pins to use. I could really use help on which code or code snippets to use. I looked at the washing machine text project, but it’s still kind of over my head. I would just like a text to my phone that says “Bird in trap #1”, when the trap relay actuates.

So far I have blinked my Imp and got the device log to say “Hello from the device”, but that’s it. Any help or advice would be greatly appreciated.


First of all, you need to have WiFi operating within the range of the bird trap.

Next, to use real text messaging, you would get a Twilio account with it’s own phone number. From Twilio, it can text any phone, and you can actually reply back. But it does cost money.

Otherwise, I know that I can send an email to my smartphone, which is free. The Imp Agent can also send an email to your phone using a remote server like Mailgun.

Likewise, if you have your own website, the agent could use your website to send an email. I use my website to send emails.

I’m trying to imagine how a bird trap would be near a WiFi connection, but that would be a requirement.

To not require WiFi, you would use a different controller (not the Imp) that has it’s own SIM card and texting account with a cell phone carrier. That would cost money too.

Thanks for the info. There is outdoor wifi in the area of the demo cage. I set up a trial Twilio and thought it was free to use. If not, I will look into sending an email, which would be fine. Any thoughts on best pins to use on the Imp for a switch signal or 5V signal? If I can get this to work for the demo cage, I might consider a different SIM card controller in the future for multiple cages.

Doesn’t matter which pin you use.
Will the Imp be battery powered, or can you use a 5V USB power supply?

If it’s battery powered, you will put the imp to sleep and wake-up with pin 2 (the trap switch).

No need to sleep if the Imp has external power.

You are not switching 5V. The pin is tied-hi to the imp’s own 3.3V. The switch merely brings the pin to ground through the ti-hi resistor. An LED on a different pin would be nice for testing your trap switch. The switch can be a simple as a magnetic reed switch somewhere on the trap. You might even want to use other sensors to detect if a bird is nearby, but doesn’t trip the switch. You could even put your trap on a load cell and the imp would know how much the bird weighs. Let the Imp trip the trap only if the weight is at a certain level. Possibilities are endless.

What you do depends on how much money you want to spend, and having the power requirements to drive things (sensors and devices) other than a simple switch.

Thanks again. I am still finding this all confusing, but fascinating. I signed up with Mailgun and modified the script for the IMP Agent. I now can get an email on my phone that has a subject of Bird Alert, and a message of Bird at Trap #1, when I hit Build and Run. The IMP is offline. What script do I put on the device side to tell it to email me.

The Imp device can only talk to the Imp agent, so the hardware device tells the server agent to send you an email. Here’s some code showing the linking between the device and the agent. It’ll need double-checking as it’s the first time I’ve free-handed code into a forum post :D.

agent.send (“trap”, status)

device.on (“trap”, function(status)
// mailgun code here with variable “status” having the same value as on the device
// this block of code only runs when the device does an agent.send (“trap”,data)

The agent is the “middle-man” that does the talking between the physical imp and the internet. When the imp sees the bird trap switch, it tells the agent to send out the email. If any website needs to do something to your imp, the website POSTS to the agent and the agent tells the imp what to do.

Without much programming experience, or hardware electronics experience, I can see where you might find this stuff confusing or mysterious.

Well, I appreciate the help from people. It is starting to make a bit more sense. Question: Is there a free service that provides texts? I ask because the Mailgun seemed to take about 10 minutes to deliver the email to my phone from the time I hit build and run. I realize that it’s bouncing around a bit, but I would like something quicker.

I’ve used the “Yo” app. It’s not SMS but it’s free, quick and elegantly simple. I can post my basic Yo code if you’re interested.

For simple messaging, I use Twitter. We have a Twitter library that you can use: just add it to your agent and it’ll send Tweets from an account you create for the purpose. You just follow that account with your own, and your phone’s Twitter app gets all the messages sent when a bird enters the trap.

So, device (hardware) detects bird; devices messages agent (server); agent Tweets; your phone shows you the Tweet. Nice and straightforward.

Twitter … I always forget about Twitter. That might be a good solution.

Agree with @smittytone that Twitter is very handy for near real time notifications if you have a twitter account. You can also set it up to send direct messages to avoid broadcasting your messages to all your followers.

Other 3rd party web services worth looking at include Temboo ( and IFTTT (, which have various types of messaging libraries. There are some web services available which also offer a limited number of free SMS per day (e.g. - I believe you can get 5 free SMS per day).

Not free, but Twilio works very well for sending texts and within the US it’s $0.0075 (3/4 of 1 cent) per message. There’s a library so integration is really easy.

So many choices! Thanks guys, still getting my head around it.

What city do you live in or near?
There has to be someone that could help you in person …
like an electronic nerd type of guy (like myself).
What you’re doing is an important project. I would help for free.

Max, thanks for the offer of help. Everyone here has been great. I am going to try something that Rocketfire sent me. I am trying to learn about this device, code, etc, but will certainly reach out to people when I’m stuck. I’m in Northern New Jersey.

This is not Northern New Jersey, but it’s a good place to reach out:

They will be able to connect you with the hardware folks you need for construction.

So, with the forum being down for a while I did some playing around on my own. Thanks to some ideas and code from Rocketfire, and some other code I found online, I was able to get my IMP to send me a Yo, when I close a switch. This may seem trivial to most of you, but is exciting to me. I still need to improve the code a bit and maybe add a switch de-bounce code, but I will be able to have any trap send me a notification, which is great.


Many times, a switch closure may be of a short duration, or a quick succession of on/off durations. If your trap switch is a type that closes and stays closed, you really don’t need to debounce. You merely need to have a timer that makes sure the switch has stayed closed for like 1 second or more. If after 1 second, it is still closed, you then say it is closed. That would ‘debounce’ the very beginning of the switch closing, where the metal contacts begin to touch. Likewise, you would look for an ‘open’ that has stayed opened for at least 1 second.

If you have a switch that is momentarily closed for a very short duration, and then reopens (like a momentary pushbutton), then you need to utilize the Imp Debounce code that someone already made.

See this:

And I can tell you’re addicted to the imp now.
For future improvements, you could tell if the trap has moved, but not tripped.
Perhaps something is jiggling it, but not tripping it?
Using a sensor like this:

Well, maybe not addicted, but enthused. I did order a second IMP. I know it can do many, many more things, but right now one is enough. I could use some help with Yo. If I go to the Yo Dashboard, I can send myself a Yo that contains a picture or a URL. How can I send a Yo with a picture using the IMP Agent?