Relays (Part 1)
Relays may look outdated in the world of microprocessors: they are big, greedy (in mA) and slow. However, some of their properties make them unavoidable still, when comes the question of: galvanic isolation and requirement for fully floating contacts.
Driving relays is no big deal as long as we care about the fit of the caracteristics from the driver and the relay. The simplest design consist in hooking one of the coil end to VCC (actually 5V with Arduino) and to drive the relay by switching the other end to ground. This will be acceptable as long as the relay draws less than 40mA, which is the upper current limit for Arduino digital ports. In other words, the resistance of the coil should not be less than (5 / 0.040) = 125 Ohms.
You will not see this design much because it fails to protect the driving port from the reverse voltage generated while opening the coil circuit. Fortunately, the solution if simple and cheap and it consists in adding a diode in parallel with the coil, so that the reverse voltage will be absorbed by this diode. A general purpose diode will suffice.
When the relay draws more than 40mA, it is necessary to use an interface between Arduino and the relay. The simplest way to achieve that is to use a general purpose NPN transistor, which Ice fits the current drawn by the relay.
Arduino digital port can drive up to 40mA per port, but the summ of these currents must not exceed 200mA. What shall we do now if we need to drive say 6 reed relays without transistors? Here are a couple of solutions. They are based of the fact that the current drawn by the relay is not linear and follows a transient curve. At switching time, the current must be at the maximum, but the need for sustaining the contact activated is lower in the steady state. At this precise time, it is not necessary to apply the full voltage to the coil.
If we are rich in digital ports, this is an option for driving the relay in eco-mode:
Both digital ports are set to 0 for swtiching the relay, and the closest port from the relay is set to input mode after a short delay (delay = time taken for the transient to happen)
An other option makes use of a capacitor. Before turning the coil on, the capcacitor is fully discharged, acting as a short circuit and letting the whole current travel through the coil; it will then charge and be transparent so that the current will flow through the resistor which is set in parallel with the capacitor.