Shop OBEX P1 Docs P2 Docs Learn Events
Transistor to be used as DC Motor power switch? — Parallax Forums

Transistor to be used as DC Motor power switch?

jtrzjtrz Posts: 40
edited 2009-04-16 03:17 in BASIC Stamp
Hi all,

This question is not what you think...I hope...

I have a small DC motor that runs off 1-2 AA batteries.· So we're talking about 1.5-3V max here.

I know there are a few ways to do this too...relay, optoisolator circuit (?), motor controller, etc.· I also read that you could do this with a transistor too.

I have a circuit that uses the PING sensor.· When the sensor is activated, pin 14 goes high and lights up an LED.· I want that pin 14 output to now control that small motor.· I was not able to get it to work by directly connecting it to pin 14...but since I've been doing a lot of reading about what it takes to control a DC motor, I know WHY...and understand why you want it isolated from the microprocessor circuit, have it's own power supply, etc.· Hey!· Whaddaya know?· I'm learnin'!· burger.gif

But my question is this...

I just want to have the motor turn on and stay on for the duration that pin 14 is high and off when it goes low.· I'm not interested in controlling forward/reverse motion or speed of the motor.

I just need·something simple to act·like a switch on the·pos (+) wire coming from the motor's battery and be controlled by the output of pin 14.· And I do not want to compromise my BS2 in the process.

Can this be done with a transistor?· If so, which transistor?· What rating would be appropriate for this...only 1.5-3v max?· Don't know that much about transistors to know which to get to control this motor (assuming this could be done).

I'm trying to keep this simple and not have to buy a motor controller like the Micro Dual Serial Motor Controller (Parallax part #30052).· They are fairly reasonable $$$-wise, but I think this might be overkill for this application?

Any thoughts are appreciated...

Thanks,

John

·

Comments

  • Steve in NMSteve in NM Posts: 54
    edited 2008-05-20 23:16
    IRL540 MOSFET!!! I bought a tube of these for $.40 each a few years ago. I'm *still* using it up.

    http://profmason.com/wp-content/uploads/2008/01/irl540n.pdf

    Rugged. Reliable. Simple to use.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The reason we're all here, is because we're not all there.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-05-20 23:27
    The Industrial Control tutorial and, I think, the StampWorks manual have sections with sample circuits and a discussion on controlling motors, relays, and solenoids with a Stamp.· These can be downloaded from the Parallax website.· Choose Resources, then Downloads, then Stamps in Class Downloads.
  • jtrzjtrz Posts: 40
    edited 2008-05-21 15:44
    Steve - Thank you very much for the reference! I read the datasheet PDF from the link you supplied.

    I just don't understand one thing about it. The "Gate Threshold Voltage" is listed as a min of 1V. If I understand the MOSFET correctly, the gate is the part that, when a voltage above the threshold is applied, will the close connection between the the sink and the drain?

    But in my case, when pin 14 is held high, it does not put out that much. So how will that work?

    Thanks,

    John

    Post Edited (jtrz) : 5/21/2008 3:51:28 PM GMT
  • jtrzjtrz Posts: 40
    edited 2008-05-21 15:56
    Hi Mike,

    It's always a pleasure to hear from you! Thanks for your reply.

    I was hoping to not duplicate this basic question about DC motor control. That's why I've been doing a lot of reading on this. I did happen to come across your reply in other posts. And I did read through both docs.

    But the difference, at least in my newbie mind, was that those other solutions were dealing with industrial-strength motors like 12v and above. I'm looking at just turning on/off a 1.5-3v motor run by 1-2 AA batteries (for short periods of time). In my mind, it's just a normally-open switch on the pos (+) side that closes and stays closed for as long as pin 14 from the BS2 goes high. I am trying to make sure I'm not overdoing it. But I think I may be oversimplifying it at the same time.

    Thanks,

    John

    Post Edited (jtrz) : 5/21/2008 7:26:39 PM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2008-05-21 16:03
    1) When a Stamp pin is made high, it is connected to Vdd (+5V) through an MOSFET with a voltage drop of around 0.6V, so the I/O pin should get to around 4.4V.

    2) The minimum gate threshold is the voltage where the FET begins to conduct. There are graphs on the datasheet for any particular MOSFET that give the gate voltage vs. the amount of current conducted (between source and drain).
  • Steve in NMSteve in NM Posts: 54
    edited 2008-05-21 23:56
    jtrz said...
    Steve - Thank you very much for the reference! I read the datasheet PDF from the link you supplied.

    I just don't understand one thing about it. The "Gate Threshold Voltage" is listed as a min of 1V. If I understand the MOSFET correctly, the gate is the part that, when a voltage above the threshold is applied, will the close connection between the the sink and the drain?

    But in my case, when pin 14 is held high, it does not put out that much. So how will that work?

    Thanks,

    John
    (Mike's answers are perfect! So just to add $.02 more...)

    You're very welcome!

    Think of these as a 3-pin solid state switch or relay. Just connect the Gate to the stamp pin and away you go. the only thing to remember is you want the·Drain to be more positive than the Source. Yet, I've hooked them up backward and they still work.

    Connect a multimeter between ground and pin 7 and run the code below. If you don't see pin 7 toggling between 0 and very close to 5VDC, you've got something else going on...

    begin:
    HIGH 7
    PAUSE 2000
    TOGGLE 7
    PAUSE 2000
    GOTO begin

    This also a quick and dirty way to test your set up with a MOSFET.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The reason we're all here, is because we're not all there.
  • ercoerco Posts: 20,256
    edited 2008-05-22 01:19
    Steve: Very well put. Just one edit on your program. Shorter is always sweeter!

    begin:
    TOGGLE 7
    PAUSE 2000
    GOTO begin


    Another option besides transistors and mosfets is a simple reed relay. Radio Shack's·# 275-232 is cheap, simple·& easy to find. It can be driven directly by a Basic Stamp: it only·draws 20 mA·and provides a nice switching action, perfect for this little 3 volt motor. Just be sure to add a small reverse-polarity diode across the coil to kill voltage spikes.




    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."

    Post Edited (erco) : 5/22/2008 1:42:02 AM GMT
  • SandgroperSandgroper Posts: 62
    edited 2008-05-22 13:10
    A BD135 (or BD136) transistor would do the trick also. It will handle loads up to 1A. If you're using the BD135, connect the motor circuit between Vcc and the collector. If you use a BD136 instead, connect the motor between the emitter and ground. A resistor (up to 4.7 k) should be used between the pin and the and the base. As with the relay, a reverse polarity diode across the load is a good investment. So is a suitable heat sink on the transistor.
  • Steve in NMSteve in NM Posts: 54
    edited 2008-05-22 15:15
    erco: HA! Elegant, simplistic beauty. I *swear* I had·a reason for that second pause. I just can't for the life of me remember what it was!·rolleyes.gif·
    I have (and used) a bunch of those relays. But you have to admit that by adding the diode, the parts count went up 2X!·devil.gif It's also prudent practice to add a pull-up/pull-down? YIKES! freaked.gif ow it's 3X!·and starting to eat up board space.·Those relays are currently $3 each, and are rated at half-an-amp. Digi-Key has IRL510s for $0.67 each, and can handle 5.6A continuous. The real-estate occupied by a MOSFET is less than that of one relay -·before you add the·diode and pull-up.

    jtrz: Something else that I remembered: Once you have· the motor toggling on and off, it's now *VERY* simple to control the speed using PULSOUT.

    Sandgroper: Also very correct. But again,· there went the parts count. You·reminded me·another great aspect of MOSFETs: The on-state impedance is so low that typically, no heat sink·required!

    Am I starting to sound like a MOSFET bigot?

    Joking aside, I literally have bags of· transistors, and unopened packages of relays that I may never get around to using. The only anomaly that comes to mind while using a MOSFET was motor noise getting back into the stamp. That can and will happen with any of these methods. True? (Another note to jrtz: Remember to add a ceramic cap across the leads at the motor for noise suppression.)

    I've·been wondering though, why would one choose a dedicated motor-driver over a stamp/MOSFET arrangement·if only to save space? You still·have to provide step/dir.·(Stamp+ MOSFETs > Stamp+motor-driver ???)·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The reason we're all here, is because we're not all there.
  • Steve in NMSteve in NM Posts: 54
    edited 2008-05-22 15:23
    Just another link for jrtz:
    http://www.me.umn.edu/courses/me2011/robot/technotes/motorcontrol/motorcontrol.html

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The reason we're all here, is because we're not all there.
  • ercoerco Posts: 20,256
    edited 2008-05-22 23:20
    Steve: Pullup resistor on pinout to a reed relay? Never seen that. Do you have an example? And to tell you the honest truth, I use these particular reed relays without the diode all the time without any problems. But I mention it here since it's the right thing to do.

    As Samuel Jackson said in SWAT, "Sometimes doin' the right thing ain't doin' the right thing!" And in "Snakes on a Plane", he may well have said, " I want these (blankety-blank) diodes off this (blankety-blank) relay!"

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • Steve in NMSteve in NM Posts: 54
    edited 2008-05-23 00:18
    erco: Nope. I was wrong. Must've had a senior moment there. In my feeble mind's eye, I was seeing the resistor between the stamp pin and the Base on an NPN. blush.gif· Not even close! I should know better than to think while at work. smilewinkgrin.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'm not a complete idiot! Some of my parts are missing.
  • ercoerco Posts: 20,256
    edited 2008-05-23 02:08
    Steve: You gotta go easier on yourself!· After researching your comment, I actually found this thread on reducing IO pin current by adding a pullup resistor: http://forum.microchip.com/tm.aspx?m=309609&mpage=1&key=&#309764
    In your own sly way, you were suggesting a practical way to reduce the Stamp IO pin current necessary to·activate the relay to keep the Stamp cooler and happier. And so to you I say thanks and Bravo! Senior moment? I think not...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • Steve in NMSteve in NM Posts: 54
    edited 2008-05-23 02:52
    erco: THAT, my friend, is an interesting read. That link's a keeper, too. TONS of great information.

    Anyway, it's a form of self-flagellation... since my auto-lobotomy didn't work out.

    I hope I haven't scared off jtrz. tongue.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'm not a complete idiot! Some of my parts are missing.
  • jtrzjtrz Posts: 40
    edited 2008-05-23 20:31
    Not yet! This ain't gonna lick me! I'm just glad I don't have my soldering iron out (yet)! [noparse]:)[/noparse]

    But I did try the Radio Shack reed relay as someone suggested (normally-open SPST reed relay). But I'm not getting it to work. I'm probably not using it correctly. Forget about the reverse diode across the coil for now. I have...

    BS2 Pin 14 to one of the coil contacts on the reed relay
    The other coil contact to GRND
    The NEG (-) of the motor to the common pin on the reed relay
    The N.O pin on the reed relay to the NEG side of the single AA battery
    The POS (+) side of the battery to the POS (+) wire of the motor

    But it seems the relay is not closing. Might be a bad relay too. So I tried this to eliminate the BS2, close the relay, and keep it closed temporarily to just see it the motor would run. It did not.

    The POS (+ Vdd?) to one of the coil contacts on the reed relay
    The other coil contact to GRND

    (Coil should be closed now, right?)

    The NEG (-) of the motor to the common pin on the reed relay
    The N.O pin on the reed relay to the NEG side of the single AA battery
    The POS (+) side of the battery to the POS (+) wire of the motor

    But the motor does not turn.

    Any ideas where I'm going wrong...

    Thanks!

    John
  • jtrzjtrz Posts: 40
    edited 2008-05-23 20:33
    Just looked at that link Steve. Yep! That's a keeper!

    Thanks!

    John
  • ercoerco Posts: 20,256
    edited 2008-05-23 21:03
    John:

    Three things. First, there's no common connection on that relay. Four connections. The two connections, one on each end, are the NO reed switch. The other two are near one end are your coil connections. Use a multimeter to make sure you measure ~250-ohms across this pair. One of these to pin 14, the other to Stamp ground (AKA Vss, AKA Stamp negative voltage). No polarity concerns here, either wire works.

    Second, you can't use a BS2 Homework board with a direct connection to the relay, since it has 220 ohm protection resistors inline with each output pin. If you have a HW board, you'll have to add a transistor switch.

    Third, you can't power the motor using the 5 volts coming out of the Stamp. The onboard regulator can't supply that much current and your Stamp will keep resetting. If you're using AA or bigger batteries (not a 9-volt) you might be able to power the motor off those also, but this depends on your particular motor & wiring layout. Best bet is to use seperate batteries for the Stamp and for the motor.

    I suggest you start by just getting the reed relay working (no motor). Just hook it up as described, and run a simple program like:

    abc:toggle 14[noparse]:p[/noparse]ause 1000:goto abc

    Then use your multimeter to verify that the reed switch (end contacts) are making & breaking contact. Only after that, get the motor going. Again, no polarity concerns here. Cheers.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • ercoerco Posts: 20,256
    edited 2008-05-24 02:05
    John:

    Remember, if Tony Stark can make an Iron Man suit in a cave, you can get this motor going! I took the liberty of snapping a few shots of what we've been chatting about. The motor was running for 1 sec and off for one sec, per the attached program. To keep things·clear in the photo, I kept wiring to a minimum and didn't include a diode here. It does work without it, but it is good policy to put one in parallel with the relay coil, banded end to pin 14 in this case, non-banded end to ground (Vss, battery negative). Put one in once you get it all going. Hope it helps.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
    2560 x 1920 - 807K
    2560 x 1920 - 820K
  • jtrzjtrz Posts: 40
    edited 2008-05-26 01:50
    Hi erco,

    Thanks so much for going above & beyond on the circuit and the photos!· I really appreciate it.·

    There·IS a common contact on the relay.· I'm looking at the schematic from the back of the packaging from Radio Shack now.··There 2 cooil contacts.· On the opposite end of the relay from where the coil contacts are, is the Normally Open (NO) contact.· The only contact left, back at the coil end of the relay, is the COM contact (at least according to the schematic from RS).

    I did have it connected to the external battery I had.· But I thought I wasn't using it correctly and turns out I was right.· I'm trying it again based on your direction and photos.· I'll let you know what comes of it.

    BTW:· I have a BOE (USB) and a BS2.

    Thanks!

    John
  • jtrzjtrz Posts: 40
    edited 2008-05-26 03:41
    Hi again erco...

    SUCCESS! I made your circuit first. Worked fine. Motor pulsed on and off about each second. Then I worked that one into my original circuit. I think I was just using the reed relay incorrectly.

    But I was able to get the PING sensor to work and to turn on the motor! Yeaaaah!

    Thanks again everyone for all your suggestions and help!

    John
  • singallssingalls Posts: 11
    edited 2009-04-16 01:17
    i hate to bump a real old thread but I have to ask.· I am trying to hook the same kind of motor to a homework board.· I know I need a switching transitor but i have a couple of questions.· This is what I have so far from reading a bunch of threads.

    P14 with a 100ohm resistor to base.· Emitter jumped to vss.· I am using the same relay as in this thread.· One side of the relay goes to a +5V.· The other side goes to the collector.· How do I hook up the small motors?

    Any help is appreciated.

    Steve
  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-16 01:33
    You treat a small motor the same way you'd handle a relay. You do need a protective diode across the relay or motor like it's shown in the StampWorks Manual or the other references. A 1N4001 or 1N914 diode from RadioShack would work fine.
  • singallssingalls Posts: 11
    edited 2009-04-16 01:51
    Mike,

    Thank you for your quick response.· I guess I am still stumped.· The two leads coming out of the motor, where would they hook up to?·

    Steve
  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-16 01:57
    Look at the diagram on the last page of Nuts and Volts Column #6. It shows how to hook up a relay or small motor with a switching transistor to a Stamp pin.

    Go to the main Parallax webpage and click on the Resources tab and you'll see a link to the Nuts and Volts Columns index.

    If you still can't figure it out, ask again and mention what you don't understand after looking at the magazine article. Your motor would be the LOAD shown in Figure 6.1.
  • singallssingalls Posts: 11
    edited 2009-04-16 02:47
    Mike,

    Again thanks for the information.· I have read that article a couple of times the last few days.· I have to admit, I am not good at reading schematics.· I understand fig 6.1 and the load.· But in that figure, where does the relay come in?· On the last page I think I understand.· When pin 7 comes high it closes the relay, but I do not see anything else to see how the door unlatches or how it is connected.

    Steve
  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-16 03:08
    The motor takes the place of the relay. If you have the transistor switch the current to the motor, you don't have a relay.
  • singallssingalls Posts: 11
    edited 2009-04-16 03:17
    Mike,

    Can you please elaborate on your last post.· I am not following.· Here is what I have.· I have a HW Board.· I want to attach a 3V motor to it.· From reading the thread I thought I need a relay (which I have).· But since I am using the HW board I thought I needed a switching transistor.·

    Steve
Sign In or Register to comment.