Mobile App Development

Ding Dong! The IoT Doorbell

July 13, 2016

  • Justin Magnini Justin Magnini
  • 2

Internetting the Things

I was looking for a reason to experiment with the Internet of Things. We happened to have a few Raspberry Pi 2’s around the office, and our office has a nice reception 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.

Breadboard and bits

Breadboard and bits

 

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 created 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 online would get notified.

            // 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);
Early version of doorbell in action

Early version of doorbell in action

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 is now ready for action!

Doorbell deployed with new 3D printed button

Doorbell deployed with new 3D printed button

The Source Code for my Slack Doorbell is available on GitHub.

Leave a Comment

2 Comments

Hi. I know this is an old article but I have given this a try and am running into problems. Could you either post a circuit diagram or elaborate if you mean GPIO6 and GPIO6 or pin #5 & pin #6 on the RasPi?

Thanks

Reply to comment

I used the Push Button Sample on Microsoft’s IoT site as a starting point.
The button is connected to GND (Pin 39) and GPIO 6 (Pin 31), and the LED inside the large push button is connected to GPIO 5 (Pin 30) and GND (Pin 25).