Saturday, February 23, 2013

Drive External Loads with your LaunchPad

Until now all of our projects with the LaunchPad have been used to flash LEDs.  But what if you need to control a load heavier that the 25 milliamps at 3V, which is the maximum current available on any LaunchPad output pin?  Here's a way to control loads as high as 10 amps using modules that you can buy on-line.

The various Arduinos are a series of microcontroller boards not unlike the LaunchPad (but more expensive) they are probably the most popular microcontrollers with the 'hacker' and 'maker' communities.  These guys build all sorts electronics-based of projects, mostly robotics; and, if you know where to look, there are a large number of Arduino-compatible modules available that perform all sorts of functions.  These functions include various sensors (infrared, acoustic, temperature, attitude, light level), GPS, motor controllers and, the subject of this post, relay modules.  The Arduino community calls these add-on boards "shields" (don't ask me why, I don't know).  Although these add-on modules are made for the Arduino, most will work with the LaunchPad with no, or only slight, modification.






Here are three relay boards that I bought on e-bay last year for another railroad related project.  The most expensive of these was about $4.88 (last year, $5.88 this year), the least expensive was under $3.  They all have the same 10 amp SPDT relay mounted on them, they all operate on 5VDC (more on that later), they all operate on an 'active low' signal, and they all are "opto-isolated".

An opto-isolation circuit means that the trigger signal from the microcontroller passes through a chip where it lights up an internal LED.  The LED illuminates an internal photodetector; the photo detector, in conjunction with other circuit elements, generates the current to throw the relay.  In this manner the microcontroller does not have to source or sink enought current to drive the relay directly.

Here's where the LaunchPad, being a low-power design, might be at a disadvantage relative to other microcontrollers like the Arduino.  I said that these relay modules required 5VDC. The LaunchPad runs on 3VDC.  So while a 5VDC microcontroller like the Arduino can drive these directly, the 3VDC LaunchPad may require some assistance to drive these relay modules.

Before I decided I needed to supply an external source of 5VDC to the relays, I decided to try them on the 3VDC available on the LaunchPad and, eureka, it worked with all three relay modules.

Here's the hookup that you have to use:


The Vcc pin in the lower right of the LaunchPad should be connected to the Vcc pin on the relay module.  Similarly the GND pin on the LaunchPad should be connected to the GND pin on the relay module.  The input pin on the relay module can be connected to any output pin on the LaunchPad (if you want to do a quick demo connect the input to Pin 2 (Port 1,0) or Pin 14 (Port 1,6) which are driving the on-board LEDs). 

Now when the output pin to which the relay is connected goes LOW (that is to ground), the relay will pull in with an audible click and illuminates the LED on the relay module.  The relay does not pull in very enthusiastically on 3V, but it always pulls in and holds so long as the LaunchPad pin remains low.

Here's a video of all three of the relay modules shown in the first photo being activated in sequence by the LaunchPad.


It's unusual that three different relay modules, all rated for 5VDC also all run on 3VDC.  Well, maybe not so strange, the circuitry on each module is very similar if not identical.

To manipulate the LaunchPad's pins, I programmed Bill Hastings sequencer program.  The command sequence that I used is:

    P1_ALL_ON;
    P1_BIT_TOGGLE(BIT6);         // Bit 6 OFF
    DELAY_SECS(3);                   // wait 3 second
    P1_BIT_TOGGLE(BIT6);        // Bit 6 ON
    P1_BIT_TOGGLE(BIT4);        // BIT 4 OFF
    DELAY_SECS(3);                  // wait 3 second
    P1_BIT_TOGGLE(BIT4);       // Bit 4 ON
    P1_BIT_TOGGLE(BIT5);       // BIT 5 OFF
    DELAY_SECS(3);                 // wait 3 second
    P1_BIT_TOGGLE(BIT5);      // Bit 5 ON and go back to                                                //the beginning
 

You may notice the first command P1_ALL_ON does not require the parenthesis as shown in Bill Hastings original posting [P1_ALL_ON()]. Remember, these relay modules work when the pin is pulled low; so turning the pin OFF per Bill's program, causes the relay to activate.  The relays have SPDT contacts so if you are just using these to turn external loads on and off, there's always a set of contacts with the right sense.

I do not know how many of these relay modules a LaunchPad can drive simultaneously; probably at least a few.  If you do not want to have to worry about overloading your LaunchPad, you can provide external 5VDC by following this schematic.


