Go Down

Topic: Arduino -> Optocoupler -> Relay problem (Read 5 times) previous topic - next topic

Mitchell Christensen

Hey,

I'm using an Arduino UNO to drive a relay via an optocoupler, and the relay on the other side of the optocoupler refuses to activate.

I'm connecting the digital pin 4 through a 180 ohm resistor to a TLP521 http://www.toshiba.com/taec/components2/Datasheet_Sync//206/4215.pdf optocoupler.  At 5v the 180 ohm resistor should provide 27ma to the TLP521.  The TLP521 has a Current Transfer Ratio of 50%, which should provide 13+ma to the relay coil which requires 12ma to operate.

When I activate pin 4, I see 5v at the input to the optocoupler, but the relay coil won't operate.  If I bypass the optocoupler, pin 4 operates the relay coil just fine.

Does anyone have any experience with optocouplers and might be able to provide some insight?  Perhaps some suggestions for test I can run to get to the bottom of this?

Thanks in advance.
-Mitch

rtadams89

Are you providing any voltage to the relay side of the optocoupler?

retrolefty

#2
Feb 06, 2012, 04:59 pm Last Edit: Feb 06, 2012, 05:02 pm by retrolefty Reason: 1
Quote
At 5v the 180 ohm resistor should provide 27ma to the TLP521.  The TLP521 has a Current Transfer Ratio of 50%, which should provide 13+ma to the relay coil which requires 12ma to operate.


I suspect you don't have a correct understanding of what 'current transfer' means. There is no real current transferred from the internal LED to the internal light sensor. You must provide a proper DC voltage source for the relay coil power that the opto's output transistor can then turn on or off.

Lefty


John_S

An optocoupler will not pass current from the input to the output. That's how they provide isolation between two circuits.

Note to utilize the isolation you need a separate power supply for the load. See the diagram below. Swap the Resistor on the right for your relay coil (don't forget the flyback diode) and it should work.


Mitchell Christensen

Sorry...I neglected to state that I also feed +5v and GND to the coil side of the optocoupler.  The +5v is coming straight from the power supply.  The power supply is rated at 500ma and my entire circuit is currently consuming ~30ma, so the additional 40ma shouldn't be a problem at all for the power supply.

-Mitch


retrolefty


Sorry...I neglected to state that I also feed +5v and GND to the coil side of the optocoupler.  The +5v is coming straight from the power supply.  The power supply is rated at 500ma and my entire circuit is currently consuming ~30ma, so the additional 40ma shouldn't be a problem at all for the power supply.

-Mitch




Can you show us a complete drawing of your setup?

Lefty

Mitchell Christensen

Sorry...you're right.  A picture is worth a thousand words.

Here is my schematic,


The +5v feeding pin 7 of the TLP521 (through the 180 ohm resistor) comes from digital pin 4 of an Atmega328, and as such should be rated at 40ma.  The +5v feeding pin 10 of the TLP521 comes directly from my power supply.  The coil on the relay http://www.pickercomponents.com/Data_Sheets/PC458_Data_Sheet.pdf is rated at 208 ohms (which works out to 24ma), but the manufacturer told me it generally operates fine at 12ma (I may add a resistor at some point).

If I remove the TLP521 from the socket, I see +5v at pin 10 and +5v at pin7 (once I activate pin 4 on the Atmega).  However, I plug the TLP521 in and the relay just sits there.  I have replace the TLP521 with a new one...same thing.

Thanks again for your help.

-Mitch

dc42

1. In calculating the current through the 180 ohm resistor, you haven't allowed for the voltage drop of the IR emitter in the optocoupler. The datasheet gives it as 1.15v typical at 10mA. It will be a little more at 27mA.

2. You haven't allowed for the saturation voltage of the optocoupler. Below Vce around 1v, the current transfer ration will be lower. So you'll need to provide around 6v or a little more to the relay + optocoupler combo for it to work.

Why are you using an optocoupler, when the relay provides isolation already?
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

retrolefty

You have wired the output transistor wrong, it needs to be in a 'low side' npn switching configuration. Ground the emitter pin 9, wire pin 10 to C1 on the relay, wire C2 on relay to +5vdc. That should work.

Lefty


dc42


You have wired the output transistor wrong, it needs to be in a 'low side' npn switching configuration. Ground the emitter pin 9, wire pin 10 to C1 on the relay, wire C2 on relay to +5vdc. That should work.


I'm sure it won't make any difference whether it is wired as a low- or high-side switch. It's not the same as a regular transistor whose base is driven from an Arduino pin, it's a phototransistor and the base is not connected.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

retrolefty

#10
Feb 07, 2012, 02:02 am Last Edit: Feb 07, 2012, 02:03 am by retrolefty Reason: 1
I would suggest you try my method anyway, just to humor me if nothing else. Then if it works we can talk all day on why. If it doesn't then I guess optos just don't work in your part of the world, a nearby black hole influence perhaps?
Wait you live near me and my optos work OK!

Mitchell Christensen

Thank you guys so much for responding.

Retrolefty, your suggestion will require a board modification, which is...painful since I'm building these by hand...on weekends.  If you are confident that this is the problem, then I will spin a board, no problem.  I'm going to see if I can cut some traces and add some wires to make your recommended changes to my current board tonight to confirm that solves the problem.

Dc42, your suggestions certainly do sound well informed, but more difficult to take action on.  Are you suggesting that dropping the 180 ohm resistor value to accomodate the voltage drop across the IR emitter in the optocoupler is all that is necessary on that side of the optocoupler?  As for increasing the voltage to the coil, that would be a big problem.  I'd have to redesign my power supply significantly to get the 6v you recommend.  Also, how does this account for the fact that the 5v out of my power supply operates the relay just fine?  Are you asserting that the addition of any switching electronics (NPN, etc.) would introduce a voltage drop that would render my +5v insufficient?

Being a software engineer by profession, this EE stuff is quite new (and confusing) to me, so I really appreciate your help and patience.

Thanks guys.
-Mitch

dbvanhorn

I also am curious as to what the opto is buying you here, if I read correctly and GND and +5V for the relay are coming from the system.  Might as well use a good old NPN configured as an open collector driver for the relay.

Optoisolators are fine, but they have some significant limitations, usually speed and Ic/Vce ratings.  I wouldn't expect one to drive a relay other than maybe a reed relay.  CTR can be less than unity.

A book that would probably help:  Horowitz and Hill  "The Art of Electronics".  It covers all these topics in detail.
An EXCELLENT reference!

Mitchell Christensen

I'm afraid there is something else going on here.  I pulled the TLP521 out of its socket and decided to measure the current being provided by digital pin 4 on the Atmega328.  Given +5v through a 180 ohm resistor I expected to see 27+ma, but I only see 13ma.  Forget the optocoupler and the relay, setting pin 4 high (+5v) and feeding across a 180 ohm resistor to GND only draws 13ma?  That seems to violate Ohm's Law, and I believe thats why my relay doesn't fire.

I have double checked that the total resistance of the circuit (pin 4, through the resistor, all the way to GND) is 178.8 ohms.  I have confirmed that I have set pin 4 to OUTPUT in setup().  I have tried two separate Atmega328 chips running the same program (one brand new, and the other is older), both stop at ~13ma (the second is slightly higher...14ma). I am running the Atmega328 in my own board (i.e. not an Arduino).  Could I have an assembly/solder problem?  I eliminated my power supply completely by powering my board entirely from an off-board Arduino I wired in.  Still 13ma on pin 4.

Any ideas why pin 4 is only giving me 13ma?

Sorry for the earlier misdirection.

-Mitch

dbvanhorn

Did you subtract the forward voltage of the optos LED when calculating current?  Also check the data sheet, the io pin may 'droop' some at that current level.

Go Up