PDA

View Full Version : PIC to Relay



Kalind
- 10th November 2008, 11:39
Hi guys. I want to use my pic to switch on/off a load (240v Light bulb) via a 5v relay. What transistor would be suitable, what relay and what diode should i use for "flyback"?

The Master
- 10th November 2008, 13:59
I best leave the choice of transistor to someone else because im not an expert with those. I can help you with the rest though. A standard 1N4001 1A 50V rectifier diode has always worked fine for me when using relays/solenoids etc.

You could use a triac instead of a relay too. It eliminates the annoying clicking sound and enables you to control the brightness if you want to take it that far

RussMartin
- 11th November 2008, 00:26
Hi guys. I want to use my pic to switch on/off a load (240v Light bulb) via a 5v relay. What transistor would be suitable, what relay and what diode should i use for "flyback"?

There are a huge number of choices, but if you want a quick solution, a generic NPN transistor like the 2N3904 would do it. If you're using 5 volts on the relay, a 2N7000 MOSFET would be even better. You can find circuit examples for both on line.

The 1N4001 is a good choice for the flywheel diode. It's already been suggested that you consider using a triac instead of a relay, and this is an excellent idea. A sensitive-gate triac can be used, or you can use a triac driver like the MOC3033.

Kalind
- 11th November 2008, 07:22
Thanks for those quick replies russ n master. Would you happen to know of a specific model 5v relay that would be able to switch an AC load (240v house-hold globe)? I prefer using the relay although its noisy :). Im just beginner and trying to figure out controlling that triac will just end up taking too long. For now i'll use a relay. Maybe later when i have some time will i experiment with a triac.

The Master
- 11th November 2008, 10:46
Controlling a triac is pretty simple. It looked confusing to me at first because i was looking at it as a transistor. All you have to do is connect it in series with the load using the A and B pins. then you apply a short between pin B and the 3rd pin. I would definately recommend using a triac optoisolator like RussMartin said. It keeps the mains electrically safely isolated from your low voltage circuit. If you ever want to try it out yourself then i would be happy to provide some drawings and part numbers that ive used in the past.

Your choice of relay depends on a few things. You already said you want it to be operated from 5V and control a 240V bulb. You also need to think about how many amps you will be using. Not a lot for a standard 240V bulb. I think most 240V relays could handle that. I would assume you want a PCB mountable one. You can get ones with a different number of switches etc (SPST, SPDT, DPDT etc). I use Rapid for components so i usually start by looking at the relay (http://www.rapidonline.com/Electronic-Components/Relays-Solenoids/PCB-Relays) page. Unfortunately it doesnt give you a lot of information without clicking on each one. 60-4190 (http://www.rapidonline.com/Electronic-Components/Relays-Solenoids/PCB-Relays/Miniature-relay-SPCO-10A/60261) appears to be suitable for your needs and is fairly cheap.

Melanie
- 11th November 2008, 13:42
This is just a 'heads-up' when dealing with Rapid...

Avoid the 'own-brand' products (eg TruSemi for Semiconductors, or TruCap for Capacitors etc) and pick a known branded product if at all possible. I can't confirm it, but based on the number of rejects we have experienced, these could be B, C or even D grade components.

I've got TruSemi 78L05's which are the closest thing to a dead-short giving 18vDC on your boards 5v rail... and I've others which vary between 4.1v and 5.9v depending on whether you are drawing a milliamp or two!

Sometimes too cheap is just that, and we have to remind ourselves of John Ruskin's poem...

Kalind
- 11th November 2008, 14:01
Hey Master, i tried getting some info on triac's. Maybe you can send me a drawing/schematic using a triac and could you people tell me what's the difference between a solid-state relay and a normal relay. Is a solid-state relay a better option? Thanks again guys and girls :)

aratti
- 11th November 2008, 17:48
Is a solid-state relay a better option?
Absolutly yes! they are a little more expensive but they are ready to use and very easy to use. Just connect pic output pin to the dc input of solid-state relay and load on the other side (See attached schematic)

Al.

The Master
- 11th November 2008, 19:16
I wasnt saying you should order from Rapid. They are my first choice though. Other electronics suppliers will have a page for relays too. I have been buying quite a few of their own components and i cant say ive had a single problem with any of them. When i need to use a new type of component i usually buy a few different versions that appear to do the same thing and test them. If by "78L05" you mean "7805 voltage regulator" then i have been using those for a long time now and theyve always been fine. Ive only had 1 or 2 beak but that was my fault for shorting it out and not realising till i touched them. I think one actually still works after burning my finger.

Heres a wikipedia page on triacs (http://en.wikipedia.org/wiki/TRIAC). Ill post back soon with a scematic and description. Also that page says the mains pins are A1 and A2 not A and B as i said before.

RussMartin
- 11th November 2008, 19:34
Sometimes too cheap is just that, and we have to remind ourselves of John Ruskin's poem...

In the words of an on-the-air fumble by John Cameron Swayze in the early days of live television advertisements: "Remember, with Timex, you get what you pay for; and you don't pay very much."

The Master
- 11th November 2008, 19:51
Ok, heres that schematic. Im sorry its not the best looking one ever. I did it in M$ paint :P

The lefthand side of the optoisolator works exactly the same as an LED. Check the datasheet for the specific one your using for the voltage. Usually i put a 1K resistor between it and the PIC. I always put a 1K resistor between the opto and the G pin of the triac too although i cant remember why (maybe someone else can clarify this bit).

It may or may not help you but ive included a circuit that i designed to control 4 lights using triacs. I usually find that a PCB layout helps me more than a schematic so you have both just incase. The triac im using is a "BTA08-600B 8A 600V" and the opto is a "MOC3020M". Both resistors either side of the optos are 1Ks. I have a few of these circuits connected up and working perfectly

aratti
- 12th November 2008, 13:13
I think useful to add the attached schematic for all who want to use TRIAC for their ac application.
Remember that the triac side is always connected to the main. Be very careful !!

Al.

Kalind
- 12th November 2008, 17:21
OK cool!! Im taking a look at the triac now. For the solid-state, isn't there a "flyback" diode required?

RussMartin
- 12th November 2008, 21:44
I think useful to add the attached schematic for all who want to use TRIAC for their ac application.


I suggest the upper schematic. You might be happier with a MOC3033 or other MOC303x. You'll also discover that the 180 ohm resistor is not necessary.

paulbergsman
- 24th January 2009, 02:53
Could you people tell me what's the difference between a solid-state relay and a normal relay. Is a solid-state relay a better option? Thanks again guys and girls :)

NEVER USE CMOS/TTL LOGIC TO DIRECTLY DRIVE A.C. INDUCTIVE LOADS.

Let me repeat that:

NEVER USE CMOS/TTL LOGIC TO DIRECTLY DRIVE A.C. INDUCTIVE LOADS.

The only safe way to control an A.C. inductive load is with a light beam.

To hammer home my point, consider DIRECTLY controlling a window air-conditioner with signals from you deluxe "game-machine" PC's parallel printer-port's CMOS/TTL signals. Will it work? Maybe. But, for how long.
Do you want to gamble with your rather expensive PC? I don't think so.


I suggest the following:

Use an optocouple between your PIC's output pin and the relay coil.
This provides a light-beam barrier between your PIC and the inductive A.C. world.

It will cost a lot more, but you could use a solid state relay, [SSR]. The SSR has an optocouple input, which controls a solid state driver circuit.

SSRs get hot. That's why the base is a big slab of metal.
SSRs come in two varieties. One for A.C. circuits. One for D.C. circuits.
The rated voltage is the maximum safe operating voltage.
SSRs rated at 120v D.C. work very well in 24v applications.