Arduino Doorbell Messenger

Posted on Mar 28, 2016 in Sundry
james portrait
James Jacoby
Chief Technology Officer, Founder

The goal for this project was simple: receive a push notification whenever someone presses my doorbell. This was made possible (cheaply) by using one of my favorite products from Adafruit: the HUZZAH ESP8266 Breakout Board. This $10 microprocessor has built-in WiFi capabilities, so it's perfect for little IoT projects like this. This project could be built a number of different ways, but my approach aims to be cheap and easy to install.

Parts Required

Circuit Setup

The circuit is very simple. All we need to do is power the HUZZAH, hook up the inputs and outputs, and control the doorbell's solenoid using a transistor. Normally, doorbells operate on 12-20 volts AC. However, controlling AC current is potentially more complicated, dangerous, and expensive. Most doorbells also function on 12V DC, so that's the route I took. For the short intervals in which it will operate this should not be a problem (although I'd love to hear any criticisms).

Services

In order to receive commands over the internet and send text messages, two services are needed:

  • Twillio is a cloud messaging service, which offers an API to send text messages. After signing up, it's easy to create a phone number for sending messages.
  • Temboo is an IoT hub that can interact with many other services, including Twillio. Each interaction is organized into a "Choreo" which you can save and call from code using their software kit. Creating a Choreo for Twillio gives you a key for activating the task.

Programming

For anyone new to Arduino, I suggest reading Adafruit's Introduction to the HUZZAH. Once you have figured out how to make it blink, just copy and paste the following gist into the Arduino IDE and replace all the #define values with the actual values from the previous step. 

#include <SPI.h>
#include <ESP8266WiFi.h>
#include <Temboo.h>

#define TEMBOO_ACCOUNT "YOUR_TEMBOO_ACCOUNT_NAME"
#define TEMBOO_APP_KEY_NAME "YOUR_TEMBOO_APP_KEY_NAME"
#define TEMBOO_APP_KEY "YOUR_TEMBOO_APP_KEY"
#define TEMBOO_CHOREO_NAME "YOUR_CHOREO_PROFILE_NAME"

#define WIFI_SSID "YOUR_WIFI_SSID"
#define WPA_PASSWORD "YOUR_WIFI_PASSWORD"

WiFiClient client;

int last = -1;
int inputPin = 2;
int flashPin = 0;
int outputPin = 4;

// prototypes

void sendSMS();
void flash(int times);

void setup() {
  // Init pins
  pinMode(inputPin, INPUT);
  pinMode(outputPin, OUTPUT);
  pinMode(flashPin, OUTPUT);
  
  // Init serial output
  Serial.begin(9600);
  delay(4000);
  while(!Serial);

  // Init Wifi
  int wifiStatus = WL_IDLE_STATUS;
  
  while(wifiStatus != WL_CONNECTED) {
    Serial.print("WiFi:");
    wifiStatus = WiFi.begin(WIFI_SSID, WPA_PASSWORD);

    if (wifiStatus == WL_CONNECTED) {
      Serial.println("OK");
      flash(3);
    } else {
      Serial.println("FAIL");
      flash(1);
    }
    delay(5000);
  }

  Serial.println("Setup complete.\n");
}

void loop() {
  int value = digitalRead(inputPin);
  
  if (value != last) {
    last = value;
    
    if (value == LOW) {
      Serial.println("Triggered!");
      digitalWrite(outputPin, HIGH);
      delay(100);
      digitalWrite(outputPin, LOW);
      runSendSMS();
    } else {
      Serial.println("Idle");
      digitalWrite(outputPin, LOW);
    }
  }
  
  delay(100);
}

void runSendSMS() {
  TembooChoreo SendSMSChoreo(client);

  // Set Temboo account credentials
  SendSMSChoreo.setAccountName(TEMBOO_ACCOUNT);
  SendSMSChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
  SendSMSChoreo.setAppKey(TEMBOO_APP_KEY);

  // Set profile to use for execution
  SendSMSChoreo.setProfile(YOUR_CHOREO_PROFILE_NAME);
  
  // Identify the Choreo to run
  SendSMSChoreo.setChoreo("/Library/Twilio/SMSMessages/SendSMS");

  // Run the Choreo
  unsigned int returnCode = SendSMSChoreo.run();

  // Read and print the error message
  while (SendSMSChoreo.available()) {
    char c = SendSMSChoreo.read();
    Serial.print(c);
  }
  Serial.println();
  SendSMSChoreo.close();
}

void flash(int times) {
  while(times-- > 0) {
    digitalWrite(flashPin, HIGH);
    delay(300);
    digitalWrite(flashPin, LOW);
    delay(300);
  }
}

I highly recommend getting everything working at your workstation before installing. You can simulate a button press by grounding the input pin and test the circuit with a multimeter. The meter should read 12V very briefly off the transistor and you should receive a text message! 

If you're feeling creative, you could easily modify the code to ring the bell using a different rhythm.

Installation

Warning: The following steps involve potentially dangerous electrical work- if you don't know what you're doing, just stop. 

First, shut off the power to your doorbell. Test the doorbell before and after and take all other necessary precautions to ensure the power is off. 

Next, locate your existing doorbell transformer (usually in your basement) and disconnect the wires from it. If you're lucky, there will be two sets of wires - one for the push button and one for the solenoid. In a normal installation, the button closes the circuit and activates the solenoid to ring the bell. We are going to change it so the button is an input for the Arduino, which will then programmatically control the solenoid using the transistor circuit and external power supply.

Lastly, mount the board somewhere safe, connect the wires as show in the schematic and plug in the power supplies.

With the power back on, you should get a satisfying ding-dong, follow shortly by a text message.

Improving Design to Development Workflows: Asset Sheets What Distance Running Teaches Us About Web Design