We have a boom gate at the parking lot in our coworking space. The gate can be opened with a button press from inside the office. Opening the gate is as simple as closing a circuit in the intercom, interesting. We wanted to simulate a button press on the intercom with an Arduino.
A quick look with the multimeter showed 12 volts on the gate circuit, nice, nothing we can't handle. We can't just wire the Arduino with the other circuit, a relay keeps them apart. Not having used relays before I started digging around and found this wiring diagram on the Arduino site.
An extra pin
I got myself the cheapest and simplest relay I could get from my local electronics hobby shop, an Omron G2E PCB relay (datasheet).
The wiring diagram from the Arduino shows 5 connections on the relay, mine has 6. The datasheet shows the internal wiring but didn't make me any wiser, so how do you connect a relay?
Reading the datasheet
It turns out the little rectangle on the bottom schematic view (between pin 2 and 5) in the relay datasheet represents the coil. Great, sending power over the coil should magnetize it and close the circuit, right? Well, I could hear the switch inside so something was working but it wasn't closing the other circuit, why?
It took me a little while to figure out why there are 6 pins: there is a normally closed pair and a normally open one. On top of that, it's not pins [1,6] and [3,4] that form the switches as I expected but pins [1,3] and [6,4].
Connecting pins 6 and 4 creates a normally closed switch, the circuit is closed when the coil is not charged. This means anything connected will be powered when the relay is in its normal state.
Connection pins 1 and 3, on the other hand, form the normally open switch. The switch is open when the coil is not charged. This is what we need for our button.
Now, as soon as you charge the coil (on pins 2 and 5) the switch will do what switches do: switch. Pins 6 and 4 will be interrupted and pins 1 and 3 will be closed.
I suppose this is so simple that it isn't even worth mentioning but hey, maybe it saves someone somewhere a few minutes. I certainly learned something.
Wanna know how the gate project, called Sesame, tuned out? There is a lot more info over on the DevSpace GitHub project page.