Resistor values with Opto Isolator - Page 1
Forum section: electronics / beginners

author: Bskitter
author_rank: Regular Contributor
timestamp: May 19, 2016, 09:09:00 pm
content: Hey Guys,So I made a post a few days ago about some trouble I am having with controlling relays with a 74HC595 shifting register chip, I cant for the life of me figure out where I am going wrong.I have triedRC snubbers on Relay contacts and the coils + and -Pull up Resistors on DS pin, STCP pin and SHCP pinsRC snubber on DS pin (data pin)Different power suppliesDifferent Relays including Arduino Relay Shieldshttp://hstech.ro/HC595/This guy had the exact same configuration as me except I only have 8 relays where he has 16 (I think)I copied that schematic (on the site provided) exactly and still did not fix in my problemI Have a relay shield with opto iso's , IF is use two separate power supply the interference does not happen.This is forcing me to now go with an option of running two power supplies in project.This is the relay design nowI want to change it to something like this(Please ignore the led and tranistor codes inside the opto iso i just made a look alike since the site I was using did not have an actually icon for one )I dont know what Resistor values are required here tho, could you guys please recommend what resistors I should use or any changes to this configuration ?I have an PC817 Opto IsoByron

author: danadak
author_rank: Super Contributor
timestamp: May 19, 2016, 09:25:26 pm
content: R1 is just to limit base drive to all thats needed to saturate Q2. For thatto occur Ib = Ic / 10 to insure saturation. So R1 = ( V1 - Vcesatcouplertransistor - Vbeq2 ) / Ib.R2 is just to limit LED current , so look up that in datasheet, recommendedLED operating current, and R2 = ( Vddcpu - Vohpin - Vled ) / IledRegards, Dana.

author: rstofer
author_rank: Super Contributor
timestamp: May 20, 2016, 03:19:43 am
content: Quote from: danadak on May 19, 2016, 09:25:26 pmAll of which is shorthand for the fact that without a datasheet for the opto, there is no way to give you a numeric answer. We should also have the relay coil detail so we can figure the 2N2222 collector current and back into the base current. There needs to be enough base current to saturate the transistor and eliminate excessive heating.The other 'gotcha' is that the 595 doesn't want to source or sink very much current - on the order of 5 mA for the conditions in the datasheet. Yes, the MAX is higher than that but realistically, the device isn't designed for driving high current loads. Which brings us back to the opto: Can we get the output into saturation with as little as 5 mA of LED current? Datasheet time...

author: Bskitter
author_rank: Regular Contributor
timestamp: May 20, 2016, 10:10:08 am
content: Datasheet time is here,Also the coil Specs are12V220Ohms55mA

author: Bskitter
author_rank: Regular Contributor
timestamp: May 20, 2016, 10:18:25 am
content: RCL = (Vcc-VF)/IF= (5V-1.2V)/0.020 A= 190 ohms (round down to 180 or up to 200 ohms)But what about the resistor of the base on the n2222 ?This saturation mode confuses me a bit,Could some explain the calculation for dummies to me please ?The most I know is that saturation mode is where the transistor acts as a switch.

author: danadak
author_rank: Super Contributor
timestamp: May 20, 2016, 10:49:11 am
content: In order to drive a bipolar T into saturation one has to drive enoughbase current to force the collector junction into forward bias. This occurswhen the beta drops sufficiently, and the industry rule of thumb is 10,so Ib = Ic / 10.http://www-inst.eecs.berkeley.edu/~ee105/sp08/lectures/lecture5_2.pdfhttp://www.ittc.ku.edu/~jstiles/312/handouts/Example%20A%20BJT%20Circuit%20in%20Saturation.pdfRegards, Dana.

