Video working with relays. In this video we will learn the basics of relays their applications working principle, and later, we will learn how to interface the relay to your Raspberry Pi. And finally, we will do an activity with all the things we have learned so far in the section. A relay is an electromechanical device that is similar to a switch. Many relays use an electromagnet to operate a switch mechanically, but other operating principles are also used, such as solid state relays. You might be wondering why to use a relay, when all it does is the same function as a switch.
The main operation of a relay comes in places where only a low power signal can be used to control a high power circuit. The relays are thus used in high current applications to isolate the low power control circuit from the high power Driver circuits does. Knowing about relays is vital if you want to do industrial or home automation. So let's see how a relay works. The diagram shows an intersection diagram of a relay and iron core is surrounded by a control coil. When the current starts flowing through the control coil, the electromagnet starts energizing and does intensifies the magnetic field does, the upper contact arm starts to be attracted to the lower fixed arm and does closest the contacts completing the circuit.
On the other hand, if the relay was already de energized, when the contacts were closed, then the context move in the opposite direction and make an open circuit. As soon as the coil current dissolves. The movable armature will be returned by the force of the spring release had the exact working of Switch. So, the same concept is also applied early is set a switch one or more poles. Each pole has contacts that can be thrown in mainly two ways. They are normally open contact, also known as no contact.
This is also called a make contact, it closes the circuit. When the relay is activated, it disconnects the circuit when the relay is inactive, normally closed contact, also known as MC contact. This is also known as break contact. This is opposite of the no contact. When the relay is activated, the circuit disconnects when the relay is deactivated, the circuit connects along with the NC and n o context of a relay. We also have a common contact called Comm.
You can see a two channel relay module here. Two channel relay module is just a circuit in which two separate relays are provided. This allows controlling two devices at a time does the mode the number of channels, the more the number of devices we can connect. Now let's interface the pifo with the two channel relay, the two channel relay has four pins to interface with raspberry pi Vcc ground I N one and i into the relay module needs five volts input at the VCC pin and more than 30 milli amperes of current to work. This is why we need an external power supply to provide the obvious deficit in the current year we will use a popular external power supply boat called the MB 102 breadboard power supply. To know more about this power supply and why we used it.
Please check out the links in the resources section. If you want to work With relays without using the external power supply unit to buy a 3.3 volts relay or a solid state relay, connect the five volt pin of the power supply to the VCC pin of the relay module. Then connect the G and D pin of the power supply to the DND pen of the Raspberry Pi For now, we will connect a jumper wire from another G and a pin of the power supply to another D independent of the Raspberry Pi. So now the PI the relay module and the power supply all share the same ground pin. Finally, interface a push button across the GPIO pin to which will be used to control the relay. Now let's connect some high power device across the relay output.
We are connecting a CFL across the end oak and compote as shown in this second diagram GPIO 01 point five version doesn't have an inbuilt class. Working with a relay like LDR or P IR does, we have to use the output device class to work with the relay. Open the relay button.py file in Tony ID and run the script. When you press the push button, you can see that the CFL becomes on. In the code, we first imported the button and the output device class from the GPIO zero library. Then we created instances of these classes along with the pin number related to each class.
The next set of codes are pretty self explanatory. I have an activity for you with the concepts we have learned till now. I want you to create a smart light for your backyard with a Raspberry Pi for the project will have an LDR a PA R and a relay. This is how it's going to work. The checks whether it's night or day time By the light intensity and only if it's night, and if it then detects the motion will make the relator switch on a CFL in your backyard. I hope you're successful with the project.
If you're stuck, you can check out the resources section for the code summary. In this video we have covered the following basics of relay, applications of relay, working principle of relay, interfacing and working with a relay using Raspberry Pi. In the next video, we will learn to interface and work with the ultrasonic sensor and motors