Shop OBEX P1 Docs P2 Docs Learn Events
Problems with driving a relay with the propeller. — Parallax Forums

Problems with driving a relay with the propeller.

Private19872Private19872 Posts: 61
edited 2014-06-07 09:38 in Propeller 1
I'm trying to drive a relay that needs an input voltage of somewhere around 9 volts with my propeller DemoBoard. My propeller was able to make it click so I thought that it was working, but when I tried to hook up an LED to the relay to see when it was on, the LED wouldn't light. I hooked the 9 volt that was powering the separate LED circuit to the relay, and sure enough it worked. I then found a transistor and tried the relay that way powering the transistor with the 5 volt power on the DemoBoard and it still didn't work. Both of the ground connections on the circuits are together. My next guess is going to be to hook one end of the relay to the 9 volt power source's positive end and then use the propeller pin as a ground for the relay. Will this damage the propeller in any way since it operates on 3.3 volts or can it handle it just fine? Thank you for your time.

Comments

  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-06-04 09:14
    Amps X Volts = Watts

    Watt is the measure of power. Obviously 1/3 the volts means the relay is struggling with much less power than required.

    Additionally, the Propeller does have a limit of about 25 milliamps of current output on its i/o pins, maybe 40 milliamps before failure. Many relays require 60 milliamps. So without verifying what the actual coil's current demand is, you can possibly damage a Propeller i/o pin by direct drive of a relay coil.

    I doubt that is occurring in this situation, but use a 2n2222 transistor between the Propeller and the 9 volt relay. Then provide a full 9 volts to the relay coil. The 2n2222 can handle 500ma, so you won't damage it.

    Between the Propeller and the transistor's base, you should have a current limiting resistor to prevent damage to the Propeller's i/o. 3.3v at 25ma would indicate about 133 ohms minimum... but something larger won't hurt anything. 220 ohms, 330 ohms, 1k ohms are all going to work but the higher you go the more chance that you will affect the relay's performance.

    You really need to comprehend how a transistor can control power and protect the Propeller i/o. Otherwise, your experiments are likely to result in burning out an i/o pin on the Propeller
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2014-06-04 09:15
    You need a transistor or other output stage to A) drive the proper voltage to the relay (9V) and B) drive the proper current. Depending on the relay you may draw an excess of current trying to power the relay just from the Prop. It doesn't matter if the Prop is driving high or low (sink or source), the current draw may well ruin your Propeller, if it hasn't been wrecked already.

    There are plenty of circuit examples on the Internet for driving a relay from a micro controller pin using a separate V+ for the relay. The ULN2003 driver chip is made for this, and is especially handy if you're wanting to power more than one relay. It contains 7 drivers in one small package.

    Be mindful of the diode shown in many circuits, especially the transistor ones. Without it the back-EMF from the relay can damage the driver.
  • Mike GreenMike Green Posts: 23,101
    edited 2014-06-04 09:25
    Yes, this will likely damage the Propeller I/O pin although the I/O pins are more robust than the datasheet specs would lead you to believe. For sure, connecting an I/O pin to a source of voltage greater than the supply voltage of the Propeller + 0.3V or more negative than -0.3V will damage the I/O pin and possibly destroy the rest of the chip. Drawing more than around 40mA from an I/O pin may damage the I/O pin, but usually the I/O pin will limit the amount of current to around 40mA.

    Nuts and Volts Column #6 shows some examples of using a transistor to switch a higher voltage or current. The examples are for the Basic Stamps, but work the same with the Propeller if you adjust the base resistor value. Instead of the 390 Ohm resistor mentioned in the article, use 270 Ohms which will give you about 10mA of base current. With a relay, you'll need a diode connected across the relay as shown in the article. This prevents problems when turning off the relay ... the collapsing magnetic field produces a voltage spike that can damage the switching transistor and can possibly damage the Propeller as well. The diode dissipates the energy from the collapsing magnetic field.
  • Private19872Private19872 Posts: 61
    edited 2014-06-04 11:42
    Thanks for your help. I was able to get my propeller to activate the relay and I installed the diode like you said.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-06-05 12:05
    Now that the relay works AND the Propeller is safe, there is more that can be done to protect the relay contacts from wearing out quickly... if that becomes an issue. Often a combination of the right resistor and capacitor will substantially extended the life of relay contacts that are switching DC loads. Values have to be fitted to the voltage and actual load. In some cases, a diode can also do wonders. This is all about arc suppression.


    http://forums.parallax.com/showthread.php/155265-Relay-contacts-welding-together....is-there-a-simple-solution
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2014-06-05 12:15
    Thanks for your help. I was able to get my propeller to activate the relay and I installed the diode like you said.

    One good turn deserves another. Perhaps you could explain in a bit more detail what you did, for the benefit of others visiting here and looking for something similar.
  • Private19872Private19872 Posts: 61
    edited 2014-06-07 08:45
    Well, what I did was just a bit different from something I tried before. I tried the circuit below (but with a 9 volt source). The difference was that the first time I did it without the resistor, so when I tried powering the transistor with the 3.3 volt source on the board it was shorting through the transistor. After I found this circuit diagram, I added the resistor, and after trying a few different resistors I found that the 100 ohm one worked the best.
    httphome.att.net~Tom.Horsleyphonetalerelay.jpg
  • frank freedmanfrank freedman Posts: 1,983
    edited 2014-06-07 09:38
    An easier (in the long run) way would be to go to all about circuits web site, or get the Horowitz and Hill book "Art of Electronics" or a number of other resources and learn what is behind the design you are trying to use. Then you could look at what you need like the pull-in current of the relay, take the coil resistance and voltage and then design you circuit to your needs. Nothing wrong with operating at the hardware equivalent of snap together kit, but that is not as fun and potentially more expensive............

    The two best resources I found was the tektronix design series (old but excellent) and from the local Goodwill store a very well written ASEE text from about 1989 in which each chapter not only covers design, but gets into troubleshooting the chapters circuits.

    Never know what will turn up in a Goodwill. Gave away a 42" plasma tv to a friend after a year when we went larger. it was $1 and only cost $50 for a driver chip. last saturday turned up a cisco 2960 switch for $3.00..... Ya just never know.......
Sign In or Register to comment.