author: Cervisia
author_rank: Regular Contributor
timestamp: May 20, 2016, 10:51:05 am
content: You don't need 20 mA through the LED.First, determine how much current you need through the relay. Is that 55 mA the minimum needed to close the relay, or the Absolute Maximum rating (i.e., the current at which it can explode)?Assuming that you actually need 55 mA, and that the transistor is to be saturated, we force Ic/Ib = 10, so the needed base current is 5.5 mA.Now use the current transfer ratio of the PC817 to determine the required LED current. If your chip isn't labeled A/B/C/D, its worst-case CTR is about 50 %, so the required LED current would be 11 mA. If your shift register cannot supply that, use a separate transistor to amplify the current for the LED, or measure the optocoupler's actual CTR (and then choose a better one, if needed).

author: Zero999
author_rank: Super Contributor
timestamp: May 20, 2016, 12:27:49 pm
content: Quote from: Bskitter on May 19, 2016, 09:09:00 pmWhy are you using both an opto-coupler and a relay?The 74HC595 is more than capable of directly driving a transistor and a relay provides galvanic isolation. There is no need to have an opto-coupler, as well as a relay.

author: danadak
author_rank: Super Contributor
timestamp: May 20, 2016, 12:41:39 pm
content: Transistor saturation, attached.Regards, Dana.

author: rstofer
author_rank: Super Contributor
timestamp: May 20, 2016, 02:20:13 pm
content: The single transistor scheme should work. The video is interesting but I'm not clear on what voltage is being applied and where.Your decoupling caps (0.1 ufd ceramic) need to be as close as possible to the Vcc and Gnd pins at each chip. Right at the chip.I would be looking at the power supply with a scope. There's something wrong if the supply is so wimpy that it drops out when switching relays. OTOH, switching all 8 at the same time might be an issue.I have used the 2N2222A for driving relays many times with no issues. There is something wrong with your power scheme. It's unfortunate but without using an opto, the ground between the logic and relays must be common. It can be two separate ground planes connected together at a single port but they must be connected.The Arduino Relay Shield uses a similar scheme except that they use PNP transistors. Here is the schematic:https://www.bing.com/images/search?q=arduino+relay+shield+schematic&view=detailv2&&id=A0A2FE751FBE845150C292F6E99B997B4C8DF0A0&selectedIndex=3

author: danadak
author_rank: Super Contributor
timestamp: May 21, 2016, 12:20:53 am
content: Keep in mind from the basic C equation you can get a rough idea ofC size needed to prevent droop.Q = C x V, I = C x dV / dTSo look up transient response time of the reg, that becomes dT. You know the total Ifrom relay specs (total of all 8, that's worst case). Now stipulate dV you will tolerate,and compute C = ( I x dT ) / dV. Amps, Volts, Farads are units used in eqns.This is an oversimplification, loop dynamics a little more complicated, but a gross way of getting tosize of C. Its also oversimplified as C is a f( V across cap).Regards, Dana.

author: Zero999
author_rank: Super Contributor
timestamp: May 21, 2016, 01:31:35 pm
content: Have you tried this.

author: Bskitter
author_rank: Regular Contributor
timestamp: May 21, 2016, 02:33:26 pm
content: Hi All !Thank you for all the feedback !@Hero999I have not tried that configuration, But I will when I get home later.Also the opto coupler will be used to separate the power from the relays and the logic part of the project,I have a feeling the power supply part of my project could have the problem,So the two problems that arise when I apply 230VAC through the relayThe 595 Chip somehow gets effect and loses the data in its register, I have probed every possible input on that chip and have seen nothing.The Arduino USB controller disconnnects as well, this tells me that there could be dip or spike in power.Now I have not explained How I am powering my project.I have a meanwell switching power supplyhttp://www.gmelectronic.com/switching-power-supply-mean-well-lrs-35-12-p332-892This one to be exactwell its Very basic, 1st here is a photo of the power supply board I have builtit consists of two LM2575 switch regulators, and one LM7805 linear voltage regulator(On the picture of my board it does look different but this is before I made the change)And I have followed these schematics.Could a sudden spike in the system cause the switching regulators to do something strange ?I also noticed that if the relays are closer to the power supply and Arduino the Problem is a lot more apparent !Any idea guys ?l

author: Zero999
author_rank: Super Contributor
timestamp: May 21, 2016, 05:02:20 pm
content: Quote from: Bskitter on May 21, 2016, 02:33:26 pmAs the 5V supply to the logic is provided by an unisolated voltage regulator, it can't be separate from the power used for the relays and there's no point in using an opto isolator.Another possibility is using a relay which can be driven directly by the 5V signal from the 74HC595.QuoteDo you only get those problems when 230VAC is applied to the relays? If so, what are you switching with the relays?

author: Bskitter
author_rank: Regular Contributor
timestamp: May 21, 2016, 06:07:56 pm
content: @Hero999I use the N2222 tranistor controlled by the 595 which is the controlled by the Arduino.I have probed everywhere with a scope and can so NOTHING, no interference at all :/This spike somehow creeps around in the Ground.

author: danadak
author_rank: Super Contributor
timestamp: May 21, 2016, 06:32:40 pm
content: If you have a DSO you can try two things to catch a spike -1) Set scope on infinite persistence, and over a few seconds see if anythingshows up outside supply rails.2) Set triggering up for a runt pulse, try 100 uS for a trail run, see if scopetriggers.Regards, Dana.

author: Bskitter
author_rank: Regular Contributor
timestamp: May 21, 2016, 06:52:23 pm
content: @DanaSo I am probing around again !and now I see a -5 dip as soon as the relays shutdows I saw this dip between ground and Vcc of the 595 register chip !Now before I continue please note i have this scope !http://www.ebay.com/itm/DSO138-2-4-TFT-LCD-Digital-Oscilloscope-DIY-Kit-1Msps-200KHz-Bandwidth-W-Probe-/191827754952?hash=item2ca9d33fc8:g:eRgAAOSwyjBW5oplI know its not the best but it is all I have for now.How do I get rid of this dip.My Idea is to just put a large cap between gnd and vcc of the chip ?Any suggestions

author: Bskitter
author_rank: Regular Contributor
timestamp: May 21, 2016, 06:55:59 pm
content: Note the gnd of the osciliscope is connected to the collector of the 2n2222 !

author: Bskitter
author_rank: Regular Contributor
timestamp: May 21, 2016, 07:00:02 pm
content: NOW I AM CONFUSEDI just put a dioide (n4007) between ground of the supply and ground of the 595 and the realy now does not shut down. WTF ?Please could someone explain this ??

author: Zero999
author_rank: Super Contributor
timestamp: May 21, 2016, 07:23:09 pm
content: It's not possible to tell you what's wrong, without a complete schematic.

author: Bskitter
author_rank: Regular Contributor
timestamp: May 21, 2016, 07:55:49 pm
content: Hey Hero999Ill get to posting a full schematic soon, just tried to draw it on this site and then they asked me to pay and it lost my sketchIll draw it somehow (in paint)but the problem goes away if i put a diode on vcc and gnd of the 595, the coil has a bit of a buzz to it tho !I suspect the flyback diode is not doing the job it is meant to be doing !

author: Bskitter
author_rank: Regular Contributor
timestamp: May 21, 2016, 09:20:01 pm
content: Here they are Sorry for the quailty if you can recommend a good free circuit drawing site I could put it in there.

author: danadak
author_rank: Super Contributor
timestamp: May 21, 2016, 10:49:31 pm
content: For drawing schematics use the free spice tools like -http://www.ti.com/tool/tina-tihttp://www.analog.com/en/design-center/interactive-design-tools/adisimpe.htmlhttp://www.linear.com/designtools/software/LTC SpiceThey have a schematic capture front end.In your schematic do not separate grounds with a diode. All grounds should meet atthe supply.Your scope is simply too slow to capture fast transients like you are experiencing. When thetime comes and you can upgrade consider a scope of 100 Mhz or better.http://cp.literature.agilent.com/litweb/pdf/5989-5733EN.pdfRegards, Dana.