Shop OBEX P1 Docs P2 Docs Learn Events
Relay circuit with optocoupler driven by Prop I/O — Parallax Forums

Relay circuit with optocoupler driven by Prop I/O

doggiedocdoggiedoc Posts: 2,241
edited 2011-03-21 19:27 in Propeller 1
I've been "cog"jugating some ideas in my head that use A/C motors so today I experimented with controlling an A/C device with a Propeller.

I came up with an opto-isolated relay to turn a lamp on and off as an experiment. Here is the circuit:

opto_relay_circuit.png


Should I add resistors or diodes anywhere. It works fine as drawn but I've seen other similar circuits with pull up or pull down resistors and/or protection diodes. Are these needed and if so where.

Thanks in advance,
Paul

PS - before some of you guys rip me a new one, remember this is how I learn. :D
«1

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-03-19 20:36
    You need the resistor and a diode with anything, Propeller notwithstanding.
    See attached.

    PE - Don't get me wrong, you can run with scissors, stick a pencil in your ear, stuff peanuts up your nose, take out your own appendix...
    800 x 511 - 697K
  • doggiedocdoggiedoc Posts: 2,241
    edited 2011-03-19 20:39
    That's easy enough! Thanks. I had a resistor on the Prop pin originally but wasn't getting enough current to the IR LED (homemade opto-coupler) so I took it off. Guess I should have put it back after I figured the rest out.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-03-19 20:44
    Well, DVM, I think it's better to activate the relay with the coil between +V and the collector, and the emitter connected to GND, instead, but I didn't want to force the issue. If you go that route, the diode should still be across the relay coil (anode to collector, cathode/band to +V.)
  • doggiedocdoggiedoc Posts: 2,241
    edited 2011-03-19 20:50
    Care to elaborate on the placement of the relay?
  • doggiedocdoggiedoc Posts: 2,241
    edited 2011-03-19 20:51
    I mean as far as why one way is better?
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-03-19 21:00
    Can you tell me about the "homemade" aspect first?
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-03-19 21:16
    In anticipation of your response --
    If the unknowing see relay coils in the emitter leg of an "opto" then they'll want to put them in the emitter leg of a transistor, too. They'll do so without regard to the coil voltage.

    In a "non-opto" transistor circuit, V_e is V_b - 0.7V; in the case of a Propeller V_e will then be appx 2.5V, it won't work and they'll marvel as to why (why?). V_e must be at least V_coil(min). If it's a 5V coil or a 9V coil or a 12V coil then it's not going to happen with the load in the emitter.

    So, I will teach with the coil in the collector leg always, fewer problems for "tinkerers."

    Relays are "isolated" anyway. The contacts are away, separate from the coil/s, especially if/when they have UL approval. I don't get the obsession with "optos" and "isolation" and "protection"; it's like a lot of stuff around here, superstitious behaviour.

    PE -- I'm "talking" NPN.
  • doggiedocdoggiedoc Posts: 2,241
    edited 2011-03-19 21:17
    Yes Sir. It is an IR LED and Phototransistor pair end to end and wrapped in heat shrink. (Radio shack parts)
  • doggiedocdoggiedoc Posts: 2,241
    edited 2011-03-19 21:23
    Like so: ala Forrest Mimms

    LEDopto.png
    920 x 499 - 669K
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-03-19 21:26
    Mims always uses a resistor with the IRED, but is inconsistent in presenting the relay vs the transistor. In some of his examples he uses the opto to turn on a "full-fledged" transistor.

    Is everything working now, however?

    PE - Providing your phototransistor is OK with the relay current, then that's a wrap.
  • doggiedocdoggiedoc Posts: 2,241
    edited 2011-03-19 21:36
    PJ Allen wrote: »
    Relays are "isolated" anyway. The contacts are away, separate from the coil/s, especially if/when they have UL approval. I don't get the obsession with "optos" and "isolation" and "protection"; it's like a lot of stuff around here, superstitious behaviour.
    I'm not very superstitious (as I throw salt over my shoulder) but the opto part of the circuit was the easiest why for me to visualize the level shift needed to drive the 12v Relay. Since it was what I had in my box, I "tinkered" with it until I made it work. I'll rearrange it tomorrow with the coil in the collector instead of the emitter.

    Thanks again!
  • doggiedocdoggiedoc Posts: 2,241
    edited 2011-03-19 21:38
    PJ Allen wrote: »
    Mims always uses a resistor with the IRED, but is inconsistent in presenting the relay vs the transistor. In some of his examples he uses the opto to turn on a "full-fledged" transistor.

    Is everything working now, however?

    PE - Providing your phototransistor is OK with the relay current, then that's a wrap.

    I soldered it all together earlier on a proto-board and its driving a compact fluorescent bulb off and on with no "apparent" issues.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-03-19 21:45
    A transistor is a current operated device. A small input current controls a (much) greater output current.
    If you want to try it with a NPN, and I encourage you to do so, please note the attached circuit.
    468 x 258 - 53K
  • doggiedocdoggiedoc Posts: 2,241
    edited 2011-03-19 21:48
    I can do that. I have no shortage of 3904s - will that suffice?
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-03-19 21:49
    Definitely so.
  • kwinnkwinn Posts: 8,697
    edited 2011-03-20 10:21
    I agree with pretty much everything posted here except the "I don't get the obsession with "optos" and "isolation" and "protection"; it's like a lot of stuff around here, superstitious behaviour.". The optos provide additional protection to the driving circuit and allow the grounds to be isolated as well, thus avoiding potential "ground loops" and noise pickup.

    Consider what happens if the transistor driving the relay should short out. You now have the output driving that transistor connected to +12V through a low value resistor. If you have a 1K or larger resistor between the prop pin and the base of the transistor the prop should survive....probably. What if that is a 24V or 48V relay? What happens if the 12/24/48V regulator shorts and applies a considerably higher voltage to the relay coil?
  • Heater.Heater. Posts: 21,230
    edited 2011-03-20 10:28
    Not much an idea here but if the opto LED is on permanently why does the optos transistor not burn as the relay coil becomes a short. Are we relying on the power handling of the transistor and the resistance of the coil?
  • kwinnkwinn Posts: 8,697
    edited 2011-03-20 10:37
    Heater. wrote: »
    Not much an idea here but if the opto LED is on permanently why does the optos transistor not burn as the relay coil becomes a short. Are we relying on the power handling of the transistor and the resistance of the coil?
    Not sure if this question was directed at me, but here goes. If the coil shorts the opto transistor will almost always burn out. Since there is an insulation layer between the opto led and the opto transistor good for about 4KV nothing will happen to the led or it's drive circuit (the prop pin or whatever). Once you replace the relay and opto isolator you are back in business.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-03-20 10:56
    There are no separate grounds in the stated situation.
    Does that make sense?

    There's no opto-isolation in a ULN-2803, an industry stalwart, open-collector outputs all the way, just as in the example I provided using a discrete transistor. I guess those should all be trashed; no opto-isolation, inferior, not dummy-proof, not radiation-hardened, not approved for medical, 4kV isn't 10kV isn't 100kV, man the life-boats, women and children first, klang-klang-klang!!

    You WIN, kwinn !
  • TappermanTapperman Posts: 319
    edited 2011-03-20 11:01
    kwinn wrote: »
    "I don't get the obsession with "optos" and "isolation" and "protection"; it's like a lot of stuff around here, superstitious behaviour.".

    Everyone has a 'preferred' approach. And they are always ready to provide a complete run down, as to 'why' their method is 'preferred'.
    kwinn wrote: »
    Consider what happens if the transistor driving the relay should short out.

    In that case, you just order another propeller. After the smoke clears.

    ... Tim
  • Heater.Heater. Posts: 21,230
    edited 2011-03-20 11:02
    kwinn,

    What I meant was that when the optos LED is on the transistor is conducting. The only limit to the current is the resistance of the coil. So presumably one has to be sure the resistance of the coil is enough to limit the current and avoid burning the optos transistor.
  • kwinnkwinn Posts: 8,697
    edited 2011-03-20 11:15
    PJ Allen wrote: »
    There are no separate grounds in the stated situation.
    Does that make sense?

    There's no opto-isolation in a ULN-2803, an industry stalwart, open-collector outputs all the way, just as in the example I provided using a discrete transistor. I guess those should all be trashed; no opto-isolation, inferior, not dummy-proof, not radiation-hardened, not approved for medical, 4kV isn't 10kV isn't 100kV, man the life-boats, women and children first, klang-klang-klang!!

    You WIN, kwinn !

    Previous posts were discussing individual transistors not ULN chips, which do have internal circuitry that provides a degree of protection. They are popular chips and have many uses in all the areas you mention and more. Opto isolators do provide more protection and permit you to isolate both the ground and power sides of the drive circuitry from each other when that is necessary. Which one you choose to use depends on the requirements of that particular application. It is not however a matter of obsession or superstitious behavior.
  • kwinnkwinn Posts: 8,697
    edited 2011-03-20 11:22
    Heater. wrote: »
    kwinn,

    What I meant was that when the optos LED is on the transistor is conducting. The only limit to the current is the resistance of the coil. So presumably one has to be sure the resistance of the coil is enough to limit the current and avoid burning the optos transistor.


    Yes, the coil current must be low enough for the opto transistor to handle. For relays that require more current than the opto transistor can provide an additional drive transistor is added. The opto transistor and drive transistor are often connected as a darlington pair. As always, a suitable diode is connected across the relay coil.
  • Heater.Heater. Posts: 21,230
    edited 2011-03-20 11:24
    And opto's don't always save you. I was recently struggling with a noise prone circuit.

    1) Outputs from an 8055 PIO card in a PC.
    2) Shielded cable from PC 8055 card connector to a board containing a back of opto isolators.
    3) Opto isolators output switching current to another back of optos.
    4) Second back of optos driving some equipment.
    5) Power for LEDS in between the two opto banks coming from a battery.
    6) Power for the equipment from a bench power supply.
    7) Ended up running the PC from batteries in an UPS to ensure there is no common ground between PC and the equipment.

    Result, turn the bench power supply on and off and often the 8055 in the PC would reset, outputs becoming inputs.

    We never figured out how to prevent that behaviour.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-03-20 11:25
    You're wrong, it's the same bloody thing, they don't build fail-safes into the design.
    Are you making this up as you go along or what?
    Again, there's no separate ground situation per the OP. Do you get that?

    When people run optos' LEDs off microcontroller pins without limiting resistors, their worry being "protection" and/or "isolation", as I've seen often round these parts, then it IS obsession and superstition.

    You offered no opto-isolation advise for the other genius who finally decided that he would run his LED backlight from 8 unused Propeller pins.
  • kwinnkwinn Posts: 8,697
    edited 2011-03-20 11:57
    Heater. wrote: »
    And opto's don't always save you. I was recently struggling with a noise prone circuit.

    1) Outputs from an 8055 PIO card in a PC.
    2) Shielded cable from PC 8055 card connector to a board containing a back of opto isolators.
    3) Opto isolators output switching current to another back of optos.
    4) Second back of optos driving some equipment.
    5) Power for LEDS in between the two opto banks coming from a battery.
    6) Power for the equipment from a bench power supply.
    7) Ended up running the PC from batteries in an UPS to ensure there is no common ground between PC and the equipment.

    Result, turn the bench power supply on and off and often the 8055 in the PC would reset, outputs becoming inputs.

    We never figured out how to prevent that behaviour.

    Opto isolation is not a panacea. If the rest of the circuitry has common connections they may not be any help. I had a bone densitometer that would very intermittently (once every 2-3 weeks) show a hole in a patients spine or pelvis. The data acquisition and high powered imaging electronics were isolated by opto isolators. Even after replacing all the electronics, the computer, and the detector the problem was still there. Even the UPS did not help. After many months I eventually found the cause. It was an old infrequently used X-ray machine two floors down in the opposite corner of the building. When it was powered up the high voltage was set by a mechanical rotary switch that produced huge noise spikes on the AC power lines. They were big enough to to get through the UPS transformer/filters/inverter, and the densitometer transformer/filter/regulator to show up as X-ray pulses in the electronics. Since bone absorbs X-rays these pulses showed up as holes in the bone image.
  • Duane C. JohnsonDuane C. Johnson Posts: 955
    edited 2011-03-20 13:05
    You can simplify your opto-isolator considerably by using Blue LEDs in a circuit similar to PJ Allen's.

    Blue LEDs have considerably more forward voltage than the silicon IR LEDs.
    I just measured this with my test StickProp computer running at 3.335V.
    Directly connecting the BLUE LED to an OUTA pin the voltage is 2.956V at 10.4mA.
    This is well within the pin output current specification.

    Second I measured the companion BLUE LED.
    The open circuit voltage is 2.207V.
    The short circuit current is about 1uA.

    Now directly drive an IRF3708 MOSFET gate with the BLUE LED and a 10MO resister
    across it to tutn it off.
    http://www.redrok.com/MOSFET_IRF3708_30V_62A_12mO_Vth2.0_TO-220.pdf
    The on resistance of this MOSFET driven this way is about 37mO and can drive
    about 7A while dissipating about 2W which shouldn't require a heat sink.
    BlueOptoIso.jpg

    Duane
  • kwinnkwinn Posts: 8,697
    edited 2011-03-20 13:09
    You're wrong, it's the same bloody thing, they don't build fail-safes into the design.
    Are you making this up as you go along or what?

    If you are referring to:
    “Previous posts were discussing individual transistors not ULN chips, which do have internal circuitry that provides a degree of protection.”
    I was referring to the 2.7K resistor and the transistor between the output transistor as shown on the ULN 2803 data sheet. If the output transistor shorts they may offer some protection.

    Again, there's no separate ground situation per the OP. Do you get that?

    I understand that in this particular instance there is no separate ground. I am referring to the use of opto isolators in general while you are referring to the specific circuit in this thread. Calling the use of opto isolators “obsession and superstition” is a pretty general statement.

    Let me state it clearly. No, in the case of this circuit an opto isolator is not required. I will also state that No, there is no reason other than extra cost for not using one.
    When people run optos' LEDs off microcontroller pins without limiting resistors, their worry being "protection" and/or "isolation", as I've seen often round these parts, then it IS obsession and superstition.

    As I said in my first post, I agree with pretty much everything posted here (to that point) except the "I don't get the obsession with "optos" and "isolation" and "protection"; it's like a lot of stuff around here, superstitious behaviour." Since your first post covered the current limiting resistor and diode I felt no need to mention it again.
    You offered no opto-isolation advise for the other genius who finally decided that he would run his LED backlight from 8 unused Propeller pins.

    I take it you are referring to the “PWM to control LED brightness & contrast” thread started by Cluso99. In that particular case there was no need for an optical isolator since he was going to be using the Vcc voltage and the power was relatively low. As for him being a genius and deciding to run his backlight from 8 unused prop pins, after reading so many his posts and replies I have a lot of respect for him, and taking advantage of unused pins rather than putting additional hardware on the board seems like a reasonable approach to me.
    I would suggest you read his post from yesterday at 9:03pm.
  • kwinnkwinn Posts: 8,697
    edited 2011-03-20 13:17
    Tapperman wrote: »
    Everyone has a 'preferred' approach. And they are always ready to provide a complete run down, as to 'why' their method is 'preferred'.

    True, and sometimes discussing the why gives you a better insight into the use of that approach.
    In that case, you just order another propeller. After the smoke clears.

    ... Tim

    I prefer to replace the cheaper opto isolator rather than have to reprogram and replace the prop, and possibly a lot of other circuitry like the eeprom, regulators, etc.

    Opto isolators can also make some designs much easier and more flexible as well.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-03-20 14:02
    kwinn,
    Doing a thing based on faith, or on the basis of not understanding, is superstition.
    Your arguments are evasions. You introduce non-existent situations as a basis for objections.
    Scouring a datasheet and coming up with some wagon-load that an internal bias resistor "may introduce some protection" is meaningless, more grasping at straws.
    Myriad layers of delusional fail-safes and imagined stop-gaps amounting to nothing.

    A relay coil is isolated from its switch contacts.
    The prevalent willy-nilly implementation of opto-isolators, as though they were some sort of magic pills that counter the consequences of staggering foolishness and mishaps real or imagined, is obsessive and/or superstitious.
Sign In or Register to comment.