Shop OBEX P1 Docs P2 Docs Learn Events
Using a Transistor As a Switch — Parallax Forums

Using a Transistor As a Switch

CharlieTCharlieT Posts: 11
edited 2012-06-21 04:10 in Propeller 1
I am trying to make a circuit (my first) that uses a transistor as a switch. I am looking for advice regarding what transistor and corresponding resistor(s) I should use.

What I am trying to do is switch a small beeping unit (extracted from a child's toy) on and off. I thought I could accomplish this with a transistor.

The beeping unit runs on two 1.5V batteries, which produce 2.82V current (I measured this manually).

From what I understand, I can use the Propeller's 3.3V output as the base supply that controls the switch...?

So, I am not sure what transistor (and resistor) I should use. Any help would be greatly appreciated.

Thank you.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-06-16 15:16
    We need more information. How much current does the beeper draw (milliAmps)? Did you want to power the beeper from the Propeller's power supply? The Nuts and Volts Column #6 gives examples for the Stamp, but the idea is the same. You could use the same kinds of transistors, but the resistors would be smaller due to the lower voltage. Something between 150 Ohms and 270 Ohms would be fine providing a base current between 20mA and 10mA.
  • Duane C. JohnsonDuane C. Johnson Posts: 955
    edited 2012-06-16 15:18
    Here are 3 solutions to try assuming:
    1. 3.3V supply.
    2. Driven by a prop pin.

    TranSwitch.png


    BTW, if the beeper unit is like those small sound chips in greeting cards
    you can run them directly from the prop pin without any transistor buffer at all.

    Duane J
    972 x 654 - 16K
  • WolfyWolfy Posts: 14
    edited 2012-06-16 15:25
    Seems like you are just starting out with the propeller, but yes you can use it to drive a transistor as a switch. If the whole circuit runs on 3-4 volts, 240 ohm resistors with a cheap 2n3904 NPN would do the job. To turn on the transtor, jus set the prop pin it is attached to high. To turn it off, set it low.


    ....................................................[SRC*]
    .......................................................+
    ....................................................(RES*)
    .......................................................+
    ...................................................{beeper}
    ...................................................... +
    (Propeller output pin))---(RES*)
    [transistor]
    .......................................................+
    ...................................................[GND*]

    edit: ignore the dots, they are only there to keep the drawing from messing up
    when I post it.

    *RES is the 240 ohm resistors
    *GND is the ground connection
    *SRC is the voltage source (positive three volts)

    I hope this will help you out, I'm not too great at drawing circuits in text form, but that one should work as long as the values you use stay relatively close.
    All that is left is for you to make the program to control it, sadly, I have no SPIN knowledge, on BASIC for the stamp.
  • Invent-O-DocInvent-O-Doc Posts: 768
    edited 2012-06-16 17:47
    Charlie,
    You are the perfect customer for Matt Gilliland's (Parallax employee) "Microcontroller Applications Cookbook" - It has all kinds of very simple circuits to do lots of stuff like this and is pretty microcontroller agnostic (though there is basic stamp code). You can buy it on Amazon or somewhere.

    I've got two copies of both the basic and advanced books and keep them near my bench because I'm just a hobbyist.
  • Cluso99Cluso99 Posts: 18,069
    edited 2012-06-16 19:15
    I would very much suspect that the current drawn is less than the 30mA that a prop pin is capable of switching directly. As long as it is not a relay which can cause spikes back into the prop.
    So, since you have measured the voltage, most likely you can also measure the current too. If its switching then you will not get a proper reading.

    I would first use a 150 ohm (150R) in series with the prop pin and your load (beeper) to ground. The resistor will protect your propeller. When the prop pin is on (high) the beeper should sound. Measure this current or measure the voltage across the resistor and you can then calculate the currrent from this. You can lower the resistance until you get to say 25mA (keeping some safety margin). The resistor can also be used to qieten the sound.
    If this does not make it beep, then you may have to switch the prop pin on and off (i.e. output alternate 0's and 1's with a delay between each - try 1KHz which is 0.5ms on and 0.5ms off)

    Duane has given you 3 circuits that should work with transistors/fets. Note that a resistor in the collector leg in series with the load (the beeper) should not be required.
  • CharlieTCharlieT Posts: 11
    edited 2012-06-18 17:22
    BTW, if the beeper unit is like those small sound chips in greeting cards
    you can run them directly from the prop pin without any transistor buffer at all.

    Duane,

    Thanks so much for the circuit examples.

    Yes, the beeper unit is in fact a tiny sound ship like one would find in a greeting card.

    Following your suggestion, I tried running the chip directly from a prop pin without any transistor buffer, and it did work(!) -- but only under certain conditions... i.e. when the sound unit is the only thing the Propeller is running, it sounds fine.

    The problem: my project also includes an LCD screen module. When used together with the LCD screen, the sound chip/speaker unit only produces static/feedback noise.

    Would implementing one of the transistor circuits you provided perhaps solve this problem?

    Thanks again.

    -- Charlie
  • RinksCustomsRinksCustoms Posts: 531
    edited 2012-06-18 18:03
    you could try a "decoupling" capacitor on the power line for your chirper. Usually an electrolitic capacitor 1uF to 10uF will help to smooth out the power to the chirp circuit. This might seem like overkill, but it's easy to implement. Instead of a NPN transistor, you could use a power MOSFET (enhancement mode). Source goes to ground, Drain goes to the negative lead of the chirper, Gate goes to a prop pin. When you make that prop pin high it turns on the power fet, and the "on" resistance is about 0.4 ohm, so its just like having a physical switch.
  • Duane C. JohnsonDuane C. Johnson Posts: 955
    edited 2012-06-18 18:14
    Hi Charley;

    I have a greeting card sound device that plays a tune.
    My prop drives it. It draws about 0.5mA.

    Clearly, the prop pin should easily drive this.
    There should be no problem.

    1. I speculate the pin may be changing for some reason. Possibly associated with the LCD or other software.
    2. Check to see if the 3.3V VDD voltage is stable. Maybe the voltage is dropping out but far enough to reset the prop. I don't know?

    Unless the thing draws a lot of current, say 20mA or more even in pulses, you should not need a buffer.

    Maybe the 3.3V or a bit lower isn't enough to make it run.

    Try running it directly from the VDD power buss and see what happens.

    Duane J
  • CharlieTCharlieT Posts: 11
    edited 2012-06-20 17:16
    Among those of you who were kind enough to reply, several people have asked me for the current. Unfortunately, my multimeter does not seem to be functioning properly to get a reading in mA.

    However, Cluso99 mentioned an approach:
    Cluso99 wrote: »
    I would first use a 150 ohm (150R) in series with the prop pin and your load (beeper) to ground. The resistor will protect your propeller. When the prop pin is on (high) the beeper should sound. Measure this current or measure the voltage across the resistor and you can then calculate the currrent from this.

    Before the resistor, the voltage reading fluctuates between 3.28 and 3.29

    After the resistor, the voltage reading fluctuates between 3.11 and 3.20

    Is it possible to calculate the current from these readings?
  • Cluso99Cluso99 Posts: 18,069
    edited 2012-06-20 18:55
    E=I*R where E= volts, I=current in Amps, R=resistance in ohms
    Therefore,
    I=E/R=0.15/150=0.001A=1mA (so that is probably why your meter doesn't read it)

    So, the prop will definately drive this without a resistor. Can you post pictures of your setup and we may see what you are doing wrong?
  • CharlieTCharlieT Posts: 11
    edited 2012-06-20 20:34
    Hi Charley;

    I have a greeting card sound device that plays a tune.
    My prop drives it. It draws about 0.5mA.

    Clearly, the prop pin should easily drive this.
    There should be no problem.

    1. I speculate the pin may be changing for some reason. Possibly associated with the LCD or other software.
    2. Check to see if the 3.3V VDD voltage is stable. Maybe the voltage is dropping out but far enough to reset the prop. I don't know?

    Unless the thing draws a lot of current, say 20mA or more even in pulses, you should not need a buffer.

    Maybe the 3.3V or a bit lower isn't enough to make it run.

    Try running it directly from the VDD power buss and see what happens.

    Duane J

    You were right -- it seems that the voltage of the prop pin I was trying to use was being affected by the LCD screen operations. I tried several other prop pins and finally found one that works. Thanks a lot for the help.
  • Cluso99Cluso99 Posts: 18,069
    edited 2012-06-20 20:41
    If the pins that don't work are not being set by another cog then you most likely have a power supply problem. It will show up elsewhere if this is the case. Best you locate the problem now.
  • CharlieTCharlieT Posts: 11
    edited 2012-06-20 20:44
    Cluso99 wrote: »
    E=I*R where E= volts, I=current in Amps, R=resistance in ohms
    Therefore,
    I=E/R=0.15/150=0.001A=1mA (so that is probably why your meter doesn't read it)

    So, the prop will definately drive this without a resistor. Can you post pictures of your setup and we may see what you are doing wrong?

    Thanks for explaining the current calculation and confirming that I don't need to use a resistor. I switched to a different prop pin, and it's working perfectly. Thanks for the help.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-06-21 04:10
    I will contradict everyone here and say use the transistor and don't make that lowly Propeller pin have to do so much of the work.

    The Propeller is rated for 300ma total, including running the 8 COGS. I try to have each pin use about 2ma. There is nothing wrong with learning how to insert a driver to boost voltage and current as these skills are often required. 28 I/O pins at 2ma = 56ma total and leaves 244ma for actually making the Propeller's COGs happy if all pins were in a sustained High condition.

    If you are always depending on 20, 30, or 40ma from an I/O pin, you are going to have several Propellers with a few damaged I/O pins. You are working near their failure limit.

    According the 2n3904 PDF, 1 ma will provide a gain of 70, so that the transistor will drive 70ma when a 3300 ohm resistor is used- far more power than the Propeller. And it can be replaced easily if you do short-circuit something.
Sign In or Register to comment.