Home > Industry Application >Security Aviation Circuits > Video doorbell design based on Raspberry Pi

Video doorbell design based on Raspberry Pi

Source: InternetPublisher:柯南道尔 Keywords: Raspberry Pi video doorbell Updated: 2024/06/03

The PiNG Video Doorbell is powered by a Raspberry Pi and uses Google Duo to start a video call with you on your phone when a visitor presses the button.

The PiNG Video Doorbell is powered by a Raspberry Pi and retro-styled in the form of a 1986 intercom and a vintage Sony cassette player.

When the doorbell button is pressed, Pi uses Google Duo to make a high-quality video call that can be answered on your phone, tablet or computer. It works when you're away from home (or when you're home but stuck with the cat), and it runs over both WiFi and cellular networks, so you can even answer the door while you're out for a walk.

It also sounds a standard wireless doorbell from inside the house as a failsafe in case the call can't be answered.

The setup and code is very simple, so read on as I show you how to make your own video doorbell from scratch in just a few hours and for under £50 (or barely anything extra if you already own a Pi and a few components).

I've always wanted to make a video doorbell with a Raspberry Pi, but until recently I hadn't found an easy way to make video calls. One that I could use in my project, but also something that would be straightforward for others to recreate. However, that all changed recently when I read reports that a browser-based version of Google Duo had been released - meaning it could work without installing a dedicated app.

Having already looked at the challenge of making calls on the Pi using Skype and WhatsApp, I was about to install Android to try Google Duo, but was put off by the inability to easily integrate the GPIO interface until the exciting news above.

After reading the article, I tested Duo first on my Windows laptop, then quickly tried using Chromium on my workshop machine, the Pi 2. This didn't go well, the Duo website came up and let me log in, but didn't show my contact list or any options to change settings. I decided to look into using a different browser (the article said it would work with Firefox and Safari, too), and tested it on the more powerful Pi 3.

I connected a Logitech webcam to the Pi 3, fired up Chromium, and to my surprise, after tweaking a few settings, I was able to call my wife from the living room in seconds. The webcam I tested had a built-in microphone, and even on the first synthetic test call, the quality was fantastic. It was a very exciting time, unlocking the potential of the video doorbell project, as well as many other possibilities.

So, making a video call using a keyboard, mouse and screen is certainly an option - but how do you make this work with a headless Raspberry Pi and some buttons?

Application Operations

Having Duo running in Chromium was great, I thought I'd just run it full screen, but then (actually by accident) I realised it could be run "out of the browser", just like you can "install" web apps on a Windows PC - here's how:

