Stamp 2 & Relays

This is the place for any magazine-related discussions that don't fit in any of the column discussion boards below.
Post Reply
Shing
Posts: 34
Joined: Tue Feb 18, 2003 1:01 am
Location: Dublin, Ireland
Contact:

Stamp 2 & Relays

Post by Shing »

Hi,<p>I am doing a project using a Stamp 2 module.<p>One features of the project is to be able to turn on a 60W bulb using software in the EEPROM of the Stamp 2. The mains here in Ireland are 220V AC.<p>Similar to above, another feature is to be able to turn on a 12V DC fan using software.<p>I have been advised to use relays but I don't know much about them. I am guessing that two output pins of the Stamp 2 would be required to control the two relays.<p>Any help or advice would be greatly appreciated. Thanks in advance.<p>Regards,
Wai Shing
russlk
Posts: 563
Joined: Thu Dec 06, 2001 1:01 am
Location: New Hampshire
Contact:

Re: Stamp 2 & Relays

Post by russlk »

The stampII outputs can handle 20 mA which is sufficient to operate a reed relay. Digi-Key part number HE100-ND. You will need to use a diode across the relay coil to catch the backswing & avoid damage to the output.
Shing
Posts: 34
Joined: Tue Feb 18, 2003 1:01 am
Location: Dublin, Ireland
Contact:

Re: Stamp 2 & Relays

Post by Shing »

Thanks for the reply. It has already helped me lots. Can I use the same type of relay to switch the 12V DC fan or should I go for another spec?<p>Regards,
Wai Shing
russlk
Posts: 563
Joined: Thu Dec 06, 2001 1:01 am
Location: New Hampshire
Contact:

Re: Stamp 2 & Relays

Post by russlk »

The relay number I gave you is rated at 1/2 amp. If the fan draws more current than that, you need a more robust relay, like Digi-Key PN z108-nd, but you will need to parallel two outputs to handle the current of 30 mA.
vapor
Posts: 10
Joined: Wed Feb 12, 2003 1:01 am
Location: North of Dallas
Contact:

Re: Stamp 2 & Relays

Post by vapor »

Here is another idea, put an OPTO isolator between the Stamp and the relay to protect your Stamp if you accidently short the load side of the relay to the control side.<p>Also, if you need to control a higher current load, then use the reed relay to control a larger relay capable of handling the load.<p> :)
lost-in-code
Shing
Posts: 34
Joined: Tue Feb 18, 2003 1:01 am
Location: Dublin, Ireland
Contact:

Re: Stamp 2 & Relays

Post by Shing »

Thanks again for the response.<p>Looking at the datasheets, the 12V DC fan draws 0.16A. That means I can use it, right? (With two and a half years of study in electronics, you'd think I wouldn't be so helpless.)<p>Regards,
Wai Shing
Chris Foley
Posts: 146
Joined: Mon Jan 13, 2003 1:01 am
Location: Chicago IL
Contact:

Re: Stamp 2 & Relays

Post by Chris Foley »

Hi. Welcome to the "real world" of actually making all these electrons actually do something. A wonderful place it is, and one that isn't taught very well in engineering schools. Maybe the teachers are spending too much time teaching SPICE simulations. SPICE is certainly more convenient for the teachers.
Anyway, you have two problems -- switching a 60W light bulb at line voltage, and driving a 12V .2A fan from a BASIC Stamp 2. For the light bulb, the reed relay suggestion has a couple of question marks. First, and most importantly, you need to check the isolation voltage between the coil and the contacts. 500V is typical for a reed relay. At 220VAC, you can expect a "normal" peak voltage of 310V between the coil common and at least one of the relay contacts. This doesn't take into account high line voltage, spikes and transients. In short, 500V is not enough for a good design. Also, the 500V spec is for a leakage current not exceeding their specified maximum, which can be up to 1mA. If you want it to keep working, you need at least 1KV isolation, and preferrably 1500V (after all, BASIC Stamp 2s go for about $50 each, right? Not to mention we don't want to inadvertently dance the 60 Hertz. Or the 50 Hertz, either.)
The second big problem here is inrush current. Unplug your 60W bulb and ohm it out with a DMM. You would think that, since P = V^2/R, the resistance of the bulb should be R = V^2/P, or 220^2/60 = 806 ohms. Your reading will typically be less than 100 ohms. What's happening is that, as the current surges through a light bulb on turn-on, the filament heats up, and the resistance increases. This inrush current is typically 4 to 10 times greater than the steady-state current, and will probably weld your normally open reed relay contacts shut on the first couple of tries.
The third consideration is Lenz' Law. Lenz said that, when you turn off an inductor, the thing will want to keep the current flowing. As a result, when you are driving a 5V reed relay from a BASIC Stamp pin, you won't have any problems on turn-on. However, when you try to turn it off, the voltage at the output pin will go well above the +5V power supply or below the 0V potential, depending on how you have it hooked up. Depending on the relay, the kick could try to go as high/low as 12V to 100V, depending on the inductance. Your Stamp output pin FET might not like that, and they usually croak unless they have special protection diodes built in (they don't). In driving an inductive load, you should always use a snubber diode across the coil to limit this excursion, and keep the inductive kick from destroying whatever's driving it.
Here's the conservative (meaning they'll really work, and will last for a while) solutions: For driving anything with inductance, capacitance, or any more current than an LED, use a transistor (or a transistor array IC) to drive anything from a Stamp. For the lamp, use a 2N3904 to drive a 2A PCB-mount relay with a 5VDC coil, around 50 ohms coil resistance, that's rated for 240VAC use. Emitter=GND, base to the Stamp pin thru a 2.7K resistor, and the collector tied to one end of the relay coil. Tie the other end of the relay coil to the +5V supply. Place a 1N4002 diode in parallel with the relay coil, cathode toward the +5V. This limits the inductive kick to 0.7V to save the transistor (BVceo=35V), and allows the inductor current to recirculate the current. Now you're ready to use the relay contacts to drive the lamp. Use the normally open contacts as the switch in the circuit, and make sure there's good electrical isolation between the coil pins and the contact pins of the relay. Clean layout prevents all kinds of problems. If you're using perfboard, clean the copper out of the isolation band between the line voltage and the logic power supply. Keep it safe, and double-check both visually and with an ohmmeter before you turn it on.
For the fan. you've got the inductive kick on the load, as well as quite a bit more current than the Stamp should provide. Since it's a 12V fan, use a Darlington NPN transistor such as the TIP100 (overkill, but they're cheap). Tie both the +5V and +12V power supply commons together. On the transistor, emitter=ground, base to the Stamp pin through a 4.7K resistor, and collector to the load. Red lead of the fan to +12, black to the TIP collector. Again, tie a 1N4002 diode from +12V to the collector, with the cathode on the +12V. Or you can use the relay setup as described above.
Long answer, sorry for the tedium. You might want to look into some of the practical electronics books written by Scott Edwards on the Stamp at www.seetron.com. General electronics knowledge books from Don Lancaster at www.tinaja.com. The fun in electronics is when you actually do something with what you've learned. Happy hunting.<p>[ February 22, 2003: Message edited by: Chris Foley ]<p>[ February 22, 2003: Message edited by: Chris Foley ]<p>[ February 22, 2003: Message edited by: Chris Foley ]</p>
Ron H
Posts: 360
Joined: Tue Dec 18, 2001 1:01 am
Location: Boise, ID
Contact:

Re: Stamp 2 & Relays

Post by Ron H »

Chris, that reply was above and beyond the call of duty! I think you gave one questionable bit of advice, to wit:<p><snip>
"For the lamp, use a 2N3904 to drive a 2A PCB-mount relay with a 5VDC coil, around 50 ohms coil resistance, that's rated for 240VAC use. Emitter=GND, base to the Stamp pin thru a 2.7K resistor"<snip><p>My 2N3904 datasheet only guarantees a beta of 30 with Ic=100 ma and Vce=1v. We need less than 0.5v across the transistor when driving the relay. The standard rule of thumb for driving a bipolar transistor into saturation is to use Ic/Ib=10, or at most, 20. We have a collector current of 5v/50 ohms=100 ma. We will then need the base current to be at least 5 ma, preferably 10 ma. With 2.7k, we are only going to get (5-0.7)/2.7k=1.6 ma, for an Ic/Ib ratio of 63. To get 5 ma, and considering the output impedance of the Stamp 2 (which I could not find), I think a base resistor of no more than 820 ohms would be appropriate. 470 ohms would be more robust. <p>Cheers-
Ron
Shing
Posts: 34
Joined: Tue Feb 18, 2003 1:01 am
Location: Dublin, Ireland
Contact:

Re: Stamp 2 & Relays

Post by Shing »

Wow, this is all a little exhilierating for me but I think I'm beginning to get to grips with it a little. Thanks for the effort! I appreciate it.<p>Regards,
Wai Shing<p>[ February 23, 2003: Message edited by: Shing ]</p>
Shing
Posts: 34
Joined: Tue Feb 18, 2003 1:01 am
Location: Dublin, Ireland
Contact:

Re: Stamp 2 & Relays

Post by Shing »

OK, so I've started trying to build the circuit described above but there have been a few setbacks already. I was an idiot and ordered a 12V relay instead of a 5V relay for the fan. However, I was told that this would still work if I modified the circuit a little.<p>So far, I have the output of the Stamp 2 connected to the base of a BC107 transistor via a 1K resistor. The collector is connected to 12V via the relay, not forgetting the flywheel diode in parallel with the relay coil.<p>Well, it doesn't work so does anyone know what's wrong with my circuit?<p>I am deeply suspicious about the way that I have connected up the relay. I have pin 5 connected to the 12V and pin 6 going to ground. Pin 7 is also going to ground and pin 12 is connected to the collector of the BC107. For the record, it's a FBR211SBD012 relay.<p>If this all a bit confusing, I can scan in a picture of my circuit diagram.<p>Regards,
Wai Shing
russlk
Posts: 563
Joined: Thu Dec 06, 2001 1:01 am
Location: New Hampshire
Contact:

Re: Stamp 2 & Relays

Post by russlk »

You are right, it is not connected correctly. Take a look at the data sheet: http://www.fcai.fujitsu.com/pdf/fbr211.pdf<p>Pins 5 & 6 are the coil. Connect 5 to +12 and 6 to the collector. It is a DPDT (double pole double throw) relay, pin 8 is NO (normally open) and pin 7 is NC (normally closed). Pins 1 and 12 are connected together and are the common of the switch.
Ron H
Posts: 360
Joined: Tue Dec 18, 2001 1:01 am
Location: Boise, ID
Contact:

Re: Stamp 2 & Relays

Post by Ron H »

Russ, you must think I'm just a nit-picking SOB, :) but...looks like SPDT (single pole double throw) to me.<p>Ron
pagliacci
Posts: 5
Joined: Thu Mar 20, 2003 1:01 am
Location: st louis
Contact:

Re: Stamp 2 & Relays

Post by pagliacci »

stamp 2 and relay :p ower mos fets are the only way to drive relays in my opinion,they are the best hammer drivers(coils for relays)available.IRF series are very easy to use .ground to one side of coil,other side of coil to source,drain directly to positive,1k resistor from gate to ground(eliminates pickup noise)drive gate positive(check data sheet for turn on E)I=e/R,of course,and have fun! :
Chris Foley
Posts: 146
Joined: Mon Jan 13, 2003 1:01 am
Location: Chicago IL
Contact:

Re: Stamp 2 & Relays

Post by Chris Foley »

Thanks, Ron. You're right. The rule of thumb for using a transistor as a switch is Ib=Ic/10. However, although minimum Hfe is 30, typically they go from 100 to 250. A bit of soft saturation seems to be less of a hazard (especially for this light of a load) than stressing out the Stamp by drawing too much current from the output pins. It's a tradeoff. I guess if we really wanted something bulletproof we would use a ULN2004 (made for 5V CMOS inputs), and find a relay that would reliably handle 4V across it instead of 5V (all you'd have to do is look at the relay spec sheet). Either that, or use another specialty peripheral driver IC. But everybody's got a handful of 2N3904s or equivalent in their junk box. Happy hunting.
Ron H
Posts: 360
Joined: Tue Dec 18, 2001 1:01 am
Location: Boise, ID
Contact:

Re: Stamp 2 & Relays

Post by Ron H »

<blockquote><font size="1" face="Verdana, Helvetica, sans-serif">quote:</font><hr>Originally posted by pagliacci:
stamp 2 and relay :p ower mos fets are the only way to drive relays in my opinion,they are the best hammer drivers(coils for relays)available.IRF series are very easy to use .ground to one side of coil,other side of coil to source,drain directly to positive,1k resistor from gate to ground(eliminates pickup noise)drive gate positive(check data sheet for turn on E)I=e/R,of course,and have fun! :<hr></blockquote><p>Using a MOSFET as a source follower is not the best way to drive a load. The common-source connection is more efficient. Ground the source, connect the drain to one side of the coil, and connect the other side of the coil to +V. Connect a diode across the relay coil, anode to drain, to protect the MOSFET from the flyback voltage when it turns off. Drive the gate positive to turn on the MOSFET. The required size of the MOSFET and diode depend on the size of the relay.<p>Ron
Post Reply

Who is online

Users browsing this forum: No registered users and 36 guests