how to trigger some 12 devices with using 5v?

Discussion in 'The Projects Forum' started by kelvinchow87, Jun 14, 2009.

  1. kelvinchow87

    Thread Starter New Member

    Jun 14, 2009
    1
    0
    i'm a student form malaysia.i'm studying PIC16f877a..
    i found a problem on triggering my 12v buzzer..
    my Pic output voltage is around 3.5V-5V..and not ability to trigger the buzzer...even i'm using 5v relay to trigger it..but is still not work..
    somebody can help me?
     
  2. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    PIC microcontrollers have very limited current source/sink capability; 20mA maximum per I/O pin, and there is an additional total I/O current limit. If you operate near the maximums, you will make the lifespan of the uC much shorter.

    Use a driver circuit, like an NPN transistor such as a 2N2222 with a 470 Ohm resistor connecting the PIC's output pin to the transistor's base, which will limit the current sourced from the pin to around 10mA. Ground the transistor's emitter, and sink current from the load via the transistor's collector.

    Here's a couple of examples; driving a relay and driving a buzzer:
    [​IMG]
     
    Last edited: Jun 14, 2009
  3. franzschluter

    Active Member

    Jun 1, 2009
    95
    0
    And don't forget to put protection diode on coil of relay or inductance device. This is to protect your transistor. You can use NPN as Mr. Sgtwookie adviced or use PNP. Some other prefer to use optocouplers as well. There is a variety of ways to do it.

    1. Transistor NPN/PNP BJT

    2. Optocoupler

    3. Mosfet
     
  4. CDRIVE

    Senior Member

    Jul 1, 2008
    2,223
    99
    Sgt.Wookie provided you with two circuits. One used a relay, that has a protection diode across the coil. The other circuit used a buzzer. If your buzzer isn't a Piezo Buzzer, but rather an electromechanical type, then you need a protection diode across the buzzer too! An electromechanical buzzer can generate thousands of high voltage spikes in a matter of seconds. ;)
     
  5. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    You couldn't use a PNP directly unless the 5v rail was common with the 12v rail, as otherwise you wouldn't be able to turn a PNP transistor off. You would need to use an NPN transistor to control the PNP transistor's base.

    Optocouplers are great for isolation, but generally an optocoupler's output transistor is pretty limited in current capability. Unless you really needed the isolation, you'd add complexity without gaining a lot, as you'd still need a driver transistor.
    Power MOSFETs must be of the logic-level variety. 2N7000/2N7002's actually work quite well for small loads.

    However, MOSFETs are very susceptible to damage by static electricity, and require some special considerations. Generally, a power MOSFET needs a resistor from it's driver circuit to the gate terminal to prevent "ringing" at high frequency, and a much larger value (say, 10k) from the gate to the source terminals to keep it turned off in case the driver circuit fails.

    For a PIC driving a small MOSFET directly, you could use a 220 Ohm resistor between the I/O pin and a small power MOSFET's gate for operation as a low frequency switch (say, under 100Hz.) For higher frequency operation and/or higher power MOSFETs, you'd really need to use a driver circuit, as otherwise the MOSFET would spend too much time in the linear region and overheat.
     
  6. franzschluter

    Active Member

    Jun 1, 2009
    95
    0
    1. You could use a PNP. PNP just means it's normally closed. Depending on how you program your PIC. I have a PLC that outputs 4.5V which goes to a PNP circuit. Depends on programmer or what you have in stock. I just posted the options.

    2. An Optocoupler can drive a relay.
    http://www.edaboard.com/ftopic158099.html

    Fairchild I think also has optocouplers that can drive relays from TTL signal. Which provides isolation. A regular BJT transistor works also but optocoupled even better if you value your PIC. I did similar setups using MOSFETs,Transistor and Optocouplers. In the end I settled for MOSFETs. All of these units are anyway dirt cheap so try out which is easiest for you to apply or which you already have available on your desk. Optocoupler definitely works. Tested but not all of them work. There are a variety of them. You should know which to use. Under Optocoupler I refer to ICs that are "light" dependent.

    If you do take PNP as switch you should take note that they are normally ON. When base sees ground they switch "on" and vice versa.

    3. MOSFETs are good for driving good loads such as 1 Amp above easily. Of course we need those with TTL level.

    Cheers
    Franz
     
  7. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    OK, let me qualify my assertion.
    If a PIC's I/O pin is set to OUTPUT, and the emitter of the PNP transistor is a volt or two more positive than the PIC's Vdd, and the I/O pin connected to the base of the transistor, the PIC won't be able to turn off the PNP transistor by the base.

    Even if the PIC's I/O pin were set to INPUT (high impedance), the ESD protection diodes on the PICs' I/O pins would keep the pin within a range of around 0.7v of Vdd and GND - 0.7v, up to the limit of the ESD protection diode's limitations. Beyond that, you'd fry the uC.

    [eta]Here's a simplified example of what I'm talking about:
    [​IMG]
    Since the PICs' I/O pin is set to input (high impedance), it's not shown; only a representation of the ESD protection diode to the positive rail. Thus, the PIC's I/O pin is held to around 5.7v (Vdd + the ESD diodes' VF). The PNP transistor is still biased ON, with about half the base current it would've received had the PICs' pin been pulled to ground.
    [/eta]

    Point granted - if a suitable Optocoupler is chosen.

    It's not just "seeing" ground; if you pull Vb more than around 0.65v more negative than Ve, it'll begin conducting.

    If Ve = 12v, and Vdd of the PIC is 5v, the highest the output of the PIC can become (without being destroyed) is around 5.7v due to the built-in ESD diodes. That would keep the transistor biased ON, until you physically disconnected the transistor's base from the PIC's output.

    Here's an example of how you'd need to configure a pair of NPN/PNP transistors to source current to a load:
    [​IMG]

    R1 limits Q1s' base current to around 10mA.
    R2 limits Q3s' base current to around 10mA.
     
    Last edited: Jun 15, 2009
  8. franzschluter

    Active Member

    Jun 1, 2009
    95
    0
    http://www.kpsec.freeuk.com/trancirc.htm

    But to turn off perhaps a pull up resistor is required.... Sorry didn't draw the diagram for it :D

    I used this as a reference before also which explains how simple transistor works...

    http://www.kpsec.freeuk.com/trancirc.htm

    Similar circuits... With 12V application...using 2N3906
    http://www.rason.org/Projects/transwit/transwit.htm


    I copied the circuit as reference and it worked but I had a pull down resistor/pull up toggle. Mines was set to pull up and it worked. My relay were 6V small PCB relays which came as a board unit (semi PCB kit which you could solder on the PIC kit (MEGA32 C-control to be precise). I didn't use it for any application just for the sake of killing time though.. Circuit I tested was less in 5min so I wouldn't know if the effects you have mentioned would really be the case if I had run it for longer periods of time...

    What you say does make sense though... But in reality this is what I have done according to some reference sites...Maybe I missed a part or two

    Cheers
    Franz
     
  9. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Note that on that page, under "Example" for the circuit you're talking about is this important sentence:
    "The supply voltage is 6V for both the IC and load."
    In this case, a single PNP transistor can be used, because the IC is a 4000-series CMOS whos' outputs can approach the power rails; thus the IC can bring the transistor's Vbe into cutoff range.

    That would get ugly (big waste of power). It would work, but it would be a very bad design.

    OK, you were using 6v for the PCB relays AND the PLC kit. That would work, as the PLC could output nearly 6v, thus allowing the transistor to enter cutoff.

    However, with a PIC running even from maximum Vdd and the buzzer or relay running from 12v, the PNP transistor alone would be kept biased on.
     
Loading...