Shop OBEX P1 Docs P2 Docs Learn Events
Replacing a 5v switch with Propeller/Transistor? — Parallax Forums

Replacing a 5v switch with Propeller/Transistor?

Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
edited 2008-07-04 13:19 in Propeller 1
I've got a device that uses a 5v switch to activate a feature on the device.

I want to replace that switch with the following.. Is this safe for the Propeller?

---P0---LED---NPN(Base)
Gnd--->NPN(Collector)
5v--->NPN(Emitter)




I'm using the LED to prevent a short on the Propeller..
(seems to work in test with the meter)

OBC

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
New to the Propeller?

Getting started with the Protoboard? - Propeller Cookbook 1.4
Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
Got an SD card? - PropDOS
Need a part? Got spare electronics? - The Electronics Exchange

Comments

  • PraxisPraxis Posts: 333
    edited 2008-06-26 23:33
    I assume that you want to switch a 5 Volt input to ground using a transistor driven with a prop output.

    If that is correct then this circuit should suffice.

    Cheers
    550 x 272 - 4K
  • Mike GreenMike Green Posts: 23,101
    edited 2008-06-26 23:34
    The LED won't prevent a short on the I/O pin.· You need a resistor.

    The way you plan to connect things will create a nice puff of smoke and not much else.

    For an NPN transistor, you connect the emitter to ground.· You connect the collector to your load with the other end of the load connected to your positive power supply for the load.· You connect the base through a resistor to the I/O pin.· The resistor value depends partly on how big a load you have and what the gain of the transistor (hFE) is.· A Propeller I/O pin can easily handle a 20mA load.· Start with a 150 Ohm resistor.
  • PraxisPraxis Posts: 333
    edited 2008-06-26 23:49
    Make the transistor do all the hard work, not the prop, depending on your transistor gain start with a 1K resistor.
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2008-06-27 00:26
    Figured more protection couldn't hurt.. 100k seems to still trigger the transistors no problem

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Getting started with the Protoboard? - Propeller Cookbook 1.4
    Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
    Got an SD card? - PropDOS
    Need a part? Got spare electronics? - The Electronics Exchange
  • Mike GreenMike Green Posts: 23,101
    edited 2008-06-27 00:34
    Arbitrarily picking values is not a good way to make design decisions.· It often results in things not working the way you want them, sometimes destructively.

    Ohm's Law is really not that hard to use.· The base to emitter forward voltage is typically 0.6V.· The Propeller's high output voltage is roughly 3.0V.· That leaves 2.4V to drop in the resistor.· I = E / R = 2.4 / 100,000 = 24uA.· That's not a lot of current.· If you have a transistor with a gain of 100 (not unusual), you'd get 2.4mA output current.· That's not a lot of current either, even for use with just an LED.
  • PraxisPraxis Posts: 333
    edited 2008-06-27 08:02
    Here is a picture that explains it in more detail.
    962 x 675 - 35K
  • Ken PetersonKen Peterson Posts: 806
    edited 2008-06-27 13:10
    If you are going to replace a switch with a transistor, it's important to understand what the switch is switching. If the switch is simply pulling a line to ground, then a NPN transistor is an easy replacement. Sometimes the function of the switch is a little more complicated. Also, what to use for "on" current depends on the value of the pullup resistor being used with the switch. You would then choose your base resistor accordingly per Mike's suggestions, and make sure Ib is less than 30mA.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2008-06-27 13:37
    Praxis,

    What you have drawn is not really correct. You should either draw voltages across components or with respect to ground. They way you have drawn it is with respect to ground but the voltage on the base of the transistor should be 0.6v (because from base to emitter the voltage is 0.6v).

    So it is 3v wrt ground on one side of the resistor and 0.6v wrt ground on the other hence 2.4v across the resistor.

    Ken,

    you make a good point, there is no such thing as a 5v switch really just a switch.

    Graham
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2008-06-27 15:03
    The project has morphed a bit since this started...

    So I'm going over to Solid State Relays as now I'm controlling more than one switch..

    I'm thinking that Digikey: 255-1546-5-ND RELAY OPTO DC 40V 700MA 6-DIP
    should fill the need.

    Can anyone share their experience with these?

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Getting started with the Protoboard? - Propeller Cookbook 1.4
    Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
    Got an SD card? - PropDOS
    Need a part? Got spare electronics? - The Electronics Exchange
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2008-06-27 18:11
    Oldbitcollector said...

    So I'm going over to Solid State Relays as now I'm controlling more than one switch..

    Why does that make a difference?

    Graham
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2008-07-03 02:56
    I thought I'd take a shot at a transistor based circuit, as relays (on order) seem like a wimp-way out of learning.

    The attached circuit didn't work, and I suspect that it's because I should not be using NPN transistors for
    this. While it worked for a single switch, it did not handle multiple. I *think* because of the common ground
    required for the Propeller.

    I submit this "transistorized error" for the experts to advise..

    I swear I'm going to master transistor logic if it kills me!

    What went wrong?
    Edit: Cleaned up the artwork a bit, hopefully a little clearer of how things are wired.

    Thanks!
    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Getting started with the Protoboard? - Propeller Cookbook 1.4
    Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
    Got an SD card? - PropDOS
    Need a part? Got spare electronics? - The Electronics Exchange

    Post Edited (Oldbitcollector) : 7/3/2008 4:01:58 AM GMT
    753 x 636 - 65K
  • Mike GreenMike Green Posts: 23,101
    edited 2008-07-03 04:10
    You're sure going to either blow out a lot of NPN transistors or possibly your Atari power supply. If what you've drawn is correct, you've connected all your Atari joystick inputs to ground. You've also connected the NPN transistors so they'll short out the Atari +5V supply as soon as they're switched on by the Propeller. Either the transistor will give up first or the Atari power supply. It'll probably be the transistor.

    Basic circuit:
    Connect transistor emitter to ground.
    Connect transistor base through 1K resistor to Propeller I/O pin
    Connect transistor collector to Atari input pin
    Connect resistor (1K to 3.3K) from Atari +5V supply to transistor collector (and Atari input pin)
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2008-07-03 04:51
    Mike,

    A closer look at the actual pins used on a typical joystick
    do not include the use of the +5 line. I haven't gotten my
    meter on the port itself yet, but it looks like the C64 I/O is
    pulled low by the switches in the joystick to ground.

    That being the case, the attached schematic replicated
    5 times should work no?

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Getting started with the Protoboard? - Propeller Cookbook 1.4
    Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
    Got an SD card? - PropDOS
    Need a part? Got spare electronics? - The Electronics Exchange
    380 x 465 - 22K
  • Mike GreenMike Green Posts: 23,101
    edited 2008-07-03 05:03
    Assuming the C64 has built-in pullups or the logic used has a default of logic high and has current limiting so a switch closure to ground is normally used, then the circuit you posted should work.
  • bambinobambino Posts: 789
    edited 2008-07-03 14:38
    Mike,

    Would changing the transistor to a darlington pair significantly change or eliminate the need for the resistor at the I/O pin?
  • Mike GreenMike Green Posts: 23,101
    edited 2008-07-03 15:00
    bambino,
    You have to have some sort of current limiting resistor. Otherwise, the base-emitter junction in the transistor will conduct as much current as you supply until either the transistor burns up or the Propeller I/O pin structure burns up. Probably the Propeller will current limit first and nothing will be damaged, but I wouldn't design on that basis.

    You need enough current into the base to saturate the transistor. Usually that's given in the transistor's datasheet. A 1K Ohm resistor as I suggested would give a base current of 2.7 mA ((3.3V - 0.6V) / 1K). Even if the transistor had a gain of only 30, that would be a collector current of 80 mA which would certainly take care of a logic input.

    With a Darlington, you'd have a base current of roughly 2mA ((3.3V - 1.2V) / 1K). Darlingtons have gains in the 1000's, so that's more than enough base drive.
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2008-07-03 15:35
    bambino,
    ·
    With a Darlington, you essentially create a current multiplier.· For example if the Hfe of one transistor is 20 while the Hfe of another transistor is 50, then the combined Hfe is 1000.· You still however need a base resistor to limit the current.· Remember that each transistor within a Darlington stage adds about 0.6V so your calculations for a base current resistor should be adjusted accordingly.
    ·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
    899 x 835 - 126K
    899 x 875 - 133K
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2008-07-04 03:11
    Kudos Mike!

    The second board worked perfectly! Thanks to you!
    I'm glad I stuck it out, as I have gained a better understanding of transistors as a result!

    Next up.. Expand the .spin code to include other input devices.
    Thinking I'll hook the accelerometer up next, maybe I'll tape it to a wiffle-bat
    and play some Commodore Hardball with it. [noparse]:)[/noparse]

    Here's a shot of the Nintendo adapter on C= Boulderdash

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Getting started with the Protoboard? - Propeller Cookbook 1.4
    Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
    Got an SD card? - PropDOS
    Need a part? Got spare electronics? - The Electronics Exchange
    800 x 600 - 124K
  • bambinobambino Posts: 789
    edited 2008-07-04 13:19
    Thanks Mike, Beau,
    I guess there is smoke in my near furture then. I have a PNP darlington with no resistor. One is driving a piezo and another driving a fan.
Sign In or Register to comment.