Camera specifications

True development of the video doorbell project started once I got the IP camera. It was a nice MJPEG-only camera, with infrared LEDs for night vision and totally rainproof. In fact, it has an IP66 certification (IEC IP Code), meaning totally dust proof and liquid proof in all cases except for immersion. You can probably guess how much fun it was at first trying to search for an IP IP camera. I even opened the camera a few times, trying to find a way to stick the Raspi inside to save space, but there was not enough space (barely).

The camera installed (top left) Behind the camera, on the wall, the square box protects all the connections All neat and tidy, just like my house...

For the outdoors installation, things were a lot tougher than I expected, even though I expected them to be a lot tougher than I expected. I decided that I would need to put the camera power transformer close to the camera (and carry 230V AC all the way there) since I was worried about DC power losses. I had to cut open the transformer (using a Dremel tool) to make it fit inside the box with the rest of the connections.

The analog circuits

Until I started working on this project, I had no idea how analog doorbell systems worked. I still don’t, except for the parts that interest me. The two apartment installation is based on 12V AC for the entire circuit. I opened the power supply box and found the transformer, rated for 12V, 1A. I researched for other installation specifications and found that they mostly use either 12V or 24V AC. This is what I had to interface to my Raspi, which supports up to 3.3V and up to 16mA per GPIO port, all of it DC.

I wanted the analog circuits to be:

Simple: I like to understand them, more so for the analog parts

Small: I like my circuits small and my placement prospects large

Light: The fewer (and commonerer) components the better

Versatile: Usable under a wide range of operating conditions

Safe: Electrically separate low and high-voltage electronics

Low power: For appeasing my tree-hugging instincts

The inside of the apartment was the only point the existing doorbell installation that was modified, since I wanted to avoid complexity and minimize potential damage.

Inside the doorbell answer phone Adding my own wiring to the existing connector (#cableporn) From an elegant box to a Kahlo painting

Circuit: Opening the door

The circuit for opening the door was the easy part. By examining the doorbell answer phone and a bit of experimentation, I saw that the door opened when two specific connectors were short-circuited. From my rather limited electronics experience, I already knew that an AC current can be controlled using a mechanical relay, which in turn can be controlled by a GPIO pin. There is an abundance of such circuits on the Internet for the inquisitive connoisseur.

GREEN connectors are on Raspi, RED connectors on the doorbell answer phone Breadboard and assorted crumbs Breadboard and assorted crumbs, reloaded

Most relays used for microcontrollers operate at 5V and require a current of something like 50mA+, to properly power the inductor that will pull the internal switch. This is normally not a problem (well, a small one) for most MCUs, but the Broadcom chip on Raspi is very touchy and delicate. Therefore, a relay by itself is not enough, and a number of extra discrete components must be used.

Asking at my local specialist electronics shop, there was a 6V, 25mA relay available, which the guys there assured me would work just fine with 5V. It could switch up to a few throusand volts of AC or DC, limited to up to 1A of current, which of course was sufficient for my purposes. Once the circuit was completed, I actually measured the closed circuit current and found that it used just 17mA. Douze points for engineering tolerance!

Circuit: Sensing the doorbell ring

Sensing the ring used the exact same mechanism but viewed from the other side. By pressing the doorbell, a short circuit would take place between two connectors inside the doorbell answer phone. These connectors would otherwise provide 12V AC electricity. Pretty straightforward stuff. So, the detection circuit should measure zero current flowing between the two connectors. I tried to find ready-for-consumption designs, but strangely enough, the Internet was not as forthcoming for the door opening circuit. After a lot of introspection and belly button spotting, I ended up with something resembling a power supply circuit with an optocoupler at the end.

GREEN connectors are on Raspi, RED connectors on the doorbell answer phone Red and white cables go to the relay circuit Green, orange and blue wires come from the doorbell answer phone

The optocoupler was the primary building piece, since I wanted to have electrical separation. I could only find single diode optocouplers easily, so the problem was reduced to providing supply to the optocoupler within specs, which were something like up to 5V reverse voltage (max) and an input current of 60mA (max). So, essentially the optocoupler (4N35) required a DC voltage, which is derived from 12V AC using a typical rectification circuit and a current limiting resistor to ensure that the current remains around 10-20mA.

Both circuits co-operating synergistically Circuits and Raspi fully functional

Edge cases operation

One of my big concerns is that the circuits behave properly under all conditions. Nobody would appreciate it if the door was permanently stuck open due to an electrical failure. So, what would happen if the Raspi lost power, or the software crashed? What about power supply loss to the doorbell circuit due to the transformer blowing up? What about the system state during reboots?

First of all, power loss for the Raspi would cause the relay to fall to the NO position (NO - Normally Open, no current going through the inductor). Obviously, that position should correspond to the door not opening, which would still allow for the door to be controlled by the existing answer phone. This implied that the controlling GPIO should be in a low state and go high once the the signal to open the door was sent. Simple, no? But what is the state of the GPIO pin while (and after) Raspi boots?

According to the Raspi documentation, during power-on, the Raspi GPIO ports are all pulled high, but that is not guaranteed. The Broadcom chip will, on reset, pull all GPIO pins high, but once the operating system starts booting, all guarantees are off and the state of pins is undefined and operating system/services dependent. Software and hardware developers are cautioned not to assume any state for the pins and current behaviours may change at any time. This indeterminism of course means that the Raspi cannot be used directly as a circuit controller. There are several ways of dealing with this, but the cleanest solution is to place an MCU between the Raspi and the rest of the circuit, since the pin state of the MCU is well-defined during startup and has no OS to worry about. The Raspi can control directly the MCU via SPI and also do reprogramming/upgrading as needed. Full flexibility and full determinism at the programmers' fingertips FTW!

For our installation, I just put up with the door buzzing for a few seconds while the Raspi boots up. My neighbours still don't know about it.