PIC 16F628 & relay

Discussion in 'Embedded Systems and Microcontrollers' started by nerdegutta, Jun 13, 2012.

  1. nerdegutta

    Thread Starter Moderator

    Dec 15, 2009
    2,515
    785
    My goal is to light two 12v 21w light bulbs with a relay, but the relay is just clicking.

    The thought is that when RB0 is HIGH, the NPN BD139 turns on and energize the relay. This doesn't happen. It's just clicking, like it's not getting enough current. The relay is a Finder, type 40.52, 12v 8A. When I measure the coil, the DMM reads 216 Ohms. I've also tried to alter the software so I can use the PNP BD238, but same thing happens. Thinking that it would be better to sink the transistor that to source it.

    It works great on the breadboard with LEDs, but when I switch the LEDs with a relay - clicking...

    I'm using a 12v car battery as a power supply.

    I've also tried with a IRL 2703, but nothing.

    The input block is push buttons. Different button, different HIGH time on RB0, but not less than 1 sec.

    I guess there is an obvious reason for this, but I'm stuck.:(

    Partlist:
    Code ( (Unknown Language)):
    1.  
    2. Part     Value          Device          Package      Library    Sheet
    3.  
    4. C1       0.1uF          C-EU050-024X044 C050-024X044 rcl        1
    5. C2       100uF          CPOL-EUE2.5-5   E2,5-5       rcl        1
    6. C3       100uF          CPOL-EUE2.5-5   E2,5-5       rcl        1
    7. C4       0.1uF          C-EU050-024X044 C050-024X044 rcl        1
    8. C5       0.1uF          C-EU050-024X044 C050-024X044 rcl        1
    9. D1       1N4148DO35-7   1N4148DO35-7    DO35-7       diode      1
    10. IC1      78L05Z         78L05Z          TO92         linear     1
    11. IC2      PIC 16F628     DIL18           DIL18        ic-package 1
    12. JP1      12vDC          PINHD-1X2       1X02         pinhead    1
    13. JP2      ICSP           PINHD-1X5       1X05         pinhead    1
    14. JP3      BTN 1          PINHD-1X2       1X02         pinhead    1
    15. JP4      BTN 2          PINHD-1X2       1X02         pinhead    1
    16. JP5      BTN 3          PINHD-1X2       1X02         pinhead    1
    17. JP6      BTN 4          PINHD-1X2       1X02         pinhead    1
    18. JP7                     PINHD-1X2       1X02         pinhead    1
    19. K1       4052           4052            F4052        relay      1
    20. QF1      12M10AHC49HT   12M10AHC49HT    HC49U        crystal    1
    21. R1       12K            R-EU_0207/7     0207/7       rcl        1
    22. R2       10K            R-EU_0207/7     0207/7       rcl        1
    23. R3       10K            R-EU_0207/7     0207/7       rcl        1
    24. R4       10K            R-EU_0207/7     0207/7       rcl        1
    25. R5       10K            R-EU_0207/7     0207/7       rcl        1
    26. R6       100R           R-EU_0207/7     0207/7       rcl        1
    27. T1       BD139          BD139           TO126        transistor 1
    28. TP1      TPPAD1-20Y     TPPAD1-20Y      P1-20Y       testpad    1
    29.  
    Thanks for reading.
     
  2. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Probably won't make much difference, but 100 ohms is a bit low for the base resistor, it should be around 300 ohms to get the current out of the pin within specification. The coil only needs 40mA so you should be able to get away with as low as 4mA base current.
     
  3. mcgyvr

    AAC Fanatic!

    Oct 15, 2009
    4,769
    969
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Does the voltage across the coil read 12V? Can your supply drive the relay by itself?

    Also, according to your schematic the only purpose for the relay is to short out the power supply.

    Typically, a "click" indicated a change of state, or an on/off action. Otherwise a relay is usually quiet, might buzz but probably not.
     
  5. nerdegutta

    Thread Starter Moderator

    Dec 15, 2009
    2,515
    785


    I've tried with different resistor values. Same thing.

    Yes, the power supply can drive the relay by itself.
    Haven't measured the coil voltage - yet.

    I'll double check my schematic against the breadboard - but it should be the same. Could that cause my problems?

    I'm trying to make a circuit close to this:
    [​IMG]

    I've not tried this:
    [​IMG]

    Could that be a better solution? With a 2N2222 and a BD238.
     
    Last edited: Jun 14, 2012
  6. mcgyvr

    AAC Fanatic!

    Oct 15, 2009
    4,769
    969
    does the relay just click once when you set that pin high? and are you sure its not switching states when that happens? (ie..continuity change from C-NC to C-NO)

    A click from a relay "typically" means it switched states..

    have you tried a different relay? many times relay contacts "stick" if they are bad.
    forget about the micro and just apply 12v to the coil and see if it even works.

    then try replacing the relay with an LED/resistor in your circuit and see if it turns on then.
     
  7. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    At 12V / 216 ohms = 56 mA of current per relay it really doesn't matter how you drive them, that's a light load for a transistor. So use the scheme from your "I'm trying to make a circuit close to this:" schematic with a single transistor.

    Just about any NPN transistor will work here. Even if you went ennie-meanie-miney-moe in a parts draw you stand almost a 100% change of picking a good transistor as long as it is NPN.

    If you are changing the circuit before you have confirmed it doesn't work you are in panic mode. Relay, have a martini and a day off then return to the task. Measuring that voltage is what will tell you the relay is being driven on correctly, and an ohmmeter across the contact pins tells you it moved.

    Your breadboard and schematic should match completely, except for any penciled in revisions you make along the way.

    "If it isn't written down it did not happen."
     
  8. nerdegutta

    Thread Starter Moderator

    Dec 15, 2009
    2,515
    785
    I've tried 3 different types of relays.

    It's like: click-click-click-click.

    When I forget about the micro; one click and the light bulb lights up. Just as I want it to to.

    I got a bunch of 2N2222 and BC547, and some BD135/139.

    Not yet. But eventually I'll guess I'll get there...:eek:
    I'll measure the voltage later today, and go over all the wiring again.

    Thanks.
     
  9. nerdegutta

    Thread Starter Moderator

    Dec 15, 2009
    2,515
    785
    Got it working. :D

    This is what I did:

    Changed the diode D1 to 1N4007
    Changed the transistor T1 BD139 to PN2222
    Changed the resistor R6 to 820 Ohm

    Thanks for your time.
     
  10. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Awesome, congratulations on a job well done. :D

    Posting what you did to fix it always helps if someone else reads your thread for help on their problem. The only thing is I don't see how any of these things would help. Changing the resistor may be it if it was drawing so much current it was resetting the micro, but that would take putting the bad value in and checking with an oscilloscope to see.
     
    nerdegutta likes this.
Loading...