Before we begin, I'd like to point out that we're working with household AC power. If you're the sort of person that is routinely told to get your parent's permission before embarking on a course of action that is considered dangerous, do so before attempting anything you read here.
I happen to be an engineer. Which means that either I know what I'm doing or I should've known better.
We begin by striping the outer layer of insulation away and exposing the inner wires.
A standard VAC cord has three wires: black (AC Hot), white (AC Neutral), and green (Ground). In deciding which wire to cut, I summoned the power of the internet. I found an authoritative reference that indicated that the safest arrangement is to splice the AC Neutral across the relay. In the photo above, one can see that I've already cut the white wire and crimped terminal contacts to the ends. To this, we're going to add our relay. I've elected to use a PVC electrical box to house the relay and splice. This is for safety. Once we've connected the AC Neutral, we wire the DC line to the relay. This particular relay requires 12 VDC to close the circuit. Note: the Arduino puts out 5VDC to control devices. We'll need an abstraction layer between out Arduino and the relay to supply it with the required input. We'll get to that in a moment.
Here we've folded and fed our AC power cord into the electrical box and connected the AC Neutral line. We've also connected our DC power line to the coil contacts. All the remains is to plug in the relay and stuff it all into the box.
With our relay nice and snug, it's time to close up the box and deliver our product.
Ordinarily, it is a good practice to test the product before one buttons it up. In this case, I had already tested the assembly before beginning this instructional series. To demonstrate the product, we'll use a 120 W flood light. Here's everything connected:
We have the relay attached to a driving circuit that will, at a time of our choosing, close the relay and power the flood light. I will describe this circuit at the close of this post. Here's the test of our product:
Obviously, it works. Here is a close up of the driving circuit:
To describe what one is seeing here: At the left, lower corner is the attachment point for two 9V batteries hooked to a line of four screw terminal connectors (0.3 spacing). The actual batteries are omitted here for clarity. We've used breadboard connectors to hook the batteries in series to provide +18 VDC. I input this into a LM7812 regulated power supply. The output is run to the lower bus line to provide a +12 VDC bus. I also crossed the +12 VDC output to the other side of the breadboard as an input to a LM7805 regulated power supply. The output of this device is run into the upper bus line to provide a +5 VDC bus line. My practice is to use this to simulate the TTL input that would ordinarily be fed forward by the Arduino. I've cross connected the grounds between the two buses via the regulated power supplies.
The key to stepping up our TTL logic to +12 VDC is the ULN2803A Darlington Transistor Array (DTA). A quick description of the DTA is that it accepts TTL input and outputs a substantially higher voltage / current than the controlling device can provide. The limit of this device is 50V / 0.5A. The chip contains 8 individual arrays. We need only one. I've added a pull down resistor (2.2 K ohm) to the port we're using. This is redundant. The DTA contains internal pull down resistors. I do this for practical reasons -- it makes it easy to discern which port to jump a wire from the +5 VDC bus. I've connected the output port to the relay via the test probe (black). The return from the relay coil (red) is connected to the common line of the DTA, which provides +12 VDC. When the input is set high, the DTA allows power to flow through the relay coil to ground an closes the relay.