[Newbie] 24v Relay + transisor + optocoupler -> arduino

im struggling to make this work, but since i have a big lack of transistor working im asking for help

i have an optocoupler to drive a 24v relay, to switch 220V... can someone give me a light here or give me a working example? i was thinking on using a 2n2222 but the more i google the more im lost i came up with a site with this schematic:


http://todohard.awardspace.com/ctos/rele/pic/e-s.ht14.jpg
Ref: http://todohard.awardspace.com/ctos/rele/pic/

EDIT:
Relay is 24v / 1K1 coil

Is the primary coil 24vdc or 24vac? How is it powered? If AC (like my HVAC relay) a transistor won't do it. You'll need a triac.

its 24vDC i made a small font with a 7824 :slight_smile:

OK. Where is the power to the 7824 coming from? Battery? Transformer? Solar panel?
Is there 24vdc on the output of the 7824?

yeah, im giving a 30vDC input to the regulator, my only problem is that i sent the relay as a load to the optocoupler and i THINK that the relay is too much current for the opto, thats why my first post is about a working schematic or the possible need for a transistor :S

Does the relay activate if you jumper the Q1 transistor with a wire?

The resistor R2 in that schematic may be too high. Maybe try a 1K resistor there rather than 10K.

Edit: The transistor in that schematic is a PNP, not NPN like a 2N2222.

sorry SurferTim but i made a mistake in my translation:
im NOT using that schematic, im currently trying to drive the relay directly with the opto and its not working.
im interested in the schematic i pasted but im not sure if it will work in 24V AND if that transistor is the right one

Not a problem. I just found your schematic. It is the second link above.

Does the relay activate if you jumper that transistor Q1 with a wire? This will check if the power supply is good enough to power the relay.

im not sure if you understood, but i want to use that circuit, im NOT using it now, i posted it to get an opinion if it was ok for using it in a 24v enviroament

about your question, the relay works OK if I put the coil to the 7824 output :slight_smile:

I would use a 2N2222, but yes, that should work.

drop in replacement, right?
also, do you think r1 and r2 are OK?

Yes, drop in.

Now you are talking about the other schematic. The way it is set up, it will not work. That circuit is for a PNP transistor.

Connect R2 from +24v to pin 5.
Connect the transistor base to the opto-isolator collector (pin 5) directly. No resistor.

Now the logic will be backwards. Activating the opto-isolator will disable the relay.

lol, im more lost now, dont hate me XD

what i want to do is to get the relay ON when i put the arduino pin HIGH

No hate here! :slight_smile:

Is there a reason you need the opto-isolator? Is the Arduino power supply completely isolated from the relay power supply?
No common ground connection?

im using an opto because of arduino protection from the reverse voltage of the relay coil (yeah, i also have the diode too) and because im switching 220vAC with the relay

You could be switching 2400vac with the relay contacts. That has nothing to do with the coil. It is +24vdc.

I would drop the opto-isolator.

but that way there is a very small chance that in case of failure of the transistor i send 24v to the arduino pin, right?

There is also a small chance that the 240vac wires will become disconnected from the relay contacts and connect to the Arduino power supply. That would be 240vac into the Arduino. :frowning:

If you use those components correctly, there is very little chance of that happening. The 2N2222 is pretty good at this kinda stuff as long as the current is less than about 200ma.

ok. i will trust you XD

so, to make the schematic in the first post work OK with an input of 24vDC i have to replace R2 with one of 1K?? and thats all?

Yes. The 2N2222 has a high gain at that current. A 1K resistor should put about 3ma into the base. At a gain of 100, that would be 300ma collector-emitter. You could probably use a higher resistance than 1K. Maybe 5K would be ok.

You want to insure it is on all the way, not just partially. That could cause heating problems with the 2N2222. Best is to check the collector-emitter voltage when it is "on". The voltage drop across the transistor should be close to zero.