Introduction to Relay

Hello everyone! I hope you will be fine and having fun. Today, I am going to give a detailed Introduction to Relay. In this tutorial, we will learn the basics of relays, the working principle of relays, the types of relays and their applications in detail.

A relay is a simple automatic switch that opens and closes the circuit(either electronically or mechanically) based on its input signal. A relay is an electromechanical switch that uses electromagnetism from a small current or voltage to switch higher current or voltage for different appliances. When a relay is in a Normally Open (NO) state, no current passes through it and when the relay is energized, the current starts to flow and we can say the relay is in a Normally Closed state. You should also have a look at Relay Interfacing with Microcontroller using ULN2003.

A Relay is used to control high-power devices with small current devices i.e. microcontrollers. When a small voltage is applied(normally from microcontrollers) to the input coil of a relay, it gets energized and the relay output changes its position from NO to NC. Relays are also used for protection purposes i.e. overload, reverse, under current, over current etc.

Now let's have a detailed overview of What is Relay???

What is a Relay?

Relay is an automatic switch, which opens and closes the circuit electronically. It uses electromagnetism from small voltage to provide higher voltages. It has two basic contacts i.e. NO (Normally Open) and NC (Normally Closed). When input voltage is applied across its coil, NC changes to NO and NO changes to NC. When input voltage is supplied, we say that the relay is energized. It has several features e.g. it can be used for switching smaller voltage to higher. But it can not be used in power-consuming devices. It has a wide range of applications. It can be used in home appliances, electronic circuits where there is a need of protection, robotics for controlling its motors for the proper motion and many more. A basic relay is given in the figure shown below.

1. Relay Pins
  • Relay has total five (5) pins with different individual functions.
  • Three pins are at one side of the structure.
  • The other two pins are on the opposite side of the structure.
  • All of these pins are provided in the table given in the figure shown below.
  • I have also made a relay pin configuration diagram.
  • Pin configuration diagram is shown in the figure given below.
2. Relay Pins Description
  • Each pin has different functions to perform.
  • So, we must know about each of the function before using it, for the better use of it.
  • All these pin descriptions are listed in the table shown in the figure below.
3. Relay Internal Structure
  • Internal structure of any electronic device leads to the better understanding about its working principle.
  • I have made a completely labeled internal structure of relay along with its pin configurations.
  • Relay internal structure is shown in the figure given below.
4. Relay Pinout
  • If you want to know about the pin configuration of any electronic device you must have a look at its pinout diagram.
  • Pinout diagram helps us to understand the pin configurations in a better way.
  • I have made a pinout diagram which contains relay animation, internal structure and the real image.
  • Relay pinout diagram is given in the figure shown below.

5. Relay Working Principle
  • Relay works on a pretty simple principle.
  • Initially when the power is not supplied and relay is in normally open condition, its contact will be opened.
  • When relay is in normally closed condition, its contact will be closed.
  • When power is supplied to its coil, it gets energized and its normally open condition is changed to normally closed and normally closed condition is changed to normally open.
  • If we want to control the device via relay through a software then we have to attach this device to its normally open terminal.
  • When the relay gets energized, that device will be turned on for the appropriate operation.
  • Working principle of array can be understand from the visuals given in the figure shown below.
  • Initially, when the power is not supplied and you can see the relay has normally closed contact as shown in the figure give below.
  • As I have told earlier, when we supply power the normally closed contact will changed its state to normally open contact and vice versa.
  • The explanation of the above step is given in the figure shown below.
  • From the above figure, you can see contact has been changed to normally open contact.
6. Relay Functions
  • Relay has the three basic functions to perform.
  • All of these three functions are provided in the table given in the figure shown below.
  • Air conditioning control (to limit & control a very high power load) are the examples of on/off control of the relay.
  • Limit control includes motor speed control (to disconnect it if it is moving with slow or faster than the desired speed).
  • Test equipment is an example of logic operation, which connects the device with no. of test points.
7. Types of Relays
  • This section will focus on the major types of relays commonly used these days.
  • There are several different types of relays.
  • The basics types are listed in the table given in the figure shown below.
  • Electromagnetic Relay is made up of magnetic, electrical and mechanical components. It has operating coil and mechanical contacts. When AC or DC supply is provided its mechanical contacts get either open of close. An electromagnetic relay is given in the figure shown below.
  • Solid State Relay consists of solid state components. It is used to perform switching operation without any movement in its parts. Its power gain is higher than the electromagnetic relays because it requires low power as in input and provides high power at the output. Solid state is given in the figure shown below.
  • Hybrid Relay is made up of electronic components and electromagnetic relays. Its input part consists of electronic circuitry which performs rectifications tasks. Its output part consist of electromagnetic relay. Hybrid relay is given in the figure shown below.
  • Thermal Relay works on a very simple principle based on heat effect i.e. the rise in ambient temperature changes one position of the contact to another. Mostly it is used for the motor protection purposes. It consists of temperature sensors and control elements. Thermal relay is given n the figure shown below.
  • Reed Relay has two magnetic strips. These strips are known as reed. These are sealed with a glass tube. The reed acts as blade as well as an armature. When magnetic field is applied to the coil. It wraps around the tube and reed start to move to perform the switching operation. Reed relays are given in the figure shown below.
