Internetting the Things
I was looking for a reason to experiment with the Internet of Things, and we happened to have a few Raspberry Pi 2’s around the office. . . and our office has a nice reception / waiting area but no doorbell…
..so why not build a connected doorbell using Windows 10 IoT running on a Raspberry Pi?
Installing Windows on a Raspberry Pi ended up being pretty straight forward, after installing the Windows 10 IoT Core Dashboard, a simple setup wizard allowed me to download the download the IoT Core image, and flash it to the Raspberry Pi’s MicroSD card. Next I connected the Pi to the office’s ethernet, then connected to it’s admin page remotely through my web browser.
A neat thing I learned about Windows 10 IoT is that my Pi could run headless (no display), but I could still connect a display if I wanted to. The Raspberry Pi could be configured to boot automatically into my Doorbell app each time it was turned on.
Building a button
My doorbell wouldn’t be very useful if it couldn’t be pressed though. I ordered a breadboard kit online, which included a variety of bits and pieces. I found a Push Button sample project on the Windows 10 IoT site, which would be the starting point for my doorbell codebase.
… and just because I thought it would be cool, I also connected an LED to the breadboard, which I would blink when the button was pressed. ¯\_(ツ)_/¯
After wiring the button and LED to the GPIO pins on the Raspberry Pi, the pins would also have to be configured in the code. For my doorbell, the button is connected to pin 5, and the LED is connected to pin 6.
private const int LED_PIN = 6; private const int BUTTON_PIN = 5; private GpioPin ledPin; private GpioPin buttonPin; private void InitGPIO() { var gpio = GpioController.GetDefault(); // Show an error if there is no GPIO controller if (gpio == null) { return; } buttonPin = gpio.OpenPin(BUTTON_PIN); ledPin = gpio.OpenPin(LED_PIN); // Initialize LED to the OFF state by first writing a HIGH value // We write HIGH because the LED is wired in a active LOW configuration ledPin.Write(GpioPinValue.High); ledPin.SetDriveMode(GpioPinDriveMode.Output); // Check if input pull-up resistors are supported if (buttonPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp)) buttonPin.SetDriveMode(GpioPinDriveMode.InputPullUp); else buttonPin.SetDriveMode(GpioPinDriveMode.Input); // Set a debounce timeout to filter out switch bounce noise from a button press buttonPin.DebounceTimeout = TimeSpan.FromMilliseconds(50); // Register for the ValueChanged event so our buttonPin_ValueChanged // function is called when the button is pressed buttonPin.ValueChanged += buttonPin_ValueChanged; ringButton.Visibility = Visibility.Collapsed; }
Slack integration
Our team uses Slack, which is an awesome communication tool that allows integration to a large amount of third party services, and features. To complete the doorbell, I would create my own custom Webhook, which my doorbell will send data to.
Incoming Webhooks are a simple way to post messages from external sources into Slack. They make use of normal HTTP requests with a JSON payload, which includes the message and a few other optional details.
I configured my integration to post to a specific #visitors channel. The Slack notification would use the @here keyword so that only those team members who were currently only would get notified. Besides, odds are that if you aren’t online, you probably aren’t in a position to answer the door anyway.
// Post Slack Message HttpClient client = new HttpClient(); String uriString = "<insert slack webhook here>"; var cameraUrl = "<insert URL to camera>"; var json = "{\"text\": \"Ding Dong <!here>! Somebody is at the Front Door. <"+cameraUrl+"|Click here to see who it is.>\"}"; var body = new HttpStringContent(json); var response = await client.PostAsync(new Uri(uriString), body);
A fancier button
My doorbell was functional, but not very user friendly in this state. Luckily the office also has a 3D Printer. One of the designers helped me with the modeling, and we 3D printed a box, and button cover that would attach to the push button connected to my Raspberry Pi.
Next, we connected the Raspberry Pi to a monitor, and flipped it around facing the door. The doorbell was now ready for action!
The Source Code for my Slack Doorbell is available on GitHub.