PIC relays control


Closed Thread
Results 1 to 21 of 21
  1. #1
    Join Date
    Jul 2007
    Posts
    65

    Default PIC relays control

    Hi All

    I'm starting a little projet with a PIC chip, since I discovered that PIC Basic can make it easy for me

    I have some programming skills, but I'm very poor at selecting components, so may someone more aware of the electronical side help me?

    I'm want to use a 16F84A or 16F628A (i have both actually), and If possible i want to drive some low power relays directly from the chip!?

    Panasonic and Omron makes 5V, 20mAh, 250ohm relays that are close to the output power of the PIC pins, but anyone ever made it work?

    I'd like a single coil latching relay, maybe the TN2-K-5V of Panason..

    Next thing is how to drive it safely, knowing that I should add zener diodes somewhere to dampen the coil release.
    Being a single coil latching relay, I will need two pins and so, current will flow both direction.
    I would prefer a relay that changes state everytime it get a pulse, so driven by only 1 pin, but I haven't seen that anywhere.


    k, enought on the relays, it's already scary long

    ttl

    Dom

  2. #2
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Flipper,

    Where are you? In the states you can get these (below) .. they work great using one output pin but they do not latch. I used them in testing equipment years ago and they were perfect. No zener needed, just a flyback diode across the coil. I drove mine direct from a PIC output at 5 volts since the coil resistance is 250 ohm.

    http://www.radioshack.com/sm-compact...i-2062478.html
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  3. #3
    Join Date
    Apr 2007
    Posts
    24


    Did you find this post helpful? Yes | No

    Default WOw finally some place I can help!

    Ok here is the deal,


    You MUST use a diode across the coil of ANY relay (unless its got one built in) Its for the back EMF (colapsing magnetic field) of the coil when you un-energize it.

    If your looking for a latching type of switch depending on what your doing you have lots of options. relays with NO and NC contacts (probly your best bet), scr's, Triacs etc..

    If your worried about not being able to drive the coil from the PIC. You can just use a FET. The input impedence of the gate of a FET is really high and takes almost no current to turn on. Just make sure to use a series resistor in the gate circuit in case the FET ever fails (If the fet ever shorted gate to whatever it could hurt the PIC)

    Oh, one other thing to consider is what your switching. If your switching AC with lots of current you will need a snubber circuit to reduce the arching on the relay contacts. I just went through this on my predesesor's motor control circuit at my work. His "new" design would fuse the contacts together about the thrid or forth time the motor started.

    Well that is my two cents (probly all its worth) hope it helped. If you want to post a schematic of what your doing I would be more then happy to look it over.

    Best!
    Bill12780
    Last edited by bill12780; - 27th July 2007 at 07:51.

  4. #4
    Join Date
    Jul 2006
    Posts
    11


    Did you find this post helpful? Yes | No

    Default

    Bill, do you have a schematic or part number for this control circuit with snubber by chance?

  5. #5
    Join Date
    Jul 2007
    Posts
    65


    Did you find this post helpful? Yes | No

    Default

    hi folks

    i'm happy to know that it's at least possible to do

    Radio Shack has become CircuitCity around here, and they don't carry much of electronics anymore...
    I will probably make an order at Digikey.

    I'm looking to drive two 12v (DC) HelmetCam, who drink 130mAh approx. each.
    (but it runs very hot... I wonder how it can only be taking 130...)
    At first I wanted to have some kind of soft power switching, because that whole thing is plugged into a camcorder, but this sounds very complex to me so I will use Zener diode in the circuit to prevent overvoltage peak.
    KIS system

    I need Latching because I won't be switching too often, and the circuit can run for more 6-7hours non-stop.

    thanks all!



    Dom

  6. #6
    Join Date
    Apr 2006
    Location
    New Hampshire USA
    Posts
    298


    Did you find this post helpful? Yes | No

    Default As I see it:

    Hi Dom,

    As I see it:
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1883&stc=1&d=118558263 1" />
    You would need a 5V relay to drive it directly.
    The PIC 25mA limit would drive 200 or more coil Ohms.
    Not:
    Mono-stable Relay, normal relay that stays energized while a voltage is on the coil.
    But:
    Magnetically Latching, or Mechanical Latching Relays
    Bi-stable Relay, “Latching “, usually means a pulse turns it on, a second pulse turns it off.
    Single Coil Latching (1 coil latching), usually means the second pulse goes to same connection.
    A single PIC I/O could give a pulse to turn it on, then later a second pulse would turn it off.

    Dual Coil Latching (2 coil latching), usually means a pulse on coil A turns it on, a pulse on coil B turns it off.
    This would require 2 I/O pins for control.

    Here is a hook-up if you want to use a 12V relay.
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1884&stc=1&d=118558290 6" />

    You could also use a SCR that would latch with an impulse from a PIC I/O pin. It would be more difficult to un-latch.
    -Adam-
    Attached Images Attached Images   
    Ohm it's not just a good idea... it's the LAW !

  7. #7
    Join Date
    Apr 2006
    Location
    New Hampshire USA
    Posts
    298


    Did you find this post helpful? Yes | No

    Post a snubber

    Hi ohararp,
    Quote Originally Posted by ohararp View Post
    Bill, do you have a schematic or part number for this control circuit with snubber by chance?
    Here is a simplified example of a snubber for AC.
    And a “fly-back” diode for DC. Note polarity.
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1885&stc=1&d=118558358 0" />

    -Adam-
    Attached Images Attached Images  
    Ohm it's not just a good idea... it's the LAW !

  8. #8
    Join Date
    Apr 2007
    Posts
    24


    Did you find this post helpful? Yes | No

    Default A little confusion here.

    OK...

    The snuber I spoke of actually is acrossed the "contacts" of the relay. You only need this if your driving an inductive load or a really high current circuit. Like say a large motor or amplifier.

    the "flyback" diode is used across the "coil" of the relay (reversed biased) to stop the colapsing field in the relay coil...Not in the load. (Although if your load was a DC inductance I supose it would work there too...)

    You can use a Zener to clamp the voltage if your concerned about spikes. But if your power supply is well regulated you should not have any problems swithing 130 mills. Just make sure you have good decoupling.

    You could use a SCR like was mentioned. You will need to remove the source voltage to get the scr to "unlatch" or turn off. This might be a good option but would require more engineering. (transistor to remove the voltage from the Anode long enough for the SCR to turn off and slow enough that it does not trigger itself)

    For the kind of current your looking at. I would use a n-channel FET. I dont really have any easy way of making a schematic for you but I will try and explain.

    Take the HIGH from the pic and run it through a series resistor that will limit the current to about half the Imax of the PIC (about a 100 ohm should give you about 12mA off the top of my head) hook the resistor to the gate of the FET put the load (your camera) in the source circuit and ground the drain.

    Oh...And this is assuming that your cameras run on DC. If your switching AC then you will need a triac.

    By using a FET you will reduce your overall Current drain. It takes alot less current to keep a FET on then it will to hold a realy.

    If you look you can find a latching Relay. I personally have never used them so am not to familar with them. But I would bet they are more expensive then using a standard realy or FET.

    If you would like I will look at my schematics tommorow at work and get the actual values I used for my snubber. I think it was .01uf and 10K if I remember right but don't hold me to that.

    Hope I have helped....

    Bill12780

  9. #9
    Join Date
    Apr 2006
    Location
    New Hampshire USA
    Posts
    298


    Did you find this post helpful? Yes | No

    Post schematic

    Quote Originally Posted by bill12780 View Post
    For the kind of current your looking at. I would use a n-channel FET. I dont really have any easy way of making a schematic for you but I will try and explain.

    Take the HIGH from the pic and run it through a series resistor that will limit the current to about half the Imax of the PIC (about a 100 ohm should give you about 12mA off the top of my head) hook the resistor to the gate of the FET put the load (your camera) in the source circuit and ground the drain.
    Hope I have helped....

    Bill12780
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1886&stc=1&d=118564652 0" />
    5 V/100 Ohms = 50 mA
    5 V/400 Ohms = 12.5 mA (half the Imax of the PIC)
    Attached Images Attached Images  

  10. #10
    Join Date
    Jul 2007
    Posts
    65


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Pic_User View Post

    Bi-stable Relay, “Latching “, usually means a pulse turns it on, a second pulse turns it off.
    I would really like a relay that behave like that!
    If it exist and the PIC can run it, that's what I want !!
    But the spec sheets aren't very descriptive in that manner...(attached Panason TN spec)

    double coils latching relays ask for 40mAh, and need 2 pins...

    About FET and other electronics switcher, i'm trying to avoid tehm because they draw some power just for operating.

    About Diodes, let's say I want to protect the PIC from the relay, I would use a 5V Zener?, or I need to add a safety margin? 4.5V?

    Lots of Amps in the coil effect of a relay?


    Thanks for all added info, i'm slowly but surely getting somewhere! 8)
    Attached Images Attached Images

  11. #11
    Join Date
    Apr 2006
    Location
    New Hampshire USA
    Posts
    298


    Did you find this post helpful? Yes | No

    Post

    Hi Dom,
    Quote Originally Posted by flipper_md View Post
    I would really like a relay that behave like that!
    If it exist and the PIC can run it, that's what I want !!
    But the spec sheets aren't very descriptive in that manner...(attached Panason TN spec)

    double coils latching relays ask for 40mAh, and need 2 pins...

    About FET and other electronics switcher, i'm trying to avoid tehm because they draw some power just for operating.

    About Diodes, let's say I want to protect the PIC from the relay, I would use a 5V Zener?, or I need to add a safety margin? 4.5V?

    Lots of Amps in the coil effect of a relay?


    Thanks for all added info, i'm slowly but surely getting somewhere! 8)
    from the data sheet:
    Panasonic TN Relays
    1 Coil latching
    TN2-L-5 V
    5V 20mA 250-Ohm coil

    The TN2-L-5 V should work directly from standard (25mA) PIC I/O pins.

    I gave incorrect / incomplete information about latching relays in a previous post.
    A single coil latching relay changes state when the polarity on the coil is reversed.

    +++++ Info +++++
    Single coil latching relay
    DC Power to coil transfers contacts.
    Contacts maintain after coil power is removed.
    To transfer contacts to original position, DC Power to the coil is reversed.
    Contacts maintain after coil power is removed.
    +++++
    Coil suppression circuit:
    Circuit to reduce the inductive switch off voltage peak of the relay coil (EMC protection)
    The latching relay protection diode would have to allow either polarity.
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1889&stc=1&d=118567495 4" />
    Then your PIC would Make I/O A high and I/O B low or I/O B high and I/O A low, to latch or unlatch the relay.

    We should mention that using the transistor in place of the relay does not use very much battery power.
    But, the PIC has to remain in control of the pin driving the transistor.
    I would consider using a logic level CMOS power transistor.
    -Adam-
    Attached Images Attached Images  
    Ohm it's not just a good idea... it's the LAW !

  12. #12
    Join Date
    Apr 2007
    Posts
    24


    Did you find this post helpful? Yes | No

    Default oops!

    Quote Originally Posted by Pic_User View Post
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1886&stc=1&d=118564652 0" />
    5 V/100 Ohms = 50 mA
    5 V/400 Ohms = 12.5 mA (half the Imax of the PIC)
    oops....Sorry....it was late when I posted that. I think I was going for the four(4) key on the keypad and fat fingered it to the one(1) right below it.
    (I mean 5/.0125 is easy math I do in my head all the time...had to be a typo...cant belive I was that tired! hahaha!)

    Pic_user...You obviously have WAY more experience with this.

    I will yield to your expertise here and bow out. I just thought that I could return the favor for all the help that I get here.

    Thanks for correcting that.

    Bill12780
    Last edited by bill12780; - 29th July 2007 at 18:25.

  13. #13
    Join Date
    Apr 2006
    Location
    New Hampshire USA
    Posts
    298


    Did you find this post helpful? Yes | No

    Smile We are all in this together

    Hey Bill,

    I do exactly the same thing with resistors. I think in current, and sometimes go down in resistance value, to lower the current, oops. I also say “bigger resistor” when I mean a bigger current, oops. We all do that type of mis-speak, don’t worry about that.

    You are more than welcome, to discuss alternate ways to do things. There is usually more that one way to solve electronics problems. Just as there is more than one way to program an algorithm. The fun of the forum is the multiple solutions discussed. Let the user decide which way they want to go. Or let their electronic junk-box decide for them. Please, always put your ideas into any thread that you want to help with. Your electronics experience is of great value.

    I posted that CMOS schematic from your description. You had said you didn’t really have any easy way of making a schematic. If you look for a drawing program called “paint.NET” it is free and way ahead of MSPaint.

    We are all in this together,
    -Adam-

  14. #14
    Join Date
    Apr 2007
    Posts
    24


    Did you find this post helpful? Yes | No

    Default Thank you..

    Thanks Adam,

    I appreciate your kind words of encouragement.

    I just kinda felt like a dumb A** if you know what I mean. I feel like a leach around here most of the time because I am still very new to the PBP and the digital world in general. always asking question that I am sure to some are so elemetry they are bored to tears! I have not had to use it this sort of thing much in my career. Hence...Ignorance...

    I will spout-off when I think I can help. But PLEASE if I am wrong just swat me on the nose with a rolled up newspaper!

    Maybe one day I can actually be of some help! hahahaha

    Thanks for the tip on the proggie...I will check it out. If I was at my work I would have just slapped something together in Eagle really fast. But I have never download it here at home.

    Thanks again! (I need to program an F-key for that line)

    Bill12780

  15. #15
    Join Date
    Jul 2007
    Posts
    65


    Did you find this post helpful? Yes | No

    Default

    thanks Gentlemen

    all of this end up being very constructive for me, and now I just need to set my mind on what parts I will order to get things started!
    My programmer is dead anyways, I've got plenty of time till the new one comes back

    the double way diode, that's pretty funky stuff!


    I'm using DesignWorks Lite for schematics, and it's pretty good for me so far...

  16. #16
    Join Date
    Jul 2007
    Posts
    65


    Did you find this post helpful? Yes | No

    Default

    just a little follow up on this

    Finally ,I had to order 4.5V relays cuz order 5V we're not stock.
    By time things arrived, I spoke with a few people and one told me that some relays were designed to be driven by IC, without anything special requd for protection.

    I then decided to give it a chance, and it work! First without a bi-color LED on the pins of the coil, but this would take to much power and only the led would light up.
    Removed the led, relay started switching, and kept going

    since then I've being debugging/coding for a while, and no problem to report, for the relay.
    Coding is another challenge

    relays PN is AGN2104H

  17. #17
    Join Date
    Apr 2006
    Location
    New Hampshire USA
    Posts
    298


    Did you find this post helpful? Yes | No

    Default AGN2104H Relay

    Quote Originally Posted by flipper_md View Post
    just a little follow up on this

    Finally ,I had to order 4.5V relays cuz order 5V we're not stock.
    By time things arrived, I spoke with a few people and one told me that some relays were designed to be driven by IC, without anything special requd for protection.

    I then decided to give it a chance, and it work! First without a bi-color LED on the pins of the coil, but this would take to much power and only the led would light up.
    Removed the led, relay started switching, and kept going

    since then I've being debugging/coding for a while, and no problem to report, for the relay.
    Coding is another challenge

    relays PN is AGN2104H
    Hi Dom,

    Glad to hear you are making headway. Thank you for the follow-up information. We are all on the learning curve of life.

    It is good to get technical advice from knowledgeable people.
    Always double check information, at least till you find out which information sources are reliable.

    Always read the data sheet.
    Always “do your home work” with the technical briefs.

    AGN2104H Relay
    4.5V nominal 6.75V maximum

    If you look at the AGN2104H data sheet:
    http://pewa.panasonic.com/pcsd/produ...pdf_cat/gn.pdf
    Quote Originally Posted by the AGN2104H data sheet
    For Cautions for Use, see “Relay Technical Information”.
    That brings us to here:
    Relay Technical Information (PDF:400KB)
    http://pewa.panasonic.com/pcsd/product/re/rti.pdf
    Quote Originally Posted by Relay Technical Information
    Countermeasures for surge voltage of relay control transistor
    If the coil current is suddenly interrupted, a sudden high voltage pulse is developed in the coil. If this voltage exceeds the voltage resistance of the transistor, the transistor will be degraded, and this will lead to damage. It is absolutely necessary to connect a diode in the circuit as a means of preventing damage from the counter EMF.
    In the Technical Brief, they are assuming you are driving the relay with a discrete transistor. If you are driving from a PIC then the “transistor” is really inside the PIC. The same precautions apply.

    Hope this helps,
    -Adam-
    Ohm it's not just a good idea... it's the LAW !

  18. #18
    Join Date
    Jul 2007
    Posts
    65


    Did you find this post helpful? Yes | No

    Default

    Thanks much for the check Adam!

    I admit I'm a bit lazy at reading tech stuff, and I kinda trust a lot electonic components, just like mechanical parts
    I fear only things when they start to smell weird, burn my fingers or don't light up anymore.
    Further more, i'm not skilled at welding so less means better!


    I understand I might be hurting the poor PIC now, but I'm just so curious to see how long he will take it that I can't get myself to puts some diodes in.
    By caution I measured the peak voltage on my fluke(112), it says 3.3V peak after a couples switch, but is that reliable? The FLuke alone may buffer the voltage?

    those tiny processor are heck of fun to play with, it's never ending!

    ... if I had a girlfriend, she d probably wish to be a PIC 8)

  19. #19
    Join Date
    Oct 2008
    Posts
    47


    Did you find this post helpful? Yes | No

    Exclamation HElp me please

    I need to know how to write the code to switch on/off a relay when a temperature setpoint is reached. The output pin im using is RC1 of a 16f873. Please, someone help me!!

  20. #20
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kalind View Post
    I need to know how to write the code to switch on/off a relay when a temperature setpoint is reached. The output pin im using is RC1 of a 16f873. Please, someone help me!!
    Code:
    main:
    if temp > setpoint then
         portc.1 = 1
    else
         portc.0 = 0
    endif
    goto main
    You write code by typing at the keyboard.

  21. #21
    Join Date
    Jan 2007
    Location
    Houston, TX
    Posts
    96


    Did you find this post helpful? Yes | No

    Default OMRON sold state relay w/built in snubber 240VAC @2A

    I have been using the OMRON G3MB-202PL DC5 solid state relay for my AC christmas lights controller. They only pull ~15mA (input impedance is 440ohms +/- 20%) and work great for switching. The voltage input is 4-6V for on. I drive them directly from my pics and have had no problems. I can tell you that it is a GREAT idea to include fuses in your circuit when you use these if you are planning on large loads 1A+. The best part is that the snubber is built right in the SIP package. They go for 4-5.50 from DIGIKEY part #Z915.

    From this forum I learned how to hold the state on or off with a simple counter.
    I use this to

    main:
    if button = 0 then
    i = i +1
    'blah blah
    endif
    gosub choice
    goto main

    choice:
    if i.0 = 0 then
    high relay1
    endif
    if i.0 = 1 then
    low relay1
    endif
    Attached Images Attached Images  
    Padawan-78

Similar Threads

  1. SMS control for Relays
    By charudatt in forum Code Examples
    Replies: 15
    Last Post: - 2nd May 2009, 00:08
  2. Replies: 5
    Last Post: - 12th September 2007, 15:59
  3. Motor Control PLC with a PIC
    By sougata in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 2nd November 2006, 07:59
  4. Pic Control With Software
    By Agent36 in forum General
    Replies: 5
    Last Post: - 18th October 2006, 18:18
  5. Need help on pic to pic flow control (simple problem I think)
    By khufumen in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 11th January 2006, 00:34

Members who have read this thread : 0

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