PIC to Relay


Closed Thread
Results 1 to 15 of 15

Thread: PIC to Relay

  1. #1
    Join Date
    Oct 2008
    Posts
    47

    Default PIC to Relay

    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"?

  2. #2
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    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

  3. #3
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kalind View Post
    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.
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  4. #4
    Join Date
    Oct 2008
    Posts
    47


    Did you find this post helpful? Yes | No

    Default

    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.

  5. #5
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    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 page. Unfortunately it doesnt give you a lot of information without clicking on each one. 60-4190 appears to be suitable for your needs and is fairly cheap.

  6. #6
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    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...

  7. #7
    Join Date
    Oct 2008
    Posts
    47


    Did you find this post helpful? Yes | No

    Default

    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
    Last edited by Kalind; - 11th November 2008 at 13:25.

  8. #8
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    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.
    Attached Images Attached Images
    All progress began with an idea

  9. #9
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    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. 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.

  10. #10
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Melanie View Post
    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."
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  11. #11
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    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
    Attached Images Attached Images   

  12. #12
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    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.
    Attached Images Attached Images
    All progress began with an idea

  13. #13
    Join Date
    Oct 2008
    Posts
    47


    Did you find this post helpful? Yes | No

    Red face

    OK cool!! Im taking a look at the triac now. For the solid-state, isn't there a "flyback" diode required?

  14. #14
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by aratti View Post
    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.
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  15. #15


    Did you find this post helpful? Yes | No

    Default Light beams are only way to control Power-Line AC

    Quote Originally Posted by Kalind View Post
    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.

Similar Threads

  1. HELP ME, SMS controlled relay using PIC
    By pazko1125 in forum mel PIC BASIC
    Replies: 14
    Last Post: - 2nd October 2008, 15:26
  2. Pic to relay
    By ruijc in forum General
    Replies: 4
    Last Post: - 8th November 2007, 19:03
  3. Serial Relays
    By tazntex in forum General
    Replies: 3
    Last Post: - 17th May 2007, 17:42
  4. Replies: 22
    Last Post: - 9th April 2007, 15:25
  5. Serial Pic to Pic using HSER
    By Chadhammer in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th March 2005, 23:14

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts