Sensitive Buildings: Building A Better DoorbellSun Oct 2, 05:29 AM


The third assignment for Sensitive Buildings involved creating a doorbell using a switch, 2 xBees, 2 Arduinos, and a buzzer, and then expanding upon that to create a better doorbell. I explained in my first assignment how the doorbell on my own building is a major frustration. So I already had some thoughts about how to improve my own doorbell situation.


Create a wireless doorbell using Arduino, xBee, and an Axis Network Camera as a sensor. Have the doorbell system send me a text message with a link to a live steam of the camera.


I'm using 2 Arduino Unos attached to 2 Seeedstudio Bees Shields. The Bees Shield has 2 Bee shaped sockets on it capable of accepting an xBee, or any other serial device on an appropriately shaped Bee breakout board. At less than $10 each, these shields are super cheap, and super convenient.

I first tried using the Bees Shield stacked with my Adafruit Ethernet Shield, and an attached Wiznet Ethernet module, but the Ethernet Shield wasn't getting power for some reason. I tried this first because there are a lot of Arduino examples using the Wiznet module since it is used in the official Arduino Ethernet Shield. Having failed to easily get power though, I turned to an old xPort I had laying around from when I was working through Tom Igoe's book, Making Things Talk. Fortunately I already had the Bee breakout board for the xPort, so mounting it with the xBee on the Bees Shield was very easy.

I was able to get the basic doorbell working pretty quickly based on the code provided in Rob's Building Wireless Sensor Networks book, but I wanted my doorbell to send me a text message when activated. For that I created a PHP page that would send an email to my cell phone number. At&t converts the email to a text automatically. I then needed to configure one of the Arduinos to hit that PHP page every time the doorbell rings.

PHP Text Message Code


$number = your-phone-number; // replace with your phone number
$message = ''; // replace with address of your access camera

$headers = 'From: Doorbell.' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

if (mail($number.'', 'Door', $message, $headers)) {
	echo 'sent';
} else {
	echo 'fail';

It had been a long time since I had worked with the xPort. Getting it configured properly, and finding some example code took a while. After a couple of false starts I upgraded the firmware on the xPort, and found this post on the Arduino forum. I modified Rob's original code to include code for the xPort.

Bell Code

#include <SoftwareSerial.h>

#define rxPin 7
#define txPin 8
#define GETCommand ("GET /doorbell.php") // this is the page that we want to connect to on the server (the server is defined in the xPort setup)

int buzzer = 2;

SoftwareSerial SoftxPort = SoftwareSerial(rxPin, txPin);
byte pinState = 0;

void setup()   {
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  pinMode(rstPin, OUTPUT);
  pinMode(buzzer, OUTPUT); 

void loop()   {
  if (Serial.available() > 0) {
    if ( == 'D'){ 
      digitalWrite(buzzer, HIGH); 
      digitalWrite(buzzer, LOW);
      char rdata = 0;
      char response[2] = {
      for (int x = 0; x < 2; x++)
        rdata =;
        response[x] = rdata;

Now happily texting, I decided to tackle the camera integration next. The camera has motion detection, and I could have just configured it to hit my PHP page directly, instead of using the xBees and xPort, but what would be the fun in that? I have an Axis M1054, which has a single input and output on the back.

Through the camera's web interface you can configure various events to trip the output. I'm not sure if there is something wrong with my camera, but the output voltage was quite low. I had to connect it to an analog input on my Arduino because it wasn't enough to trigger HIGH on a digital pin. I'll have to look into that some more. Otherwise it was pretty easy to get the camera integrated with my doorbell.

Door Code

int button = 2;
int camera = A0;
int firstReading;
int secondReading;
int thirdReading;

void setup() { 
  pinMode(button, INPUT);
  pinMode(camera, INPUT); 

void loop() {
  firstReading = analogRead(camera);
  secondReading = analogRead(camera);
  thirdReading = analogRead(camera);
  if (digitalRead(button) == HIGH || (firstReading == 0 && secondReading == 0 && thirdReading == 0)) { 


Video Player

Video of me testing the video doorbell.

Next Steps

At some point I'd like to build this out for real. I already see a couple areas for improvement. It would be nice to have some type of textual feedback for the user, so that they know when they have triggered the doorbell. It would also be great to be able to send a message back to the person waiting at the door from my phone. Both of these things could be solved with a LED display attached to the door. I'd also like a build a proper App, and use push notifications instead of text messages, that way I can check the door from an iPad or my Mac.

› fatbits