Skip to main content

How to Drive a Relay through an Opto-Coupler

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

Simulation and Working


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.

 



 

Need Help? Please leave a comment, I'll get back soon with a reply!




Comments

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

    ReplyDelete
  2. 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?

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

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

    ReplyDelete
  5. 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,

    ReplyDelete
  6. 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.

    ReplyDelete
  7. 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?

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

    ReplyDelete
  9. 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.

    ReplyDelete
  10. 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

    ReplyDelete
  11. 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.

    ReplyDelete
  12. 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...

    ReplyDelete
  13. 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.

    ReplyDelete
  14. 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

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

    ReplyDelete
  16. formula is

    (3 - LED Fwd voltage) / LED current

    ReplyDelete
  17. 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

    ReplyDelete
  18. 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

    ReplyDelete
  19. 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

    ReplyDelete
  20. yes, you can use any optocoupler

    ReplyDelete
  21. /*
    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;
    }
    }
    }

    ReplyDelete
  22. 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

    ReplyDelete
  23. 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

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

    Thank you

    ReplyDelete
  25. 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

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

    ReplyDelete
  27. Thanks a LOT SIR,
    I appreciate your help..

    ReplyDelete
  28. 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

    ReplyDelete
  29. 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.

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

    ReplyDelete
  31. 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

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

    ReplyDelete

Post a Comment