Using a BS2 to control relays
jjohns63
Posts: 9
Hi all, I'm hoping someone can help me out. I'm completely stuck. I've got a BS2 running the program below. Pins 1-5 are wired to transistors, driving several relays. Only 3 relays are ever engaged at a time. Each relay draws 79mA when engaged and the transistors have an amplification factor of ~180. The problem is that my program will completely restart, seemingly at random. Here's a diagram of my circuit, the circuit is repeated for each pin, 1-5:
Any suggestions will be most welcome. Let me know if you have any questions.
Any suggestions will be most welcome. Let me know if you have any questions.
' {$STAMP BS2} ' {$PBASIC 2.5} INPUT 14 Counter VAR Word HIGH 15 Counter = 0 DO UNTIL Counter=10 DEBUG "LOOPING", CR IF IN14=1 THEN Counter = Counter + 1 ELSE Counter = 0 ENDIF PAUSE 10 LOOP DEBUG "start!",CR LOW 15 PAUSE 1000 ' Wait a second before starting HIGH 3 ' Extend piston #1, DEBUG "START PISTON #1", CR PAUSE 1000 ' Wait a second for the piston to move HIGH 2 ' Spin motor, DEBUG "START MOTOR", CR PAUSE 7000 ' Wait several seconds for the bulb to unscrew LOW 2 ' Stop motor, LOW 3 ' Retract piston #1, DEBUG "STOP MOTOR, PISTON #1", CR PAUSE 1000 ' Wait a second for the piston to move HIGH 4 ' Extend piston #2, DEBUG "START PISTON #2", CR PAUSE 1000 ' Wait a second for the piston to move HIGH 3 ' Extend piston #1, DEBUG "START PISTON #1", CR PAUSE 1000 ' Wait a second for the piston to move HIGH 1 ' Spin the motor in the other direction DEBUG "START MOTOR (REV)", CR PAUSE 16000 ' Wait several seconds for the bulb to screw in LOW 1 ' Stop motor, LOW 3 ' Retract piston #1 DEBUG "STOP MOTOR, PISTON #1", CR HIGH 5 ' Start train DEBUG "START TRAIN", CR PAUSE 7000 ' Wait for train to complete run LOW 5 ' Stop train DEBUG "DONE", CR STOP
Comments
Without a better and more complete diagram, it's hard to tell what's going on.
Looks like you need a current limiting resistor on the base of your transistors. Even though the current required for the Relays are relatively small, you still need a current resistor on the transistor base. A bipolar transistor is a current device and has a fixed voltage of about 0.6V ... driving it directly with 5V can damage it or cause excessive current drain from the Stamp which may be causing your resets.
If the relay draws 79mA, a good rule of thumb is to double this value in the calculations. So the transistor needs to drive 158 mA in this case.
If your Hfe or gain is 180, then the base current requirement would be about 0.88 mA. 158mA / 180 = .87...mA
Since the Stamp is capable of driving the I/O at 5V the current limiting resistor value can be determined with the following formula....
R = ( Vsource - Vbe ) / Ibe
Where:
Vsource = 5V (Voltage from the I/O)
Vbe = 0.6V (Voltage across the Base Emitter transistor junction)
Ibe = 0.88mA ( Current requirement across the Base Emitter transistor junction)
R = ( 5V - 0.6V ) / 0.88mA
R = 4.4V / 0.88mA
R = 5000 Ohms .... It's ok to use the closest standard value of 4.7k Ohms in this case.
Edit:
You can use a PNP transistor only if the supply to the transistor is at the same voltage potential as vdd. That said
you should not use the regulated vdd from the Stamp to drive your relays. A separate external regulator should be used
to power your relays via the transistors.
Check this link...
www.parallax.com/Portals/0/Downloads/docs/cols/nv/vol1/col/nv6.pdf
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 2/2/2009 7:09:06 AM GMT
Beau, if I replace the Vdd with another voltage source, do I need to use a regulator, or could i just use a 9V battery?
EDIT:
I'm using Fig B here: ourworld.compuserve.com/homepages/Bill_Bowden/r_ctrl.htm. I'm using Fig B because my relay coil voltage is 5V.
Post Edited (jjohns63) : 2/2/2009 4:11:34 PM GMT
If your voltage sources are different, use Figure A from the link that you provided.... Figure B even states that it "...can be used when the input voltage is the same as the relay coil voltage."
Edit:
Although take what you read with a grain of salt... I'm not sure I totally agree with some of the writers comments in that article.
.... use "figure A", it's a popular configuration used in many applications.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 2/2/2009 4:53:35 PM GMT
So my relays are 5V rated coils, therefore I should be able to use Fig B since the I/O pins are 5V. Or am I misunderstanding the diagram?
Yes, the input (transistor base) through a current limiting resistor goes to the BS2's I/O.
Yes, the V+ should be another voltage source. It can be the same potential as Vdd (+5V), just coming from an External 5V regulator instead of the one that the BS2 provides. The reason is because the BS2's regulator simply can't handle a great deal of current, especially multiple relays at 100 mA or so.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
I'll post here if it works or not, but I won't know for several hours.
Edit:
OK, I spoke too soon. I had several successful runs but after moving my circuit, it seems that it has stopped working consistently. I get random resets, same behavior as before. The reset doesn't always happen in the same place in the program. It seems that if I shorten my trigger switch wires, the program runs fine.
Post Edited (jjohns63) : 2/3/2009 2:12:18 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·"If you build it, they will come."
Post Edited (erco) : 2/3/2009 3:00:17 AM GMT
Thanks for all your help everyone.