Go to the Google Duo site in Chromium on your Pi (https://duo.google.com/)

Sign in with the Google Account you want to use to ring the doorbell

Click on the three dots (hamburger) > Install Google Duo (if you are not using the latest Raspbian, you may need to select More tools > Add to desktop

Click "Add" in the dialog box that appears.

- A Google Duo shortcut will appear on your desktop

Then double-clicking the Duo icon on the desktop opens up, but like an app, without the usual Chromium furniture. I'm not sure if running it this way uses less Pi resources (seems to make sense?) but it does make the interface cleaner.

After some testing, I set up a separate Google account for the doorbell and linked it to the phone number on my Android phone, but you may not need to do this if you have an existing Google account and you’re happy to use it for the doorbell.

It doesn't remember your login details on each launch, but it will keep you logged in once you've turned it on, and mine has been running for over a week without me having to touch it. Before making a test call you'll need to make sure your webcam is plugged in and select your audio source by clicking the 'cog' settings icon and 'Manage Sources'. The available microphone and speaker options are simple, and you can play a test sound to make sure they're correct - you'll have to grant permission in a popup the first time you do this, and may need to experiment depending on your webcam/audio setup.

Once the source is saved, it's also a good idea to set the video shape to wide so that you can see as much as possible when the doorbell calls you. To do this, click on the contact as if you were going to make a call, then click on the "Show Wide Video" rectangle in the top right corner of the video preview, then press X to go back. This setting will be remembered until the Pi is rebooted.

Mouse Map

If Duo were a full application, then command line options might be available, such as launching the app and immediately calling a specific contact. In the absence of this (for now?), I need to find a way to automatically start a call by pressing a GPIO button.

To do this, I used the Python module PyUserInput, which lets you program mouse movements, clicks, and keyboard strokes.

My idea was to set up a script to wait for a button press, then move the mouse to the Contact text box, type in the contact's name, press Enter and click Video Call. Duo remembers the last person contacted and displays them in the center of the screen, but I don't want to rely on this in case the doorbell calls the wrong person (because this happened once in testing)!

10 It took some trial and error to get the mouse to click in the right place (making the app full screen helped) and to find the right keystroke to simulate the "Enter" key, but it was fun. There's also a little script on the GitHub page called Position.py that shows the mouse coordinates, which was very useful.

With that fixed, I added more code to initiate mouse movement based on the GPIO button click. This worked fine in testing, and once the call was hung up, the Pi would go back to the original screen, so when the doorbell button was pressed again, it would repeat the same action.

Software Setup

After much experimentation, I refined the setup process to the following steps.

Most of the following setup is best done with a monitor connected after a fresh (full) install of Raspbian. First enable the VNC server, and it's best to log in/create a VNC account to make connecting to the Pi as simple as possible. With the Pi running headless, you'll need to connect and log into the Duo after booting, which is simple and only takes a few seconds - I usually just use my phone to do this.

VNC can be enabled under Start > Preferences > Raspberry Pi Configuration (Interfaces tab). Because the Pi will be running headless, we also need to tell it to assume there is an HDMI display connected, and manually set the resolution (System tab) so that the mouse commands in the script line up with elements on the web application. I chose option 19, 1280x720, if you use a different resolution you may need to edit the mouse coordinates in the PiNG.py script.

Next we need to install PyUserInput from the terminal:

pip3 install PyUserInput

... and then download the PiNG.py script from GitHub onto the Pi, I just popped it into the main Pi folder. To avoid having to launch the script after every reboot, it's worth setting it up to run automatically after the desktop loads by editing the global autostart file:

sudo nano /etc/xdg/lxsession/LXDE-pi/autostart

And add the following line at the bottom to point to the script location:

@python3 /home/pi/PiNG.py

After reboot the script should run automatically.

Since the Pi may wait a while for the doorbell to ring (unless you're really popular), it's a good idea to disable the default screen dimming, as this may interfere with mouse clicks. Counterintuitively, the best way to achieve this is to install Xscreensaver:

sudo apt-get install xscreensaver

Once installed, you can configure the screen saver options (Start > Preferences > Screen Saver) and set it to disabled.

It's essentially just programming the doorbell button to perform a series of mouse clicks to control the Duo web app on screen. Except it's not really on screen, because the Pi is running headless.

If you have done the above and the Pi has rebooted, you should be able to disconnect the monitor (if you used one), connect to the Pi via VNC from your phone or PC and log into Duo, set it to full-screen, select the audio source and set the video width as described above. Once that's done you can disconnect the VNC connection and the doorbell will be ready to use!

Audio

I knew audio would be important for this project, as there's no point talking to the mailman remotely if he can't hear you! I decided to use a Pimoroni pHAT BEAT since I had one handy - although it was a bit overkill for this project in some ways.

I really only need a mono output for the doorbell, but the pHAT BEAT provides stereo output for two speakers, as well as a nice LED VU meter.

The only complication with using a pHAT for audio is that it will sit on all the pins on the GPIO header - I needed some of those to hook up the doorbell button and LED. To get around this, I added a pico hat hack3r from last year's Raspberry Fields party pack. It's a tiny but very handy board that basically splits the GPIO outputs in two, allowing you to connect a HAT while still exposing a full set of GPIO pins. While this is great, you have to be careful not to conflict with pins already used by the HAT, so I double-checked pinout.xyz and decided on the following:

Doorbell button - GPIO22 (pin 15) and 3v3 (pin 17) on the next door

Notification LED - GPIO9 positive (pin 21, through resistor), pin 25 negative

With the webcam, audio, buttons, and LEDs connected and working, I now had a working video doorbell - albeit one spread out across my workbench. Next I needed to think about how I would use it and what it would look like.

Extra Bells

The setup works fine on the bench, but what happens IRL? I'd like to have just one doorbell outside to avoid confusing visitors, but at the same time wonder what would happen if someone rang the doorbell while I couldn't answer the call, or if someone in the house didn't hear the double call.

The answer to these concerns was to include a standard wireless doorbell transmitter in the build, which could be paired with the existing chime we had in the house. That way, even if the Pi part of the build stopped working for some reason, the "normal" doorbell would still ring.

Case Logic

Once I had proven that the code worked, the next thing was to decide on a use case for the project. I wanted it to be obviously a doorbell, but for obvious security reasons I didn't like the idea of ​​hanging a fully wired Pi outside my house.

I decided to split the project into two - a doorbell unit outside the house connected to the Pi Base Station inside. There were several good reasons to go in this direction:

Fewer components can be squeezed into the enclosure and exposed to the elements

Better WiFi signal in the house, added Ethernet option

Easier to perform maintenance and upgrades

Secure my precious Pi 3B+ behind a locked door

The decision on a webcam was easy - I've had a MotionEye security camera running 24/7 for over two years using a Microsoft Lifecam HD 3000 and a Pi Zero, so it was a logical choice - especially as it has an integrated microphone. Many other webcams work well with the Pi, and you can even use a standard Pi camera - though you'll need a separate microphone to capture the audio.

The externals were simple too, a walkie talkie from 1986! I bought 3 of these retro devices a while back, and only used one in the Google Pi Intercom project in 2017, so spares were handy - plus I was already familiar with its internals and felt confident I could make everything fit.

For the internal base unit I considered just using a standard plastic project box, but as the local Maplin had closed down it wasn't easy to choose a suitable match - so I decided to re-use some older technology and mounted the Pi inside an old cassette player. This worked out really well as there was plenty of space - it meant the VU meter LEDs could be displayed through the tape window which was a handy extra touch. I was also able to connect the original speakers from the cassette player to the spare outputs on the Phat Beat - which meant the ringtones and voices would play inside the house and outside.

To connect the two units together I decided to use 6 conductor alarm cable as it is very thin and easy to work with and a connection block can be added to each end.

As always these cases require some disassembly and modification before they are ready for use, so once I stripped out the original circuitry I started cleaning up the insides using a rotary tool.

The intercom was first, and I had to chop off a plastic post to make room for the webcam, cut a hole for the wide angle lens, and sand off a lot of protrusions to make it easier to mount things like speakers. Once I had a blank canvas, I thought about how to fit the various components. I needed to make room for:

A new speaker

Two lever micro switches

Wireless doorbell circuit

Webcam

Cable connection block

Small prototype circuit for LEDs

And the initial switch and mechanism - it seemed spacious at first, but now I'm beginning to doubt it.

To make this process easier, I used a handy trick from Hitachi Pi TV Conversion and started by building a plexiglass chassis to house all of the components. Plexiglass is definitely ideal because you can see when marking where to cut the holes. First, I roughly cut it to size and drilled holes so it would mount on the intercom's existing screw posts. From here I added the components one by one, drilling and cutting holes to fit them or make room for them. Another benefit of doing this is that I was able to test if everything was working properly before final assembly!

To make the webcam fit, I had to carefully cut away a lot of its plastic casing so that it could stick directly behind the wide-angle lens - if you need to do this, pry off the front of it first, don't chop off the back with wire cutters and pliers like I did!

I was less picky about the cassette player and ruthlessly stripped away all the circuitry and components, leaving just an empty box. Cosmetic parts like the large button were simply hot glued in place, and I filled a broken little light window hole with a red button.

To get the Pi to sit in the right place behind the tape window, I first hot glued a Lego plate to the bottom of an old Pi case. I then hot glued a matching plate in the right place inside the tape player to make a nice semi-permanent accessory - the GPIO pins are accessible with the tape door open, but I wanted to make sure I could take the Pi out to change SD cards etc without any hassle. I've learned the hard way to plan ahead for future disassembly and maintenance! Finally, I cut some slots out of the outside of the tape player so that the USB and HDMI ports are still accessible after assembly, just in case.

Assembly and painting

After test fitting the Perspex chassis into the intercom, I gave it a coat of paint - I agonised over the colour for a while, trying to choose between white, matt black and brown, but opted for 'Claret Red' for a change.

Final assembly was pretty straightforward, I hot glued the intercom chassis to the final housing and also mounted the wireless doorbell circuitry on the back of the unit for easy battery replacement. The last job was to add a nameplate, which I simply printed out in different font sizes - but as I started to add this I realised some of the hot glue had seeped through a small hole in the case, spreading all over the fresh paint and blocking the nameplate slot.

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号