Shop OBEX P1 Docs P2 Docs Learn Events
if and how to use a relay controlled by a basic stamp — Parallax Forums

if and how to use a relay controlled by a basic stamp

LucipherLucipher Posts: 15
edited 2005-05-05 16:04 in BASIC Stamp
I am using a basic stamp 2 to control an air conditioning unit made out on an old mini fridge. i have a thermo couplr hoooked up to the stamp and all programmed and is workin fine.

I was wondering if it was possible to use a relay some how to kick on the home made A/C unit once it receives a certain temperature reading from the thermo couple.

my program being used for the thermo couple is attached, and i am stumped on how to maybe add another loop to turn on the relay if it is possible.

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-04-23 06:59
    Lucipher -

    Just in passing, it appears from the program that you're using a BS-2pe not a BS-2.

    Use the attached program as a prototype, as I'm not sure it does exactly what you want, but it does compile cleanly. No guarantees however :-)

    Regards,

    Bruce Bates
  • LucipherLucipher Posts: 15
    edited 2005-04-23 15:03
    good point, about that new code, i see it assigns a pin to a relay, but can i control a relay to kick on a 120 volt fan or should i use an amp?

    thanks for all the help

    Lucipher
  • steve_bsteve_b Posts: 1,563
    edited 2005-04-23 15:33
    Lucipher,
    the stamps typically don't generate enough current to trigger a relay....and it's sometimes nice to buffer your stamp pins to what you connect them to (either thru a transistor or optoisolator).

    Here's a quick drawing that floats around on this board for connecting a relay up.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·

    Steve
    http://ca.geocities.com/steve.brady@rogers.com/index.html
    "Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-04-23 15:55
    Steve,

    ·· That circuit is common for 5 Volt Relays.· Parallax Technical Support recommends using a 1K resistor on the base of the transistor if Vdd is more than 5 Volts.· For example, if Vdd is 12 Volts.· This is to protect the Stamp pin in the event the Relay Coil or Diode·should short and destroy the transistor.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • LucipherLucipher Posts: 15
    edited 2005-04-23 16:09
    So should i use a 5v relay that would turn on my 12v relay for my fan to kick on?

    i have seen this done before with a basic stamp and figured i would be able to use the same set up.

    thanks again for all the help.

    Lucipher
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-04-23 16:56
    Hello,

    ·· No, you should control the 12V Relay directly.· If you're driving a 12V Relay, it can be done with a 2N3904 NPN Transistor no problem, as long as the current rating of the coil is around 100mA or less.· Don't forget the Diode across the Relays coils.· It will help to protect the transistor from the effects of the Relay coil when it de-energizes.

    ·· By the way, the reason you shouldn't use one Relay to control another if you can help it is noise.· This seems to be a growing problem recently with people using, for example, a 5V Relay to control a 12V Relay, which controls a 120V Relay.· In this case I can't help but wonder if an SSR could possibly be so much more expensive that 3 mechanical Relays doing the same job, but generating more noise (Using more current when turning on).



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • LucipherLucipher Posts: 15
    edited 2005-04-23 20:51
    ok so now i got a 9v dc relay, a transistor and diode in the circuit like the one shown earlier in the link. I was wondering if i have the code in the link below, with the max temp set to 26 degrees celsius. and min at 20, will i be able to test when pin 11 (for the relay) is high and low as the temperature changes?

    and with the transistor, by lookin at it how can you tell when pin is which, the B-C-E pins, Its so dinky i can barely read the part number.

    Lucipher
  • LucipherLucipher Posts: 15
    edited 2005-04-23 20:54
    forgot the attachment..........cool.gif
  • steve_bsteve_b Posts: 1,563
    edited 2005-04-23 21:24
    what type of transistor are you using?
    google the part number and look for a datasheet!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·

    Steve
    http://ca.geocities.com/steve.brady@rogers.com/index.html
    "Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
  • LucipherLucipher Posts: 15
    edited 2005-04-23 21:55
    its one i got in the parallax kit. the one recommended before.

    Now i have a new problem, i had the thermocouple part working correctly then needed to move it all down a few rows on my bread board thats attached and now when i try to check it its all over the map. soetimes it works its way down to 0 then back up to like 80 degrees celsius.

    i have taken it apart and rebuilt the circuit multiple times making sure all wires arent touching and each were in the nodes all the way and what not and cant figure out, any helo would be awesome.

    Lucipher
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-04-23 22:07
    Hello,

    ·· The part number is important to know.· Two transistors can look exactly alike and have different pinouts.· Even if they have the same pinouts, they can be different types.· For example one might be NPN and the other PNP.· If the one you have is a 2N3904, and you're looking at the transistor with the leads aiming down and the flat surface toward you, the pins should be Emitter, Base, Collector.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • LucipherLucipher Posts: 15
    edited 2005-04-24 16:03
    So i do have a 2N3904 tranisitor, and tried to hook it up like in the diagram usually used to use a realy with a microcontroller, in the diagram, is the 220 ohm resistor connect to the signal pin?

    lucipher
    ·
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-04-24 16:08
    Hello,

    ·· If it's a 2N3904 transistor, and you're switching a 9V Relay, these are the recommended connections.· The left lead (Emitter) connects to ground.· The center pin (Base) connects to a 1K resistor and that connects to your Stamp PIN.· The right pin (Collector) connects to one side of the Relay, and the other side of the Relay connects to your 9V source.· You will also need a diode (like a 1N4001) across the Relay leads, Cathode toward the 9V side.

    ··· When the Stamp PIN is high, it will turn the Relay on.· Let me know how it goes.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • LucipherLucipher Posts: 15
    edited 2005-04-24 17:10
    Ok so i have it hooked up like you just suddested, and it wont kick on the relay when it hits the max temperature. so do i connect the relay directly to one of the terminals to the battery or to the Vdd?

    Lucipher
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-04-24 17:18
    ·· Assuming the circuit doesn't work electrically based on that code may not be the best test.· Try a program that just makes the Stamp Pin you've connected the transistor to HIGH.· For exampe, if you have it connected to PIN0, try a program of just:

    HIGH 0
    PAUSE 2000
    LOW 0
    

    ·· That should turn on the Relay for·two seconds, then off.· See if that works.· If it does, it's not the circuit, but the code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • LucipherLucipher Posts: 15
    edited 2005-05-04 16:18
    Ok, so i had to re-solder another A/D chip because the legs broke off the last one, i have it set up and its reading the temperature fine, now im having trouble with setting up the relay, transistor, and diode so it will kick on when the temperature reads say 26 celsius and to kick off at 20 cslsius. i have a 5v relay, 2N3904 transistor and 1N4003 diode.

    And if i put too much current or apply to much voltage to the relay coil will it get stuck closed if it is a normally open relay?


    Lucipher
  • LucipherLucipher Posts: 15
    edited 2005-05-04 16:53
    Another question, in the attached code, i have the "relay_pin" set to pin 15 so it should go high when the current_temp is higher then the Max_temp at·25 and Low when current_temp is lower then Min_temp at 20. but it doesnt do it at all, it just leaves my LED on, i am using an LED just to test to see if PIN 15 turns high and low as it is supposed to but it just stays high the whole time. please help cause this is getting agrevating.

    Lucipher
  • LucipherLucipher Posts: 15
    edited 2005-05-04 17:11
    here is the code i am using
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-05-04 18:03
    Lucipher said...(trimmed)
    i have a 5v relay, 2N3904 transistor and 1N4003 diode.
    What about the 1K resistor for the base?· You didn't mention that...
    Lucipher said...(trimmed)
    Another question, in the attached code, i have the "relay_pin" set to pin 15 so it should go high when the current_temp is higher then the Max_temp at·25 and Low when current_temp is lower then Min_temp at 20. but it doesnt do it at all, it just leaves my LED on, i am using an LED just to test to see if PIN 15 turns high and low as it is supposed to but it just stays high the whole time.
    The reason this is happening is because the raw value of Cur_Temp is always going to show higher than your Max_Temp.· The reason is that the value returned is not the same value you are displaying in your DEBUG code.· There you are re-formetting the code for the decimal point by dividing it by 100, displaying that part in decimal, displaying the decimal point, etc.· That value itself is not suitable for your calculation without extracting the whole value (Left of the decimal point), which you should be able to do, since technically you're doing it in the code already.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • LucipherLucipher Posts: 15
    edited 2005-05-04 23:16
    yeah i have the 1k resistor in connecting the pin to the transistor.

    but how would i·use the·values then? would i just multiply them by 100 and make the max_temp 2500 and the Min_temp to 2000?

    Lucipher
  • LucipherLucipher Posts: 15
    edited 2005-05-05 00:19
    so i have the circuit set up to set off an LED when it hits 25 degrees celsius for the max temp and to turn off once it cools down to 23 degrees. this is workin fine, i try to set up the 5v relay with the diode in parallel to the relay, one end of the relay connected to the collector pin on the transistor, the other to a node connected to my vdd on the board, then a 1k resistor between the base and pin 15 and the emitter is connected to the vdd on the stamp. the 5v relay kicks on and closes the circuit for the now 9v relay.

    the 9v relay is connected to the battery itself and one of the open sides of the 5v relay which then goes to the positive side of the battery completing the circuit so the 9v should close for the fan and compressor to kick on. but im not sure where i messed up since the LED was working with it fine......



    Lucipher
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-05-05 01:10
    ·· Well for starters, your relay connections are incorrect.· The emitter of the transistor should be to Vss, not Vdd.· You have no ground.· Second, I don't understand why every tries to run two relays to contro, a single device when they could do it with one.· Two Relays is going to introduce all kinds of noise into the supply, and possibly reset the Stamp.· Now, on that diode you're using, is the cathode end toward Vdd, and the Anode end toward the transistor's collector?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • LucipherLucipher Posts: 15
    edited 2005-05-05 01:39
    i have the lined end towards vdd in parallel with the relay, the problem is that the relay i have can only handle .5 amps at 125 VAC. and the 9v i would like to kick on can handle 10 amps at 120VAC. So i dont wanna burn out my 5v relay.

    Lucipher
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-05-05 02:14
    ·· So why can't you control the 9V Relay with the transistor?· That was my point.· You're using the transistor to control a relay to control another relay, to control AC or whatever.· But the first relay doesn't have to be in the loop.·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • LucipherLucipher Posts: 15
    edited 2005-05-05 13:43
    Thanks for all your help everyone, i just got a little mixed up by using a 9v relay when the microcontroller only puts out 5v max. but then isnt that what the transistor is used for? well it works great now and thanks again.

    Lucipher
  • Beau SchwabeBeau Schwabe Posts: 6,557
    edited 2005-05-05 16:04
    This is a post from another thread, but the same formula for a motor can be applied to a relay
    to determine the proper value of the current limiting resistor on the base of your transistor.


    http://forums.parallax.com/showthread.php?p=534806

    ...See my FAQ01.gif from the above link.
    Lucipher said...

    ... i just got a little mixed up by using a 9v relay when the microcontroller only puts out 5v max

    First of all, the microcontroller does not drive the relay. It drives the transistor. If you connect
    your relay as shown, using an NPN with the Emitter tied to GND, then the relay can have a source
    voltage HIGHER than 5V on the Collector side of the transistor.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe - Mask Designer III

    National Semiconductor Corporation
    Latest Company News
    (Communication Interface Division)
    500 Pinnacle Court, Suite 525
    Mail Stop GA1
    Norcross,GA 30071
Sign In or Register to comment.