Relays are a common item used to power units requiring a higher voltage or current than a microcontroller can handle and/or a unit or sensor that has a high electrical or current consumption. For automation its usually connected to a microcontroller and sensor that turns something on when a specific data point is reached or detected and turned off when the data point no longer exists or is valid.
An example would be if you had a microcontroller such as an arduino connected to a PIR sensor and a relay connected to a camera. You could configure the arduino to activate the relay when the PIR detects a heat source nearby, say if someone were entering your room or if you wanted to watch what your pet pig was doing when you let it outside. Being that the required voltage and current ratings are well outside the arduino’s capability -about an amp of current and 125VAC– you would have to connect the camera to a relay to safely power and control it. But how do you know which relay is right for you?
Required Materials:
Low Power Relay | Arduino Nano -OR- Attiny 85| Jumper Wire Set | Bread Board
Resources:
Programming the ATtiny | ATtiny Datasheet | Arduino Nano Pinout | Arduino Nano Datasheet
Choosing the Correct Relay
involves simply checking the voltage ranges of the relay against that of your camera in this example. Note that you can power a vast array of electrical components and sensors and apply them for different use cases. You’re not limited to just using a camera or just using a camera to watch your pets, not even a pig!
For example, let’s assume the following picture is for a camera.

Let’s look at the output: DC5V is direct current at 5 volts with a current of 2.1Amps. An compare it with the electrical characteristics of a relay.

On the first row we see that at 10 amps the maximum volts in alternating current is 250VAC, or 250 volts of alternating current. However, with 10 Amps of current the max DC voltage (Direct current) supported is 30 volts. The next row below states that at 12 amps the maximum supported volts in AC is 125VAC and at 12amps the maximum volts DC is 28volts. Going back to the plug for the camera, we see that the output for the camera plug is well within the parameters of the relay, meaning the relay can be used to manage the on/off state of the camera.
If the camera plug parameters were incompatible with the relay, a high power/ high current relay may be needed. Below is an example of a much higher current relay.

Underneath the model number SLA-12VDC-SL-C we see the current/ voltage tolerances at 30 amps is 250VAC and 30VDC, making it compatible with most electronics.
The next step is understanding the wiring and how its connected
NO/NC/COM Screw Terminals
are labels used to identify how a circuit is connected and how you the user can power it. When viewing the silkscreen next to the screw terminals or sometimes underneath it you will find the labels NO/NC/COM, which refer to where you connect the wires so that the circuit is “normally opened” NO aka, not powered by default; “normally closed” NC, normally on and working by default, and “common” COMM which is where at max one wire will be placed. The second wire is placed at either the normally closed or normally opened screw terminal depending on how you want the connected unit to operate. If working on a power hungry unit I’d have it connected to normally opened, otherwise, normally closed works fine.

Power and Operation
The intelligent way of controlling a circuit is via a microcontroller. There are other ways, but for automation and sensor integration purposes we’re going to focus on a microcontroller. I recommend using an arduino nano for smart sensors or an Attiny 85 if you’re processing sensors that generate a simple high or low signal. Whether you’re using the ATtiny or any arduino based board the code will be the same. Microcontroller receives a signal, analyzes it, then if its aligned with the datapoint declared in the programming, then it activates the relay. But how do you connect the microcontroller to the relay?

Both pictures result in the same outcome in that the microcontroller is able to control when the relay turns on or off. To the left is a screw terminal connection while the right depicts a male header pin connection. DC+, DC-, and IN reference the positive, negative, and signal in respectively. The IN pin is the control that turns the relay on or off. this is similar to the S (signal in), + (positive), and – (negative) of the male header pin relay. When connecting to a microcontroller you can connect it to any digital or analog pin, for reference take a look at the datasheet for the arduino nano

The sketch above shows a basic setup using the arduino nano. The PIR data pin is connected to arduino digital pin 2 and sends a high signal when it detects heat, the arduino then sends either a HIGH or LOW signal to activate the relay. Some relays require a HIGH or LOW signal to activate and may have a programmable switch to dictate which signal type is needed to activate the relay such as what you see in the red square here. After that, the last step is uploading the code and you’re good to go!