8. Relay Applications
  • Relay has a wide range of application in real life.
  • Some of the major applications are listed in the table given in the figure shown below.
  • Relay can also be used in relay boards for controlling either DC or stepper motor.
  • One relay can control a single device, since two relay module has two relays so it can control two device simultaneously.
  • Two relay board is given in the figure shown below.
  • TV remote is another example of relay applications.
  • TV remote is given in the figure shown below.
  • Relay can also be used in mobile robots to control their motion properly.
  • Visuals for the above step is given in the figure shown below.
9. Relay Simulation in Proteus
  • I have made relay simulation in Proteus ISIS in order get a better idea about it.
  • As the relay is energized, LED will be turned ON.
  • A simple relay simulation in Proteus is given in the figure shown below.
  • I have also made another relay simulation in Proteus ISIS as shown in the figure below.
  • When the relay gets energized, LED will be turned ON, as shown below.
In the tutorial, Introduction to Relay, I have discussed the basics of relay. This is a fully detailed article the basically focuses on the the basics of relay including its pins configurations, its functions, types, working principle and many other things. I hope you have enjoyed the tutorial and I am sure you will appreciate my efforts. If you have any sort of problem you can freely ask us in comments anytime. Our team is always there to help you and to entertain you. I will also try my level best to answer your questions. I will share further interesting topics in my upcoming tutorials. Till my next tutorial, take care and bye :) strong>

How to use Serial Port in VB 2010

Update: Few bugs were reported by some readers, which I have corrected and updated the code. Now, its fully tested and 100% working.

Hello friends, hope you all are enjoying the start of winter season. By the way, I really hate winter season and I just want to hibernate in this season . :) Well coming to our today's lecture, my today tutorial, serial port in VB 2010, is actually based on a request made by one of the member on my Facebook Page and as it is a really good topic so i thought to share it.

Today we will make a software on Microsoft Visual Basic 2010 in which we will send data through the serial port in VB 2010. In this software we will send the data and also receive it. Simply follow all the given steps carefully and you can easily interface the Serial Port in VB 2010, its a fully working project with code so don't do any mistake. Moreover check these two complete tutorials on Microsoft Visual Studio 2010 as well, these are quite fascinating.

First of all download the Microsoft Visual Basic 2010. The installer can be freely downloaded from Microsoft. After installing the software follow these simple steps. So ,let's get started with How to use Serial Port in VB 2010:

How to use Serial Port in VB 2010 ???

Step 1 : Creating a New Project
  • Open your installed Microsoft Visual Studio 2010 software. The first interface will be something like that :
  •  Now click on the New Project and select Windows Form Applications.
  • In the project name box, add name of your project as I have added Serial Port Interface.
  • Click OK and a new window will be opened as shown in below image which contains a blank Form1.
  • In this Form1 we are gonna add our controls buttons etc.
Step 2 : Changing Name of Form
  • Now click on the form1 and the properties panel will be open on the right side. Now, in the properties tab shown on the right side change its name to frmMain (for easier identification specially when adding more forms).
  • Also change the text of the form to something you like as Serial Terminal. This will be shown on the title bar of your application.
Step 3 : Adding Controls To The Project
  • Lets start to add some controls in our software like buttons,combo box and labels etc.
  • So from the Common Controls tab add two buttons, two combo boxes and two labels into your Form1 and  align them as shown below :
  • For Button 1, change the text to Connect and change the name to btnConnect.
  • For Button 2, change the text to Disconnect and change the name to btnDisconnect.
  • For Combo Box 1, change the name to cmbPort.
  • For Combo Box 2, change the name to cmbBaud.
  • For Label 1, change the text to Comm Port.
  • For Label 2, change the text to Baud Rate.
Note :
  • Keep the names and texts of same character as i wrote them.
  • They are case sensitive so be careful. I will recommend to just copy paste them.
  • If you make even a one letter mistake the code will not run.
  • btn and cmb are just to remind that they are button and combo box respectively. Its better to do neat programming.
Step 4 : Adding Serial Port & Boxes
  •  Now from Container tab, add two Group Boxes in the forum.
  • Change the name of Group Box 1 to Transmit Data.
  • Change the name of Group Box 2 to Received Data.
  • Now add a Text Box and a Button in the Transmit Data Group Box.
  • Change the name of the Button to Send and text to btnSend.
  • Change the name of the Text Box to txtTransmit.
  • Now add a Rich Text Box in the Received Data Box and change its text to rtbReceived.
  • Arrange all these components as shown in the below image :
  •  Lastly and i think its the most important part of this tutorial, add a Serial Port Block into your forum. It will appear at the bottom. Don't change any of its parameters just leave it as it is.
