Shop OBEX P1 Docs P2 Docs Learn Events
Best Practices for driving a relay with an I/O pin. — Parallax Forums

Best Practices for driving a relay with an I/O pin.

Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
edited 2010-03-04 18:18 in Propeller 1
I'm currently working on a project which incorporates the Propeller controlling a "real world" item.
I'm using a 5v relay (which seems to be perfectly happy at the 3v output of the Propeller) with a
diode between the pin and the relay. Can someone confirm that this is "best practice" in this situation?

Also, as I plan to use PWM at some point in this project, does someone know correct part# for a
solid state equivalent of the top of their head?

Thanks!
OBC

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
New to the Propeller?

Visit the: The Propeller Pages @ Warranty Void.

Comments

  • BeanBean Posts: 8,129
    edited 2010-03-04 15:21
    OBC,
    I assume you mean the diode is across the coil connections (reverse biased) ?

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Use BASIC on the Propeller with the speed of assembly language.

    PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

    March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
    ·
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2010-03-04 15:26
    Bean,

    Actually, I wasn't really worried about the VSS side of the relay. My diode is between the I/O pin
    and the relay itself. Reverse against the I/O pin to keep current from coming back to the Propeller.

    No?

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Visit the: The Propeller Pages @ Warranty Void.
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2010-03-04 15:47
    Normally the diode goes across the relay coil with reverse bias to prevent a back emf by sending the stored energy back to the supply.

    Graham

    edit: some reed relays contain a diode for protection.

    Post Edited (Graham Stabler) : 3/4/2010 3:53:54 PM GMT
  • LeonLeon Posts: 7,620
    edited 2010-03-04 15:53
    A diode wired like that doesn't really do anything. You could zap the Propeller chip.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Leon Heller
    Amateur radio callsign: G1HSM
  • BeanBean Posts: 8,129
    edited 2010-03-04 16:18
    OBC,
    The way you have the diode, it blocks the current. There is nowhere for the current to go. This generates very high voltages across the coil.
    With the diode across the coil, the diode absorbes the current caused when the coil is turned off. Keeping the voltage at 0.7V max.

    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Use BASIC on the Propeller with the speed of assembly language.

    PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

    March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
    ·
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2010-03-04 16:22
    Just to confirm.. Figure 1 in the attached image is how I'm setup right now.

    I've had no issues running this circuit in an on/off loop for well over an hour.
    (That might be another testament to how robust the Propeller is.)

    I get the idea that Figure 2 is the direction I need to go in? Do I need the transistor?


    Edit: This is the relay I'm using.

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Visit the: The Propeller Pages @ Warranty Void.

    Post Edited (Oldbitcollector) : 3/4/2010 4:34:26 PM GMT
    704 x 318 - 14K
  • Mike GreenMike Green Posts: 23,101
    edited 2010-03-04 16:29
    Figure 1 doesn't help you at all. Figure 2 is what you want. You need the transistor if the amount of current is more than the Propeller I/O pin can handle. Typically a Propeller I/O pin can handle 20-25mA. It's been tested to maybe 40-50mA, but I wouldn't plan on using that. There are current limits as well for each group of 8 I/O pins and for the chip as a whole. Look at the datasheet for the numbers. I've used reed relays without a transistor (just a diode) that require 20mA and had 16 of them activated two at a time.
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2010-03-04 16:37
    @Mike,

    So something like this?

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Visit the: The Propeller Pages @ Warranty Void.
    294 x 266 - 7K
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2010-03-04 16:57
    That is correct.

    When the diode is turned off the magnetic field collapses, this field contains energy. A back emf is then produced, this means that the potential of the point connected to the propeller pin will rise however now the diode will become forward biased and the energy will return to the supply.

    Graham
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2010-03-04 17:12
    Thank you Graham.

    I tend to be a visual learner and the text descriptions just weren't completely sinking in.

    It looks like a single relay or two should be fine in my situation.

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Visit the: The Propeller Pages @ Warranty Void.
  • BeanBean Posts: 8,129
    edited 2010-03-04 17:34
    OBC,
    · If you use the transistor, don't forget a resistor between the Propeller pin and the base of the transistor. The value will depend on how much current the relay needs, and the gain of the transistor.
    · I'd start with a 1K and lower it if that doesn't work. Don't go below about 180 Ohms though.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Use BASIC on the Propeller with the speed of assembly language.

    PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

    March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
    ·
  • kwinnkwinn Posts: 8,697
    edited 2010-03-04 17:44
    @OBC

    Re: Also, as I plan to use PWM at some point in this project, does someone know correct part# for a solid state equivalent of the top of their head?

    Sorry, not aware of any solid state equivalent for the top of my head or any one else's head, however if you are looking for a solid state relay to replace the one you are using I may be able to help if you post the current rating and voltage it is to be used for wink.gif
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2010-03-04 17:51
    @kwinn,

    Basically I'm switching 4.5-9v DC with a Propeller pin.


    Thanks

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Visit the: The Propeller Pages @ Warranty Void.
  • hover1hover1 Posts: 1,929
    edited 2010-03-04 17:53
    Jeff,

    I have some ULN2803 driver chips left over from the Christmas Give-a-Way. I gave away about 40, and I have about 20 left. I'll sent you a couple.

    Drive directly from the Prop, and the protection diode is built in. I have never tried to run it at 3.3 volts though. But what the heck, they are free and might come in handy for another project.

    Jim
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2010-03-04 17:56
    Thank you hover.

    I'll give them a look see. [noparse]:)[/noparse]

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Visit the: The Propeller Pages @ Warranty Void.
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2010-03-04 18:05
    OBC, me too. I need to install some software on my PC so I can make quick sketches.

    For PWM what about using a mosfet, some have amazingly low on resistances, convenient packages and can be switched directly by the propeller. If you are just switching power they are a great solution.

    Cheers,

    Graham
  • kwinnkwinn Posts: 8,697
    edited 2010-03-04 18:10
    An opto-isolator such as the 4n29 can handle up to 150mA at up to 30V. If you need higher currents an added transistor is all that is required.
  • tdlivingstdlivings Posts: 437
    edited 2010-03-04 18:18
    I found this article on calculating the base resistor size of single transistor

    relay drivers.· You will need to use an ohm meter to measure the relay coil

    resistance to get an idea of required current unless you have a data sheet

    which gives the relay holding current. The diode is important.

    The assumption in the discussion so far is that the relay is small and the

    current is low enough for the prop to drive it directly. However I like having

    some kind of drive interface, single transistor or an open drain or open collector

    IC . I prefer to wipe out the driver rather than the micro is something bad happens.

    Tom
Sign In or Register to comment.