Many microcontroller designs typically mix multiple interfacing methods. A microcontroller (µC) system can be viewed as a system that reads from inputs, performs processing and writes to outputs. Microcontrollers are useful to the extent that they communicate with other devices, such as sensors, motors, switches, keypads, displays, memory and even other micro-controllers. Often a need arise to interface output of the microcontroller with an electromagnetic relay (EMR).
Relays are devices which allow low power circuits to switch a relatively high Current and/or Voltage on/off. Here is a simple microcontroller-relay interface circuit with perfect “galvanic isolation”. “Galvanic isolation”means an isolation between two circuits, i.e. no metal conduction between those circuits. Transfer will then take place for instance optical or by induction. Galvanic means “related to DC”. Galvanic Isolation says that the driver circuit is separated from the signal source in such a way that DC current cannot bridge the connection. The widely accepted method for galvanic isolation is the use of optical isolator (optocoupler/photocoupler).
CNY17-1 from Vishay Semiconductors is an optically coupled pair consisting of a gallium arsenide infrared emitting diode optically coupled to a silicon NPN phototransitor. Signal information can be transmitted by the device while maintaining a high degree of electrical isolation between input and output.
Interfacing this circuit with a µC is very simple and straight forward. Input of the circuit can be connected to the selected output port of the µC through the input terminals. However keep an eye on the supply polarity. Logic 1 (H = 5V) at the input of the optocoupler PC1 (CNY17-1) will switch on the electromagnetic relay, and logic 0 (L=0V) will turn it off. The whole circuit can be powered from any DC source capable of delivering about 50 mA at 12V DC.