Charlton's Blog

Build a Tweeting Doorbell

A fine way to spend an afternoon

Published: Apr 14, 2017
Category: Hardware Hacking, Projects

It’s been a while since I’ve made a post of any kind, and especially one related to a project, so here’s something vaguely useful that I’ve recently put together.

Earlier this year, I found myself nearly missing a few deliveries as a result of my doorbell being somewhat difficult to hear from across the house. The bell itself is somewhat hidden in a wall behind a cabinet, so if you’re not in a room that’s directly adjacent to the one with the bell you’ll find that it’s very difficult to hear it.

Thankfully, this is a small problem that can easily be solved through the power of technology. Specifically, by leveraging the open platforms provided to developers by tech companies so desperate for market share that they’re willing to do so at absolutely no cost to the user. For this project, we’ll be using my favorite of these loss-leading social platforms, Twitter.

The Basics

Naturally, the first step in all of this is to determine what kind of environment we’re working in, so I started by popping the wall open to have a look at the ringer circuit, which is simple enough. In my particular situation, pressing the doorbell drives a solenoid which activates the ringer, which is simple enough. This means that we should be able to detect button presses by wiring the control circuit of a relay (rated around 12–24v, most likely) into the exposed terminals.

I ended up ordering a couple of automotive relays, which were rated at 12v and conveniently came in a pack of 2, with sockets.

In this image, the basic wiring is visible: the twisted blue and white pair coming in from the right is wired into the screw terminals on the bell, and connected to the control circuit on the relay. When the relay is “tripped” (e.g. activated) by a current passing through those wires, it causes the NO (normally open) contacts to close, which can be read by the microcontroller attached to the blue and yellow wires coming out of the relay on the lefthand side

Once the relay is wired up, the next thing you’ll want to do is connect the blue and orange wires to the VCC-3v3 and XIO-P0 pins on the C.H.I.P. It doesn’t matter what order you connect these in whatsoever, you just need to make sure one of each wire goes into one of the respective headers on the board. I’d recommend attaching male jumper pins to the end of each wire to make things easy, and give you a solid connection.

With the wiring done, it’s time to get the software side of things set up. My stack is set up like so:

Setting Up the Environment

The software that actually runs the environment is just as important as the hardware components, and while it’s still fairly straightforward, it’s also more complex. Here’s what you’ll need to do.

I’m assuming that you’re already SSHed into your C.H.I.P. and are currently staring at a nice little shell. If this isn’t you, have a look at this guide.

First, install Node.js. I recommend using the excellent NVM (Node Version Manager) script for this, as it will save you from all the headaches incurred by the often outdated Node packages generally available in the apt repos for most ARM platforms.

Install Node like so:

curl | NVM\_DIR=/usr/local/nvm PROFILE=/etc/bash.bashrc bash

export NVM\_DIR=”/usr/local/nvm” \[ -s “$NVM\_DIR/” \] && \\. “$NVM\_DIR/”
nvm install 4.8.2

Once installation is complete, you’ll want to download the code for this project:

git clone []( && cd bellhop

Note: if you don’t have Git installed, you can grab a copy with sudo apt-get -y install git. After installation completes, run the above command again.

Next, you’ll want to run the following, which will install the project’s dependencies:

apt-get -y install gcc make curl git python libpython-dev build-essential # this should satisfy all package dependencies 
sudo npm i -g --unsafe-perm pm2 johnny-five twit chip-io
npm link johnny-five twit chip-io

After those packages have finished installing, reboot the device. Then you’re ready to move onto the next stage, which is configuring the bot.

Set up Twitter

The next step in this protracted abuse of VC money is to register a Twitter account for your bot. To sign up, click here. I’d recommend making the bot’s twitter private to prevent random netizens from seeing when your doorbell is rung (though that isn’t strictly necessary).

Once your account is ready, the next order of business is to generate a set of API keys. This is another matter of clicking a few buttons, and is a relatively straightforward process:

After that, you’ve successfully provisioned your bot’s Twitter API keys and have officially made it through the bulk of the tutorial. Step away from your worktable for an hour or so because you’ve committed a lot of time and energy to this project and are probably getting slightly neurotic at this point.

Use this time to give yourself a pat on the back and grab a stiff drink.

Getting Things Configured

Welcome to the last little bit of setup. The next order of business is to fill out the bot’s configuration. Lucky for you, this is the easiest part.

Start by running the following, from inside of the bellhop directory:

nano ./config.js

Here are the fields you’ll want to fill in with the appropriate information:

Note: If you’re having trouble finding these, you can use ctrl+W to search.

You also have the option of making a few other tweaks, as well:

Once you’ve edited config.js to taste, ctrl+o and ctrl+x to exit.


No project is done without a little testing. Try running the following in the bellhop folder:

sudo node main.js

If your shell sits quietly and does nothing, that’s good! It means the bot is running without issues. Check the bot’s timeline for a status message, like this one:

If you can see this, that means that the Twitter API keys are valid and everything is functioning properly software-wise. Try ringing your doorbell to see if it sends you a tweet.

Did something go wrong?

First, try rebooting. This reloads everything and fixes most types of weird, one-off errors.

Second, Double check your wiring. If you rang the bell and the script didn’t crash or log any errors, then some electrons probably aren’t flowing the right way. Run the script and temporarily stick a paperclip into VCC-3v3 and XIO-P0 to simulate the relay closing.

If the script is crashing, have a look at the error:

Did none of the above work for you? If that’s the case, feel free to scour StackOverflow at 3 in the morning (or send me a DM if you’re totally stumped).

Now, run it persistently

Assuming everything is properly functional, you can run a few short commands to have the script run automatically in the background, forever.

Ctrl+C out of the bot, if you’re still running it, and make sure you’re still in the bellhop folder. Then, run the following:

sudo pm2 startup # Starts the PM2 service whenever the system boots
pm2 add main.js # Tells PM2 to manage the bot's processs
pm2 save 

With that, the project is complete. Test that this is working by rebooting the system, leaving it alone, and watching Twitter to see whether it posts another status message.