If you power the relays this way, their operation will be snappier and you will not have to worry about the LaunchPad supplying power for the relays.  The 5VDC has to be reasonably clean because of the opto-isolator chips on the relay modules; the output of a power pack set for 5V will not do. Note that the ground of the LaunchPad and the ground of the external power source must be connected together for this to work.

So where do you get the relay modules? Last year, when I bought my relay modules, they were listings from various sellers on e-bay.  At the time of this writing, only one of the original modules is still listed on e-bay in the seller's store.  It's the largest relay module at the top in the video.  You can find it here: relay module.   The price this year is $5.88 and it's not a bargain, you can do better.

If you search e-bay's listings and the e-bay stores of vendors of hobbyist electronics, you can find a lot more at better prices.  Here's a two-channel relay module for only $2.98: 2 channel relay module  Hookup to this module will be a little bit different because it has two input pins, one for each relay.  

You'll notice the title of this e-bay listing: "5V Two 2 Channel Relay Module With optocoupler For PIC AVR DSP Arduino ARM"  It contains a number of clues that indicate that this unit should work with the LaunchPad.  First off, it's rated for 5V; this is essential as there are nearly identical 12V and 24V relay modules listed on e-bay.  Then notice that it lists "PIC AVR DSP Arduino ARM". All of these are other microcontrollers or Systems on a Chip (SoC).  When you see this listed, there's an excellent chance that it will work with the LaunchPad.  So if you search e-bay for "relay" then key-in on the listings that list "5V", "microcontroller" or any of the specific microcontrollers listed above, you should be OK.

All of these relay modules listed on e-bay will ship directly from the vendors in China - even if they claim that the merchandise is in the US. This has not been a problem for me; but you have to keep two things in mind.  First, the "free" shipping will take about 3 weeks.  Not a problem if you are aware of that.  However, there is a lot of variability in shipping time, and most of the vendors will advise when your package ships, but they cannot tell you when it will arrive.  Second, use only Pay Pal to pay for your purchase.  With Pay Pal, the overseas vendor never gets your credit card number; so it's safe.  With Pay Pal you have recourse if your merchandise does not arrive or it is not as advertised.  The vendors do not want to lose their Pay Pal accounts and, therefore, they do not play games with your order.

If this has not raised any red flags (pun intended), then you can also go directly to some vendors in China and skip e-bay.  I've had good results with Good Luck Buy and Deal Extreme.  These vendors have lots of these relay modules in configurations from 1 to 16 channels.  Here are a couple:  identical relay module  this appears to be identical to the $5.88 module listed above; one channel module without opto-isolation without the opto-isolation, this one may not work on 3VDC, but at $1.64 you can afford to experiment; here's the cheapest 8 channel unit that appears to include opto-isoation 8 channel relay module; and it's rated highly by the users.  Remember a multi-channel relay module will require wiring to multiple output pins on the LaunchPad.


Good Luck Buy and Deal Extreme are not manufacturers and their merchandise changes periodically. So if you find something that you like, don't hold up your re-order. The rules for ordering from China apply here too.     

If you are not comfortable with ordering from China, then you can find similar items (at higher prices) from the hacker/maker websites.  And Amazon actually has some of theseHere are 8-channel and 2-channel modules that ship from Amazon 8 channel module from Amazon  2 channel module at Amazon  

About the only significant differences I can see between all of these modules is that some use PC pins for the connection to the microcontroller and some, like all of the ones that I bought, use screw-terminals.  All of the relay modules seem to use screw terminals for the connections to the relay.  These modules are so inexpensive, it does not pay to fool around with individual relays.  They also have diodes to protect against switching inductive loads (you don't need to know what that is, but you do need the diodes). So unless you know how to hook up individual relays, stick with these modules.

Well, as usual, I've run very long with this post.  So enjoy switching heavy loads with your LaunchPad.



 


4 comments:

  1. Good stuff! Thanks for the well written explanation. I have two of the TI-Launchpads plus a Raspberry Pi that I am experimenting with. These little relay boards should do the job perfectly. The Raspberry Pi is also 3.3v and is very sensitive to higher voltage - no way I want to risk blowing it out.

    ReplyDelete
    Replies
    1. Michael:

      If you are going to mix 3V and 5V logic, I recommend that you use the opto-isolated relay modules.

      TT

      Delete
  2. I purchased this one a few days ago, waiting on it to arrive.

    http://www.ebay.com/itm/251231186076?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649

    ReplyDelete
    Replies
    1. When you have a chance to play with it, let us know if it works on 3V.

      Delete