Step 5 : Coding Section
  • Now we come to the coding part of our project. If you double click on your forum, it will open a new window something like that :
  • This is the place where we add our code and in other words add functionality to our project, this window is called Code Editor.
  • If you double click on any button or box, its respective code will created in this region automatically.
  • Now what you need to do is copy the below code and paste it in your code editor window.
  • Just remove all the previous code in your Code Editor Window.
  • Here's the code for Serial Port in VB 2010:
    'Code Starts here ....
    'Import Systems which we are gonna use in our code
    Imports System
    Imports System.ComponentModel
    Imports System.Threading
    Imports System.IO.Ports

    'frmMain is the name of our form ....
    'Here starts our main form code .....
    Public Class frmMain
    Dim myPort As Array
    Delegate Sub SetTextCallback(ByVal [text] As String)

    'Page Load Code Starts Here....
    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    myPort = IO.Ports.SerialPort.GetPortNames()
    cmbBaud.Items.Add(9600)
    cmbBaud.Items.Add(19200)
    cmbBaud.Items.Add(38400)
    cmbBaud.Items.Add(57600)
    cmbBaud.Items.Add(115200)
    For i = 0 To UBound(myPort)
    cmbPort.Items.Add(myPort(i))
    Next
    cmbPort.Text = cmbPort.Items.Item(0)
    cmbBaud.Text = cmbBaud.Items.Item(0)
    btnDisconnect.Enabled = False
    End Sub
    'Page Load Code Ends Here ....

    'Connect Button Code Starts Here ....
    Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
    SerialPort1.PortName = cmbPort.Text
    SerialPort1.BaudRate = cmbBaud.Text
    SerialPort1.Parity = IO.Ports.Parity.None
    SerialPort1.StopBits = IO.Ports.StopBits.One
    SerialPort1.DataBits = 8
    SerialPort1.Open()
    btnConnect.Enabled = False
    btnDisconnect.Enabled = True
    End Sub
    'Connect Button Code Ends Here ....

    'Disconnect Button Code Starts Here ....
    Private Sub btnDisconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisconnect.Click
    SerialPort1.Close()
    btnConnect.Enabled = True
    btnDisconnect.Enabled = False
    End Sub
    'Disconnect Button Code Ends Here ....

    'Send Button Code Starts Here ....
    Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
    SerialPort1.Write(txtTransmit.Text)
    End Sub
    'Send Button Code Ends Here ....

    'Serial Port Receiving Code Starts Here ....
    Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
    ReceivedText(SerialPort1.ReadExisting())
    End Sub
    'Serial Port Receiving Code Ends Here ....

    'Serial Port Receiving Code(Invoke) Starts Here ....
    Private Sub ReceivedText(ByVal [text] As String)
    If Me.rtbReceived.InvokeRequired Then
    Dim x As New SetTextCallback(AddressOf ReceivedText)
    Me.Invoke(x, New Object() {(text)})
    Else
    Me.rtbReceived.Text &= [text]
    End If
    End Sub
    'Serial Port Receiving Code(Invoke) Ends Here ....

    'Com Port Change Warning Code Starts Here ....
    Private Sub cmbPort_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbPort.SelectedIndexChanged
    If SerialPort1.IsOpen = False Then
    SerialPort1.PortName = cmbPort.Text
    Else
    MsgBox("Valid only if port is Closed", vbCritical)
    End If
    End Sub
    'Com Port Change Warning Code Ends Here ....

    'Baud Rate Change Warning Code Starts Here ....
    Private Sub cmbBaud_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbBaud.SelectedIndexChanged
    If SerialPort1.IsOpen = False Then
    SerialPort1.BaudRate = cmbBaud.Text
    Else
    MsgBox("Valid only if port is Closed", vbCritical)
    End If
    End Sub
    'Baud Rate Change Warning Code Ends Here ....

    End Class
    'Whole Code Ends Here ....
 
  • After adding the code your Code Editor Window will look something like this one :
Step 6 : Compile Your Project
  • After adding all the code, now you are ready to compile your code and run your application.
  • To compile go to Debug -> Build SerialPortInterface and if everything's going right then your project will pop up.
  •  To test your application, just add some LCD to your serial port or simply short your Rx Tx pins and whatever you send you will receive it.
  • Here's the image of my final application. I have converted it to .exe file, in my coming tutorials i will tell you how to convert a project to .exe file.
Note :
  • The project exe file and the complete code has already been emailed to all our subscribed members.
  • If someone didn't get it or want to get these files then first Subscribe to Our Newsletter and then post your email here and I will email it to them.
So that was all on How to use Serial Port in VB 2010. I hope you guys have enjoyed it and are gonna design it on your own. Take care !!! :)
Syed Zain Nasir

I am Syed Zain Nasir, the founder of <a href=https://www.TheEngineeringProjects.com/>The Engineering Projects</a> (TEP). I am a programmer since 2009 before that I just search things, make small projects and now I am sharing my knowledge through this platform.I also work as a freelancer and did many projects related to programming and electrical circuitry. <a href=https://plus.google.com/+SyedZainNasir/>My Google Profile+</a>

Share
Published by
Syed Zain Nasir