Skip to content

The Nap Doorbell: SMS

March 20, 2010

Introduction

I am very excited with what we achieved with this project.  We succeeded in getting devices to not only talk with each other, but to talk across multiple platforms with multiple protocols, and to deliver a message as complex as desired in a format legible to anyone who can read or feel, not simply a blink of a light that requires a prior understanding of a coded signal.

For this final portion of the Doorbell Project, Adib Dada, Michael Doherty and I came up with a doorbell that sends you a text message if someone presses it insistently.  Normally, a light will go on, but there will be no sound indicator, the idea being that if you are napping you will remain undisturbed.  If someone really needs to wake you, though, and they hold down the button for more than a few seconds, you will get a text message on your cell phone.  If you have your phone set to alarm or buzz on receipt, you should awaken if you are not too deep in sleep.

The set-up required the following:

  • Arduino & XBee: We modified the set-up from the Doorbell with Feedback exercise
  • Zigbee Gateway Device: we used Digi’s ConnectPort X2 that Rob Faludi set up at ITP.  You can read more about his work on this at his website http://www.faludi.com/2009/02/18/itp-zigbee-internet-gateway-beta-begins/.
  • Server w/Website: we used a couple of servers, including the ITP server, and my website hosted there, but any will do.
  • Cellular Service & Phone: we used ATT and the iPhone, but this will work on any platform with any SMS service.

How Does It All Work?

Here’s a great whiteboard diagram Rob Faludi drew for us that really helps lay it out:

The Arduino is programmed to send an http url page request via the XBee.  The Zigbee Gateway device is programmed with a simple Python script (developed by Rob Faludi) to process this request and return the page.

The web page contains a PHP script that sends an email to the wireless carrier’s database for the target phone number, and returns a success or failure signal to the Gateway device.  The email comes through as a text message on the target cell phone, and the Gateway communicates the success or failure signal back to the Arduino via the XBee, the Arduino then lighting an appropriate LED.

Arduino & XBee Hardware:

Here is the basic hardware set-up for the Arduino and XBee:

And close-ups:

The LEDs should look pretty familiar from the previous exercise, with some modifications:

  • Yellow: Circuit power confirmation
  • Green (Pin 13): Doorbell button press confirmation
  • Green (Pin 12): Message sent confirmation
  • Red (Pin 11): Message fail confirmation

Arduino & XBee Code:

The next step was to look up the Gateway Network PAN ID (Personal Area Network ID) for ITP: it can be found here, and it is AAAA.  Since the Gateway has a Coordinator on it, we made sure our XBee was programmed as a router, and then set its PAN ID to AAAA in CoolTerm (Mac).  Destination High and Low addresses ( ATDH & ATDL) were set to 0 as the router is just looking for the coordinator.

Here’s the Arduino code.  Note that it is an adaptation of Rob’s code for the Basic Doorbell, and in the general notes at the top says it requires the BELL program on the receiving end.  The Gateway device is standing in for this piece in this case, but there is no reason why you couldn’t run a remote radio-controlled doorbell off this as well.  That is not the focus of this project, though, as the code would need to be slightly different, and the radios would likely need to run in API Mode.

/* * ********* Doorbell Email BUTTON ******** * Morgen Fleisig, Adib Dada and Michael Doherty * modified version of Rob Faludi's "Doorbell Basic BUTTON" * which requires pre-paired XBee Radios * and the BELL program on the receiving end * by Rob Faludi http://faludi.com */ //#define VERSION "1.00a0" int BUTTON = 2; int LED_PRESS = 13; //Green int LED_SENT = 12; //Green int LED_FAIL = 11; //Red int incomingByte = 0; long previousMillis = 0; int buttonState = 0; void setup() { pinMode(BUTTON, INPUT); pinMode(LED_PRESS, OUTPUT); pinMode(LED_SENT, OUTPUT); pinMode(LED_FAIL, OUTPUT); Serial.begin(9600); } void loop() { // send a URL over the serial port if the button is pressed if (digitalRead(BUTTON) == HIGH) { if(buttonState == LOW) { previousMillis=millis(); } if (millis()-previousMillis>10) { //For short button presses, just light the Button Press LED for 1 sec digitalWrite(LED_PRESS, HIGH); delay(1000); digitalWrite(LED_PRESS, LOW); } if (millis()-previousMillis>3000) { Serial.println("http://itp.nyu.edu/~mif226/sociableObjects/EmailButton.php?code=4444");  //NOTE 1: replace above with your webpage (I took mine down) //NOTE 2: note "?code=4444" at end of string and see discussion below digitalWrite(LED_PRESS, HIGH); delay(1000); // prevents overwhelming the serial port digitalWrite(LED_PRESS, LOW);
if (Serial.available() > 0) { // read the incoming byte: incomingByte = Serial.read();
if (incomingByte == 'S') { //if (Serial.read() == "sent") digitalWrite(LED_SENT, HIGH); delay(1000); digitalWrite(LED_SENT, LOW); }
if (incomingByte == 'F') { digitalWrite(LED_FAIL, HIGH); delay(1000); digitalWrite(LED_FAIL, LOW); } } } } buttonState = digitalRead(BUTTON); }

This is obviously in beta stage, and if I were to refine I would consider eliminating the delays, or at least the multiple instances of them, and nest the conditionals.  This code will work fine if you are bench-testing it, but under pressure during a presentation, it will appear a little wonky.  The delays stop the program altogether for a second each, and the independent conditionals mean that even if you push the button longer than 3 seconds, the Arduino needs to execute the each conditional independently, so the response time of the LEDs to the button presses feels a bit awkward.

PHP Code:

Michael Doherty put together this simple PHP that we put on my website:

<?php
$pass = $_GET["code"];
$to = "1234567890@txt.att.net";  //Your phone # and carrier here
$subject = "Someone's at the Door!";
$message = "Hello! This is the doorbell talking.  Someone's annoying me at the door.  Wake up!";
$from = "Adib & Morgen's Fab Pad";
$headers = "From: $from";

if($pass==4444){
	mail($to,$subject,$message,$headers);
	//echo "sent";
	echo "S";
}
//else echo "fail";
else echo "F";
?>

With the built-in $_GET function, the php file collects the value in the url of “code”, and if it is equal to 4444 (this can be anything), it will mail ATT and echo “sent” back to the Zigbee Gateway (and in turn the XBee and Arduino).  The idea of the code is to prevent false pings from triggering the text message.  Note that this method is in no way secure however, as information sent this way is visible to everyone.

I changed the echoes from “sent” and “fail” to “S” and “F” because the Arduino was coded to read an incoming byte, and it was easier to leave it that way, but either will work.  Obviously, the subject, message and headers can all be modified as you wish.

Prototype:

Here’s the SMS Nap Doorbell, mocked up for our class presentation on February 17, 2010:

Okay, it could use a little more love, but it’s a prototype!  The light at the top indicates you’ve pressed the doorbell, the light at the bottom indicates you’ve sent a text message.

The guts:

Conclusion:

Besides just being an interesting experiment in getting multiple objects to communicate with each other and people across diverse platforms with scalable protocols, this also has plenty of useful applications.  You can, for example, run out on a quick errand even if UPS or Time Warner Cable is coming sometime between 8 and 4 without fear of missing them, and more importantly, a person who has impaired hearing will still know if someone is at the door.



Advertisements

From → Sociable Objects

2 Comments

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: