n2222 with Opto Iso PC817

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 tried

  • RC snubbers on Relay contacts and the coils + and -
  • Pull up Resistors on DS pin, STCP pin and SHCP pins
  • RC snubber on DS pin (data pin)
  • Different power supplies
  • Different Relays including Arduino Relay Shields

http://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 problem |O

I 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 now

I 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 Iso

Byron

I cant for the life of me figure out where I am going wrong.

This doesn't tell us anything. You need to tell us what you did and what happened when you did it.\

"I tried [this] and [that]....etc"
doesn't tell us how you connected anything so that doesn't help either.

What is your question ?

Your original circuit looks good, there should be no need to make it more complicated.

IF is use two separate power supply the interference does not happen.

Are the GNDs of both supplies connected together?

"This guy had the exact same configuration as me except I only have 8 relays where he has 16 (I think)"

Are you using his 16-output sketch (too)?

If you are using an opto-isolated relay board you may not need a ground wire to Arduino, what are the relays switching?

I want to change it to something like this

PC817

What's the forward voltage and current of the opto led ?

VF = 1.2 V @ 20mA

IF = 20mA
Vcc = 5V

RCL = (Vcc-VF)/IF
= (5V-1.2V)/0.020 A
= 190 ohms (round down to 180 or up to 200 ohms)

Hi,
Sorry..confused.
Are you using an optoisolated relay board or are you building your own?

If "really optoisolated": then the ground of the relay power supply does not need to be connected to Arduino ground.

See info about optically-isolated relay boards HERE:

If "really optoisolated": then the ground of the relay power supply does not need to be connected to Arduino ground.

Good catch Terry. I didn't notice the ground symbols were the same. They should look different for isolation as you pointed out. Why use an opto isolator if you're going the share the GND ?

Hey Guys ! thank you for all the feedback,

I will use separate Power supplies with separate grounds. so the relays will have their own power supply

@raschemmel, I had the whole circuit hooked up with just n2222 transistors controlling the output Everything worked Perfect until I started putting 230VAC through the relays, then all these relays started to bounce around.

raschemmel:
VF = 1.2 V @ 20mA

IF = 20mA
Vcc = 5V

RCL = (Vcc-VF)/IF
= (5V-1.2V)/0.020 A
= 190 ohms (round down to 180 or up to 200 ohms)

Thanks for the calculation ! so I put this (180ohm res) between the 74HC595 and the Anode of the optoisolator, but what about the diode between the emitter and base of the n2222 ?

The characteristics of the coil:

12V

220Ohm

55mA

@Runaway Pancake !

Not using his sketch !

But about my program !

I only upload the data to the chip ONCE ! In the start up and NOT in the loop.

eg

void setup()
{
  pinMode(DS_pin_RELAY, OUTPUT);
  pinMode(STCP_pin_RELAY, OUTPUT);
  pinMode(SHCP_pin_RELAY, OUTPUT);
  pinMode(ena, OUTPUT);
  digitalWrite(ena,LOW);//Sets OE pin of ship to LOW 
 data sheet it says active LOW 
  for(int i = 0;i<8;i++)
    {
    regon_RELAY[i] = HIGH;
    regoff_RELAY[i] = LOW;
    }
    writeregon_RELAY(); // This turns on all outputs to HIGH 
}

I do this because I want the data in the register to stay the same no matter what happens on the relays.

I put 4k7 Ohm resistor on all data pins (dose not help)

RC circuit has shown on the other guys website (in my first post)

100nf to ground--- DS pin from Arduino ---100Ohm to DS pin on chip

Byron

but what about the diode between the emitter and base of the n2222 ?

You sound smart enough to calculate that yourself from the 2n2222 datasheet.

for an hfe of 100

and an ILoad of 1A ,

VBESAT = 0.5 V

Ib = ILoad/hfe
= 1 A /100

= 0.010 A (10 mA)

then Rb = (12V -0.5 V)/0.010 A

= 11.5 V/0.010 A

= 1150 ohms (round down to 1 k)