• Skip to main content
  • Skip to primary sidebar

Homemade Circuit Projects

Get free circuit help 24/7

Circuits for Beginners | Basic Circuits | LED Driver | Hobby Circuits | Transistor Circuits

New-Projects | Privacy Policy | About us | Contact | Disclaimer | Copyright | Videos

You are here: Home / Electronics Tutorial / How to Connect a Relay through an Opto-Coupler

How to Connect a Relay through an Opto-Coupler

Last Updated on June 14, 2022 by Swagatam 48 Comments

ask questions through comments

The following post describes how to drive a relay by using an isolated method, or through an optocoupler device. We will learn three methods, first method is by connecting relay directly with the optocoupler output pins, second method is by using external PNP transistors, and third method is by using external NPN transistors. Any standard optocoupler such PC817, TIL111, or MCT2E can be used in the discussed circuit diagrams.

The question was asked by one of the interested members of this blog, Miss Vineetha.

Before studying the proposed design, let's first understand how an opto coupler works.

How an Opto-Coupler Works

An opto-coupler is a device  which encapsules an LED and a photo-transistor inside a hermetically sealed, water proof, light proof package in the form of an 8 pin IC (resembling a 555 IC).

The LED is terminated over a couple of pin outs, while the three terminals of the photo-transistor is terminated over the other three assigned pin outs.

The idea of operating a relay with an optocoupler is simple, it's all about providing an input DC from the source which needs to be isolated to the LED pin outs via a limiting resistor (as we normally do with usual LEDs) and to switch the photo transistor in response to the applied input triggers.

The above action illuminates the internal LED whose light is detected by the photo-transistor causing it to conduct across its relevant pin outs.

The photo-transistor output is normally used for driving the preceding isolated stage, for example a relay driver stage.

Connecting Relay Directly with an Optocoupler

In the following circuit diagram we can see how a relay can be connected directly connected with the collector of the optocoupler's internal transistor.

Remember, although the above connection diagram looks simple and easy, you must ensure that the relay coil resistance is not below 300 ohms, otherwise the optocoupler may heat up and get destroyed.

So if you want to use the above configuration and connect the relay directly with the optocoupler, then you have to first measure the coil resistance of the relay and make sure it is higher than 300 ohm.

This is because, most optocouplers cannot handle more than 50 mA current as the load current, therefore the relay coil must have a relatively high resistance so that it does not pass more than 30 or 40 mA current.

The following concepts show how a relay driver can be configured with an optocoupler using transistors. As shown in the following circuit diagrams, the relay driver may consist a NPN transistor or a PNP transistor.

An external transistor is recommended in a situation where the relay coil resistance is low, below 300 ohms and the relay requires a higher amount of current above 50 mA.

Using PNP Transistor

As can be seen diagram below, a PNP relay driver is connected with the optocoupler. When it's a PNP transistor such as a BC557, the base terminal of the transistor is coupled with the collector terminal of the optocoupler's internal transistor, the emitter is connected with the positive line and the collector pin is configured with the relay.

The freewheeling diode associated with the relay safeguards the transistor from back EMF voltage spikes generated by the relay coil.

The resistor values are not critical, any resistor value between 4k7 and 22K can be used for the two resistors.

Using NPN Transistor

The next diagram below shows how to integrate an NPN relay driver stage with an optocoupler. If an NPN transistor such as a BC547 is used in the relay driver, the switching voltage is received from the emitter of the optocoupler's internal transistor.

Thus, the base of the BC547 NPN transistor can be seen connected with the emitter of the optocoupler transistor, emitter of the BC547 is connected with the ground line, and collector of the BC547 is configured with the relay. The diode has the same function as explained in the previous paragraph.

The resistor value is not critical, any value between 1K and 10K can be used.

get free help for circuit diagrams

You'll also like:

  • 1.  Understanding Solar Panels
  • 2.  Reed Switch – Working, Application Circuits
  • 3.  How Supercapacitors Work
  • 4.  Simple Triac Triggering Circuits Explained
  • 5.  Calculating Inductors in Buck Boost Converters
  • 6.  Basic Electronic Circuits Explained

About Swagatam

I am an electronic engineer (dipIETE ), hobbyist, inventor, schematic/PCB designer, manufacturer. I am also the founder of the website: https://www.homemade-circuits.com/, where I love sharing my innovative circuit ideas and tutorials.
If you have any circuit related query, you may interact through comments, I'll be most happy to help!

Subscribe for the Latest Posts


 

Reader Interactions

Comments

    Have Questions? Please post your comments below for quick replies! Comments should be related to the above artcile Cancel reply

    Your email address will not be published. Required fields are marked *

  1. Abhishek Adhikari says

    March 11, 2022 at 2:01 pm

    Hello Sir
    how can i connect the three components sir? optocupler, relay and my load (R8).
    it would be great if you correct the circuit. please.
    Thank you for your help.
    i.ibb.co/9Gp87xb/with-optocoupler.png

    Reply
    • Swagatam says

      March 11, 2022 at 8:44 pm

      Hello Abhishek, You have done it perfectly. The method shown in your above link will work. However the opto LED must be reversed according to me. I forgot to show the relay positive connection…please correct that.

      how to connect opto coupler to a current sensing resistor

      Reply
  2. BEH says

    December 23, 2021 at 10:04 am

    Hi sir.
    What is the use of BC-547 in this circuit? why don’t we just use the optocoupler to drive the relay?

    Reply
    • Swagatam says

      December 23, 2021 at 1:12 pm

      Hi Beh, most opto couplers are rated at a maximum of 50 mA current while relay coils can be anywhere between 30 mA and 100 mA, therefore an external transistor becomes imperative, which ensures that the opto coupler remains safe from an over current situation regardless of which relay is used.

      Reply
  3. Olusegun says

    August 28, 2021 at 11:52 pm

    Hello mrSwagatam,
    This my first time of going through your website. I really find it interesting, you are really a leader and doing thing many can’t share.
    I really required circuit for automotive voltage stabilizer.
    I will be very grateful if my request is granted.

    Reply
    • Swagatam says

      August 29, 2021 at 10:18 am

      Thank you Olusegun, I appreciate your thoughts! For an automitive voltage stabilizer you can refer to the following article:

      https://www.homemade-circuits.com/make-this-voltage-stabilizer-circuit/

      Reply
  4. Az says

    May 26, 2021 at 12:46 pm

    Hi,
    could I use PC817 as optocoupler for the circuit above?

    Reply
    • Swagatam says

      May 26, 2021 at 1:00 pm

      yes you can use it!

      Reply
  5. Anu says

    May 23, 2021 at 1:25 pm

    Why do we need to use the IGBT for switching relay. Why can’t we just use the optocoupler to drive the relay?
    thanks

    Reply
  6. Ngoc Dang Dinh says

    December 28, 2020 at 8:35 am

    Hi Swagtam,
    I am making a relay driver for output 220VAC 10A. Input for relay is 5VDC and isolated with optocoupler (MOC3021). However, the whole controlling circuit is using same 5V power (HL PM05) and used common ground for driving the Relay. This will create some noise that upset the sensors attached to the micro-controller. Can you show me some way to separate ground for Micro-controller and the 5V relay without using 02 separated power source?
    Thank you very much for your attention.
    Ngoc from Vietnam

    Reply
    • Swagatam says

      December 28, 2020 at 5:53 pm

      Hi Ngoc, separating the ground can make the circuit very complex, instead you can try putting stabilizing agents across all the concerned parameters.

      You can put a 10uF, 0.1uF, and a 5 V zener diode right across the relay coil.
      Do the same across the supply line for the sensors.
      The microcontroller would be already having all these on board.
      Try this and see if that helps.

      Reply
  7. fungai shuhwa says

    November 2, 2020 at 3:13 am

    hi i want to control a 48 dc motor have tried to source around but failed to get a compatible relay is there any alternative method that i can use

    Reply
    • Swagatam says

      November 2, 2020 at 10:07 am

      Hi, what kind of control do you want to implement on the motor?

      Reply
  8. aakash karekar says

    September 25, 2018 at 4:33 pm

    Hello sir,
    I have modified the above circuit so please can you just have a look and tell me whether this circuit will work or not?

    link for the circuit
    https://drive.google.com/file/d/1kSvsSgoAIv2Qw94WIyQcQ-RCZjcgJw7R/view?usp=sharing

    Thankyou

    Reply
    • Swag says

      September 25, 2018 at 5:35 pm

      Hello Akash,

      it looks OK, however the base resistor needs to be increased to at least 10K, and also for better response connect another 10K from the emitter of the opto transistor to the ground line.

      Reply
      • aakash karekar says

        September 25, 2018 at 7:04 pm

        Thankyou sir.

        Reply
      • aakash karekar says

        September 25, 2018 at 7:06 pm

        (also for better response connect another 10K from the emitter of the opto transistor to the ground line.)
        sir,what does this mean?

        Reply
        • Swag says

          September 25, 2018 at 7:26 pm

          from the junction of the base resistor and optocoupler pin, connect another 10k to ground, because it is always recommended to keep transistor base to its emitter level through a resistor, so that during an absence of signal, the base does not remain floating

          Reply
          • Aakash karekar says

            September 25, 2018 at 9:44 pm

            Sir you are GREAT.
            once again thank you sir..

            Reply
            • Swag says

              September 26, 2018 at 6:48 am

              It’s My pleasure Akash!

              Reply
  9. Aakash karekar says

    September 25, 2018 at 12:13 am

    Hello sir,
    Is mct2e different from pc817?
    Can I use pc817 in above circuit?

    Thank you

    Reply
    • Swag says

      September 25, 2018 at 6:31 am

      working of PC817 is similar to MCt2E, but PC817 is more powerful than MCT2E with its specs. yes you can definitely use it…

      Reply
  10. Aakash karekar says

    September 25, 2018 at 12:06 am

    Hello sir,
    I want to operate a relay through optocoupler as shown in the circuit.
    Can you suggest a transistor in place of bc547/bc557 to handle current up to 1.5amps,because I want to operate car relay which consumes current up to 1.5 amps.

    Thank you

    Reply
    • Swag says

      September 25, 2018 at 6:29 am

      Hello Akash, for 1.5 amps you can TIP31C for BC547, and TIP32C for BC557. However for operating a car relay coil you can easily try 2N2222 for BC547 and 2N2907 for BC557

      Reply
      • aakash karekar says

        September 25, 2018 at 3:34 pm

        Thanks a LOT SIR,
        I appreciate your help..

        Reply
        • Swag says

          September 25, 2018 at 4:15 pm

          you are welcome!

          Reply
  11. BARUTI says

    June 12, 2018 at 1:57 pm

    /*
    This code was based on BARUTI SPWM code with changes made to remove errors. Use this code as you would use any other BARUTI ,s works.
    11/6/2018
    */
    const int sPWMArray[] = {500,500,750,500,1250,500,2000,500,1250,500,750,500,500}; // This is the array with the SPWM values change them at will
    const int sPWMArrayValues = 13; // You need this since C doesn’t give you the length of an Array
    // The pins
    const int sPWMpin1 = 10;
    const int sPWMpin2 = 9;
    // The pin switches
    bool sPWMpin1Status = true;
    bool sPWMpin2Status = true;

    void setup()
    {
    pinMode(sPWMpin1, OUTPUT);
    pinMode(sPWMpin2, OUTPUT);
    }

    void loop()
    {
    // Loop for pin 1
    for(int i(0); i != sPWMArrayValues; i++)
    {
    if(sPWMpin1Status)
    {
    digitalWrite(sPWMpin1, HIGH);
    delayMicroseconds(sPWMArray[i]);
    sPWMpin1Status = false;
    }
    else
    {
    digitalWrite(sPWMpin1, LOW);
    delayMicroseconds(sPWMArray[i]);
    sPWMpin1Status = true;
    }
    }

    // Loop for pin 2
    for(int i(0); i != sPWMArrayValues; i++)
    {
    if(sPWMpin2Status)
    {
    digitalWrite(sPWMpin2, HIGH);
    delayMicroseconds(sPWMArray[i]);
    sPWMpin2Status = false;
    }
    else
    {
    digitalWrite(sPWMpin2, LOW);
    delayMicroseconds(sPWMArray[i]);
    sPWMpin2Status = true;
    }
    }
    }

    Reply
    • Swag says

      June 12, 2018 at 4:55 pm

      Thanks for this submission, could you please tell us what improvement you have done in this code? and what error the code given in the article has?? hope you will clarify this for all of us

      Reply
  12. Swagatam says

    August 5, 2017 at 3:31 pm

    yes, you can use any optocoupler

    Reply
  13. Jelajah Android says

    June 6, 2017 at 4:16 am

    Hi sir need your help, i want to make a module relay for arduino, i Using pc817 optocoupler to my module ,but i don't know value of resistor and a transistor? Can you tell to me value of that and what a this schematic can i use to my module? Please help me sir. Thanks you

    Reply
    • Swagatam says

      June 6, 2017 at 11:42 am

      Jelajah, you can use all the values exactly as indicated in the above article….any one of the schematics can be used for making the module.

      the opto LED resistor could be a 4k7…it's not too critical

      Reply
  14. Sandeep K says

    April 2, 2017 at 8:35 am

    Can i use an audio signal to trigger the optocoupler. With a high speed diode in series and a cap after that to smooth out the trigger signal

    Reply
  15. Kesava Raj says

    March 26, 2017 at 9:17 am

    Both optocoupler and cd4017 i'm using for 1 project….

    I'm apllying 5v to cd4017….
    Pin no 2 I'm connecting to opto coupler Anode,,,cathode is negative….
    My question is ,what is the resistor value for opto coupler anode to pin 2 cd4017…shall i use 320, or 470 or 1k….

    But cd4017 all o/p giving 3v only …so i need the resistor vakue for connecting the opto coupler…

    If any resistor calculation formula for optocoupler,pls tell sir

    Reply
    • Swagatam says

      March 26, 2017 at 12:18 pm

      1K should also work since opto LED require very little current but you can use 470 ohm for confirmed results.

      Reply
    • Swagatam says

      March 26, 2017 at 12:19 pm

      formula is

      (3 – LED Fwd voltage) / LED current

      Reply
  16. Kesava Raj says

    March 26, 2017 at 3:18 am

    Sir I'm using CD4017 ic..input voltage i'm giving 5v but the o/p voltage is 3v only coming so shall i use 470 or 1k…

    Reply
    • Swagatam says

      March 26, 2017 at 6:00 am

      Kesava, input voltage to 4017 or the optocoupler, please clarify?? for an opto the emitter side will show slightly less voltage than the input, and that does not make any difference since the output transistor will require just 1V to trigger.

      Reply
  17. Kesava Raj says

    March 23, 2017 at 1:36 am

    Hai sir…..

    Small doubt for me..

    1.Trigger source voltage means what,is it any ic o/p
    2.if i use trigger voltage 5v ,pls tell the value of resistor…1k or 470ohms…
    3.pls tell the voltage & current rating of the opto coupler emmiter and collector.

    I'm waiting for your reply sir

    Reply
    • Swagatam says

      March 23, 2017 at 2:32 pm

      Hi Kesava, trigger source refers to the external isolated signal which needs to be used for activating the relay

      for 5V , a 1K will be enough, although slightly higher will also do.

      the C/E rating will depnd on the opto specs which will need to be checked from its datasheet.

      Reply
  18. Kesava Raj says

    March 20, 2017 at 6:34 pm

    Hai sir…..

    Small doubt for me..

    1.Trigger source voltage means what,is it any ic o/p
    2.if i use trigger voltage 5v ,pls tell the value of resistor…1k or 470ohms…
    3.pls tell the voltage & current rating of the opto coupler emmiter and collector.

    Reply
  19. Swagatam says

    February 12, 2017 at 11:44 am

    Hi, could you tell us where did you learn that microcontroller output gives 1V? I am interested to see it.

    Reply
  20. Unknown says

    February 12, 2017 at 10:11 am

    Hi,
    How this circuit should be modified in order to have microcontroller trigger the optocoupler? Apparently you can not just connect the left part of the circuit to microcontroller pin as microcontroller provides only 1V on pin high, when 4N25 requires at least 1.3V?

    Reply
  21. VM says

    October 28, 2015 at 6:57 pm

    Hi Bro!

    I made this circuit (BC557) to drive an automotive relay. As this is to be used in an automotive application, the signal trigger voltage and also the relay driving voltage comes from the same battery source. Only the signal trigger is controlled so that it is turned on as required.

    I am attaching a link to the changes that I made in this circuit diagram. I have made the ground common for both the trigger signal voltage and the driving battery voltage.

    https://drive.google.com/file/d/0B7h83BRbOTR0N2NfUE1MWmtkb1k/view?usp=sharing

    When I connected this circuit, the BC557 is conducting the full voltage without even the trigger signal volt wire connected. The relay I used was 50 ohm 30 Amps automotive relay. When this relay was connected it turned on without triggering the optocoupler.
    When I connected a double coil relay with effective 100 ohms resistance, the relay did not turn on without the trigger, but when i connected the trigger signal wire then it turned on, but it does not turn back off even after removing the signal trigger wire.

    Also the BC557 gets pretty hot within a few seconds. I tested all the components and they are all OK,

    What am I doing wrong?

    Also what changes should I make so that this circuit can be used with automotive relays and also noting that the driving source is same as the signal source?

    Thanks for your help.

    Regards,

    Reply
    • Swagatam says

      October 29, 2015 at 7:34 am

      Hi Bro, your circuit is absolutely correct, and there's no way the BC557 can conduct without a trigger unless:

      1) your BC557 is faulty or connected the wrong way.

      2) the opto is faulty or the input is leaking voltage to the opto LED.

      confirm the second point by disconnecting the opto LED cathode from the ground line. If this corrects the issue then the problem could be due to a leakage voltage to the LED…check the trigger input to stop this leakage.

      If the above does not solve the issue, then you may try disconnecting the opto transistor emitter and check the response…if this stops the relay driver conduction would indicate a faulty opto or an incorrectly connected opto.

      By the way BC557 is not suitable fro driving a 50 ohm relay, you must use a 8550, or a 2n2907 or any similar 1 amp (C/E) PNP transistor for this.

      Reply
  22. White Dragon says

    April 26, 2015 at 6:44 pm

    sir. how can i drive a 12v relay with pc817 opto coupler with 2n2222 to isolate 220AC voltage from PIC MCU?
    can you please help me?

    Reply
    • Swagatam says

      April 27, 2015 at 11:36 am

      White dragon, can you please explain the link between 220V and the MCU, meaning how the 220V is related to the MCU circuit?

      Reply
    • Swagatam says

      April 27, 2015 at 11:39 am

      …I think I got it….you can try the second circuit from the above article, the BC547 can be replaced with 2n2222

      Reply
  23. Swagatam says

    November 17, 2013 at 8:39 am

    you can use triac or an ssr in place of a relay

    Reply

Primary Sidebar



Categories

  • 3-Phase Power (15)
  • 324 IC Circuits (19)
  • 4017 IC Circuits (52)
  • 4060 IC Circuits (25)
  • 555 IC Circuits (98)
  • 741 IC Circuits (19)
  • Amplifiers (59)
  • Arduino Engineering Projects (83)
  • Audio Projects (94)
  • Battery Chargers (83)
  • Car and Motorcycle (94)
  • Datasheets (46)
  • Decorative Lighting (Diwali, Christmas) (32)
  • DIY LED Projects (89)
  • Electronic Components (97)
  • Electronic Devices and Circuit Theory (35)
  • Electronics Tutorial (110)
  • Fish Aquarium (5)
  • Free Energy (34)
  • Fun Projects (12)
  • GSM Projects (9)
  • Health Related (19)
  • Heater Controllers (28)
  • Home Electrical Circuits (100)
  • How to Articles (20)
  • Incubator Related (6)
  • Industrial Electronics (28)
  • Infrared (IR) (40)
  • Inverter Circuits (98)
  • Laser Projects (12)
  • LM317/LM338 (21)
  • LM3915 IC (25)
  • Meters and Testers (64)
  • Mini Projects (156)
  • Motor Controller (66)
  • MPPT (7)
  • Oscillator Circuits (24)
  • PIR (Passive Infrared) (8)
  • Power Electronics (33)
  • Power Supply Circuits (75)
  • Radio Circuits (9)
  • Remote Control (47)
  • Security and Alarm (61)
  • Sensors and Detectors (118)
  • SG3525 IC (5)
  • Simple Circuits (74)
  • SMPS (29)
  • Solar Controllers (60)
  • Timer and Delay Relay (53)
  • TL494 IC (5)
  • Transformerless Power Supply (8)
  • Transmitter Circuits (40)
  • Ultrasonic Projects (14)
  • Water Level Controller (45)


Circuit Calculators

  • AWG to Millimeter Converter
  • Battery Back up Time Calculator
  • Capacitance Reactance Calculator
  • IC 555 Astable Calculator
  • IC 555 Monostable Calculator
  • Inductance Calculator
  • LC Resonance Calculator
  • LM317, LM338, LM396 Calculator
  • Ohm’s Law Calculator
  • Phase Angle Phase Shift Calculator
  • Power Factor (PF) Calculator
  • Reactance Calculator
  • Small Signal Transistor(BJT) and Diode Quick Datasheet
  • Transistor Astable Calculator
  • Transistor base Resistor Calculator
  • Voltage Divider Calculator
  • Wire Current Calculator
  • Zener Diode Calculator


You can also Chat with me here:

Facebook
Twitter
YouTube
Instagram
My Facebook-Page
Quora



© 2022 · Swagatam Innovations

We use cookies on our website to give you the best experience.
Cookie settingsAccept All
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Please visit the Privacy Policy Page for more info.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT