Rebuilding...

Sensitive Buildings: Building A Better Doorbell · Sunday October 2, 2011

Assignment

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.

Goal

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.

Documentation

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


<?php

$number = your-phone-number; // replace with your phone number
$message = 'http://the-address-of-an-axis-camera.com'; // replace with address of your access camera

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

if (mail($number.'@txt.att.net', '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); 
  SoftxPort.begin(9600);
  Serial.begin(9600);
}  

void loop()   {
  if (Serial.available() > 0) {
    if (Serial.read() == 'D'){ 
      digitalWrite(buzzer, HIGH); 
      delay(1000); 
      digitalWrite(buzzer, LOW);
      delay(1000);
      SoftxPort.print(GETCommand);
      SoftxPort.print("\n");
      SoftxPort.print("\n");
      char rdata = 0;
      char response[2] = {
        0,0};
      for (int x = 0; x < 2; x++)
      {
        rdata = SoftxPort.read();
        response[x] = rdata;
      }
      delay(5000);
    }
    Serial.flush();
  }
}

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); 
  Serial.begin(9600);
}

void loop() {
  firstReading = analogRead(camera);
  delay(100);
  secondReading = analogRead(camera);
  delay(100);
  thirdReading = analogRead(camera);
  if (digitalRead(button) == HIGH || (firstReading == 0 && secondReading == 0 && thirdReading == 0)) { 
    Serial.print('D'); 
    delay(12000);
  }
}

Video

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.

› Matt


Make A Comment
Name:
Website:
Message: