• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Homemade Circuit Projects

Get free circuit help 24/7

  • +1000 Circuits
  • Hobby Circuits
  • Basic Circuits
  • Learn Arduino
  • Logic IC Pinouts
  • Disclaimer
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 January 17, 2020 by Swagatam 39 Comments

The following post describes how to drive a relay by using an isolated method, or through an opto-coupler device.

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 opto-coupler 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.

As shown in the following circuit diagram, the relay driver may consist a NPN transistor or a PNP transistor.

Circuit Operation

If it's a PNP transistor, the base is coupled at the collector of the photo transistor, alternatively, if a NPN transistor is used in the relay driver, the trigger is received from the emitter of the photo transistor quite like a Darlington paired configuration.

The rest of the operations are self evident.

SHARING IS CARING!



Previous: High Voltage Transistor MJE13005 – Datasheet, Application Notes
Next: 5 Simple Alarm Circuits for Protecting your Home/Office from Theft

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!

You'll also like:

  • 1.  How Electret Microphones Work – Full Tutorial and Diagram
  • 2.  How to Wire a MQ-135 Gas Sensor Module Correctly
  • 3.  LiFePO4 Battery Charging/Discharging Specifications, Advantages Explained
  • 4.  What’s PWM, How to Measure it
  • 5.  Digital-to-Analog (DAC), Analog-to-Digital (ADC) Converters Explained
  • 6.  How to Configure Resistors, Capacitors and Transistors in Electronic Circuits

Please Subscribe (Only if you are Genuinely Interested in our Newsletters)


 

Reader Interactions

Comments

    Your Comments are too Valuable! But please see that they are related to the above article, and are not off-topic! Cancel reply

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

  1. Search Related Posts for Commenting

  2. Ngoc Dang Dinh says

    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

      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
  3. fungai shuhwa says

    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

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

      Reply
  4. aakash karekar says

    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

      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

        Thankyou sir.

        Reply
      • aakash karekar says

        (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

          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

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

            Reply
            • Swag says

              It’s My pleasure Akash!

  5. Aakash karekar says

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

    Thank you

    Reply
    • Swag says

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

      Reply
  6. Aakash karekar says

    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

      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

        Thanks a LOT SIR,
        I appreciate your help..

        Reply
        • Swag says

          you are welcome!

          Reply
  7. BARUTI says

    /*
    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

      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
  8. Swagatam says

    yes, you can use any optocoupler

    Reply
  9. Jelajah Android says

    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

      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
  10. Sandeep K says

    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
  11. Kesava Raj says

    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

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

      Reply
    • Swagatam says

      formula is

      (3 – LED Fwd voltage) / LED current

      Reply
  12. Kesava Raj says

    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

      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
  13. Kesava Raj says

    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

      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
  14. Kesava Raj says

    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
  15. Swagatam says

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

    Reply
  16. Unknown says

    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
  17. VM says

    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

      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
  18. White Dragon says

    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

      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

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

      Reply
  19. Swagatam says

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

    Reply



Primary Sidebar

Electronic Projects Categories

  • 3-Phase Power (15)
  • 324 IC Circuits (19)
  • 4017 IC Circuits (51)
  • 4060 IC Circuits (25)
  • 555 IC Circuits (94)
  • 741 IC Circuits (18)
  • Amplifiers (49)
  • Arduino Engineering Projects (82)
  • Audio Projects (85)
  • Battery Chargers (76)
  • Car and Motorcycle (88)
  • Datasheets (45)
  • Decorative Lighting (Diwali, Christmas) (32)
  • DIY LED Projects (82)
  • Electronic Components (97)
  • Electronic Devices and Circuit Theory (35)
  • Electronics Tutorial (99)
  • Fish Aquarium (5)
  • Free Energy (34)
  • Games (2)
  • GSM Projects (9)
  • Health Related (17)
  • Heater Controllers (24)
  • Home Electrical Circuits (98)
  • Incubator Related (6)
  • Industrial Electronics (27)
  • Infrared (IR) (39)
  • Inverter Circuits (94)
  • Laser Projects (10)
  • LM317/LM338 (21)
  • LM3915 IC (24)
  • Meters and Testers (55)
  • Mini Projects (153)
  • Motor Controller (65)
  • MPPT (7)
  • Oscillator Circuits (15)
  • PIR (Passive Infrared) (8)
  • Power Electronics (33)
  • Power Supply Circuits (65)
  • Radio Circuits (9)
  • Remote Control (46)
  • Security and Alarm (56)
  • Sensors and Detectors (116)
  • SG3525 IC (5)
  • Simple Circuits (72)
  • SMPS (29)
  • Solar Controllers (60)
  • Timer and Delay Relay (51)
  • TL494 IC (5)
  • Transformerless Power Supply (8)
  • Transmitter Circuits (39)
  • Ultrasonic Projects (12)
  • Water Level Controller (46)

Follow Homemade Circuits

Facebook
Twitter
YouTube
Instagram
My Facebook-Page
Quora

Feeds

Post RSS
Comment RSS

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
  • Privacy Policy
  • About Us
  • Contact
  • Disclaimer
  • Videos – Circuit Test Results

© 2021 · Swagatam Innovations