Controlling switches with a PIC


Closed Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Apr 2006
    Posts
    92

    Default Controlling switches with a PIC

    I was wondering if anyone could point me in the right direction about how to control switches with the pic18f452

    I would like to replace a momentary push button switch whose contact is normally open (off), and "on" when grounded (pressed). It's a single pole, single throw switch.

    So I would like to replace this switch and control it with the PIC.

    Thanks for any advice.

    T
    Last edited by TonyA; - 4th March 2008 at 17:31.

  2. #2


    Did you find this post helpful? Yes | No

    Default

    Something like an SN75477 interface driver chip would work. Basically it is an open collector transistor with some glue logic. If you want some isolation use an opto-isolator like a PS2801-1. It is an LED driving a phototransitor. Just connect the phototransitor outputs up like a standard open collector driver.

    JIC, an open collector drive output is just a series resistor connected to a positive voltage on one end and the other end connected to the collector pin of the transistor. The emitter is connected to ground and your output signal is connected to the collector as well, sometimes through an isolation resistor.
    Last edited by falingtrea; - 4th March 2008 at 17:48. Reason: spelling

  3. #3
    Join Date
    Apr 2006
    Posts
    92


    Did you find this post helpful? Yes | No

    Default

    Thank you.

    Is it possible to just use a 2N2222 transistor?

    I found this schematic, however my application is a little different. (It got me thinking though):

    http://www.rentron.com/images/rely-drv.gif

    If the relay was omitted from that circuit, and since I just need to switch an incoming wire to ground via the transistor. The "switching" would be controlled by the PIC.

    Would I just connect B of the transistor to the pic pin, C to the incoming wire and E to ground?

    Then toggle the PIC pin attached to B of transistor? Would this send my "incoming wire" to ground?

    Thanks for the help.

    T
    Last edited by TonyA; - 4th March 2008 at 18:08.

  4. #4
    Join Date
    Sep 2007
    Posts
    50


    Did you find this post helpful? Yes | No

    Default

    It really depends on how much current you are switching and if it is AC or DC. I would think the simplest way is to use a relay for the load and a Darlington Transistor if the relay draws too much current from the pic.
    Best Regards,

    Kurt A. Kroh
    KrohTech

    “Goodbye and thanks for all the fish”

  5. #5
    Join Date
    Apr 2006
    Posts
    92


    Did you find this post helpful? Yes | No

    Default

    The load is 5V dc. It's just a simple digital switch that I want to replace/control with the pic.

    I just need to control the grounding of the "incoming" 5V dc wire.


    If we removed the diode and relay, and disconnected "C" from the schematics "VCC" from this circuit: http://www.rentron.com/images/rely-drv.gif

    1. Attached a 5V dc voltage wire to the "C" of the 2n2222 transistor.
    2. Connected "E" of transistor to ground.

    Would the 5V dc wire (connected to "C") be brought to ground when the pic pin is high?

    Now, referring to the schematic as it is exactly in that diagram, is the transistor there just bringing the (-) of the relay to ground. In other words, when the PIC pin is brought high or low this action switches the relay (-) to either ground or "no connection"?

    Thanks again for the help.
    T
    Last edited by TonyA; - 4th March 2008 at 18:35.

  6. #6
    Join Date
    Sep 2007
    Posts
    50


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by TonyA View Post

    Would the 5V dc wire (connected to "C") be brought to ground when the pic pin is high?

    The 2n2222 is an NPN BJT transistor.

    See: http://en.wikipedia.org/wiki/2N2222

    Yes, when voltage is applied to the base, current will flow from C to E. When the base is low, there is no flow.
    Best Regards,

    Kurt A. Kroh
    KrohTech

    “Goodbye and thanks for all the fish”

  7. #7
    Join Date
    Apr 2006
    Posts
    92


    Did you find this post helpful? Yes | No

    Default

    Thanks for the help, I appreciate it.

    Would the 2n2222 work for my application? (i.e. just pulling a 5V wire to ground?) Which transistor would you recommend?

    Thanks again,

    TOny
    Last edited by TonyA; - 4th March 2008 at 22:17.

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by TonyA View Post
    Thanks for the help, I appreciate it.

    Would the 2n2222 work for my application? (i.e. just pulling a 5V wire to ground?) Which transistor would you recommend?

    Thanks again,

    TOny
    Use the 2N2222. As long as you aren't pulling a zillion amps thru it, you'll be fine.
    Just make sure you read and understand how to do so...

  9. #9
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by TonyA View Post
    (i.e. just pulling a 5V wire to ground?) Which transistor would you recommend?
    None!

    Just use the Tri-State output of the PIC.

    Code:
    PORTB.0 = 0   ; Pin goes to gnd when not Tri-Stated
    
    TRISB.0 = 0   ; Output to Ground
    ;....
    TRISB.0 = 1   ; Output Tri-Stated
    Added:
    If there's any possibility that the external 5V is higher than the PIC's 5V?
    Use PORTA.4 instead. It doesn't have the VDD voltage limit.<br>
    Last edited by Darrel Taylor; - 4th March 2008 at 23:04. Reason: RA4
    DT

  10. #10


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by TonyA View Post
    Thank you.

    Is it possible to just use a 2N2222 transistor?

    I found this schematic, however my application is a little different. (It got me thinking though):

    http://www.rentron.com/images/rely-drv.gif

    If the relay was omitted from that circuit, and since I just need to switch an incoming wire to ground via the transistor. The "switching" would be controlled by the PIC.

    Would I just connect B of the transistor to the pic pin, C to the incoming wire and E to ground?

    Then toggle the PIC pin attached to B of transistor? Would this send my "incoming wire" to ground?

    Thanks for the help.

    T

    That circuit is a basic open collector one. The trick is that since the relay has a 100 or so ohms of resistance it acts as a current limit. So you would need to replace the relay with maybe a 220 ohm resistor so that you don't blow the transistor. But like Darrel mentions, You could just use the PIC pin directly. The main reason to use the transistor would be if the switch you are replacing goes to something that has a much higher voltage than the PIC could handle, or you want to protect the PIC with the cheap transistor.

  11. #11
    Join Date
    Apr 2006
    Posts
    92


    Did you find this post helpful? Yes | No

    Default

    Darrel, and FalingTrea thanks. I was wondering about that. Thanks again.

    Tony
    Last edited by TonyA; - 5th March 2008 at 01:06.

Similar Threads

  1. HSERIN & Interupts (aka controlling PIC programs from a remote PC)
    By HankMcSpank in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 17th June 2009, 15:46
  2. Controlling stepper motor with PIC
    By The Master in forum Off Topic
    Replies: 3
    Last Post: - 1st July 2008, 11:21
  3. Controlling power to a PIC with another PIC
    By jswayze in forum Off Topic
    Replies: 3
    Last Post: - 28th May 2005, 20:44
  4. Serial Pic to Pic using HSER
    By Chadhammer in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th March 2005, 00:14
  5. Battery Backup with PIC controlling switch
    By Dwayne in forum Schematics
    Replies: 1
    Last Post: - 27th December 2003, 14:16

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts