If you’re like me, then you probably have one or two of those remotely controlled sockets lying around. By simply inserting them into an outlets and plugging in your AC appliance You can use the included remotes to violently turn on/off all kinds of appliances That means there must be some kind of switch, inside the remotely controlled sockets, that can handle mains voltage. So, let’s grab the suitable bits and crack this thing open. On the inside we can see a fuse a radiofrequency PCB and HX2272 IC, which is a remote control encoder, and a suspicious-looking box that makes a clicking sound Every time we turn on or off these sockets. This component is called a relay, which is in a nutshell, an electromechanical switch You sometimes find such relays next to a 4 pin IC Like this 8 once have an IC right here, which according to its datasheet is a so called optocoupler But what kind of relationship do those two components share? Well, we are about to find out in this electronic basics episode, In which we will learn what makes those two components special, when to use them, and most importantly, how to use them properly. Let’s get started! First off, let’s have a closer look at relays, which exist in a variety of different looks But in general they all share the same fractional principle, if we open one up we can see that it basically Consists of a coil and at least two contacts, on the enclosure of the relay we also have to find useful information If not, then you need to google the part number and use the datasheet in stats anyway our relay casing states a coil voltage of 5 volts Which means that by applying this voltage to the pins of the coil, current will flow through its which thus creates a magnetic fields Attracts the anchor on top of the coil and therefore closes the previously open contacts This way this switch is now closed and thus could connect our appliance to mains voltage the symbol of a common relay Looks like this with the coil on the left side and the NO (Normally Open) switch on the right side NO stands for normally open which describes the state of the contacts when the coil is not energized there are also NC (Normally Closed) switches aka normally closed switches and and change over contacts which consists of three contact points and basically provides both switch options of course they exist voltage and current limitations for those switches Which you can find on the relay itself or once again in the datasheets Another important aspect is that when you apply a too low voltage to the coil this switch will not activate Or behave unreliable due to the low magnetic force But on the other hand if you apply a too high voltage, the over current may heat up your coil excessively and thus cause a coil short circuits Which renders your relay unusable At this point, you should be able to create a simple relay circuits that for example turns on/off a small light bulb And while it may look like everything works flawlessly There is a big problem If we measure the voltage across the push-button that I use to power the coil We can see that there are voltage spikes of above 200 volts every time the coil denergizes This switch does survive this, but if we would replace it with a transistor Then there is a big chance that this transistor will not live for very long The reason is that the collapsing magnetic fields, induces a current which creates an over voltage due to the open circuits So the solution is to add a flyback diode Which parallel to the coil so that the current can flow and thus prevent the over voltage And with that being done our simple light bulb circuits works without a problem, but you might be asking yourself Why do I not simply use MOSFET when switching DC or a TRIAC when switching AC? So let’s imagine we create such switching circuits and our loads draws 10 amps of current The problem is that both the MOSFET and TRIAC possess a voltage drop which multiplied by the current equals the power loss of the switch The context of relay however, have such a small water drop at 10 amps that features the lowest power loss Even if we add the power the relay coil requires Next the MOSFETs control voltage and the load we want to switch need the same voltage ground potential While the relays control and load ground potential doesn’t have to be the same We can use 5 volts from a microcontroller and turn on 230 volts at the switch without having to worry that the microcontroller could get destroyed by 230 volts accidentally touching the control signal That means both circuit parts are galvanic isolated from one another Which is an important safety feature But of course while the MOSFET can be used to dimmer light sources efficiently through PWM The relay is way too slow for that since it is still partly a mechanical switch So in conclusion a relay is great at switching big loads with low power losses while providing a galvanic isolation But on the other hand they are slow and their contacts will wear out over time But what about the optocoupler I talked about earlier? For that let’s go back to the TRIAC switch, AC circuits To power its gates and does turn on the TRIAC. We need a switch that connects the AC voltage to it’s A relay with in this example not work, since we want to control the phase angle at a frequency of 50 Hertz Instead we could use an optocoupler, which is also known as an opto isolator which should make its function a bit more clear, on the inside it consists of an infrared LED and a Photosensitive sensor which is nowadays mostly a transistor or a TRIAC Thus by applying the forward voltage Mentioned in the datasheets to the IR LED it lights up and therefore activates the transistor or TRIAC on the other sides Which starts activates the AC mains voltage TRIAC we talked about earlier, since the opto coupler TRIAC can also handle up to 400 volts And since the inputs and output side of the opto coupler are just like the relay galvanic isolated There’s no harm for our control microcontroller signal, since the isolation voltage goes up to 7500 volts in this case, of course a transistor based optocoupler cannot switch that high of voltage But it can for example turn on a second transistor, which then can turn on the coil of relay Which brings us back to the example we started with This way this circuit offers a double galvanic isolation Which is a very safe environment for our microcontroller signal So in conclusion optocouplers can switch faster than relays, provide galvanic isolation, and need less activation current But on the other hand they cannot handle big loads, which is why they are sometimes next to relays Of ourse there are more advanced applications for optocouplers as well but for now you should be familiar with the basics and be able to create some amazing projects as always, thanks for watching Don’t forget to Like share and subscribe Stay creative, and I will see you next time!