PIC 16F628 & relay

Thread Starter

nerdegutta

Joined Dec 15, 2009
2,684
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:
Rich (BB code):
Part     Value          Device          Package      Library    Sheet

C1       0.1uF          C-EU050-024X044 C050-024X044 rcl        1
C2       100uF          CPOL-EUE2.5-5   E2,5-5       rcl        1
C3       100uF          CPOL-EUE2.5-5   E2,5-5       rcl        1
C4       0.1uF          C-EU050-024X044 C050-024X044 rcl        1
C5       0.1uF          C-EU050-024X044 C050-024X044 rcl        1
D1       1N4148DO35-7   1N4148DO35-7    DO35-7       diode      1
IC1      78L05Z         78L05Z          TO92         linear     1
IC2      PIC 16F628     DIL18           DIL18        ic-package 1
JP1      12vDC          PINHD-1X2       1X02         pinhead    1
JP2      ICSP           PINHD-1X5       1X05         pinhead    1
JP3      BTN 1          PINHD-1X2       1X02         pinhead    1
JP4      BTN 2          PINHD-1X2       1X02         pinhead    1
JP5      BTN 3          PINHD-1X2       1X02         pinhead    1
JP6      BTN 4          PINHD-1X2       1X02         pinhead    1
JP7                     PINHD-1X2       1X02         pinhead    1
K1       4052           4052            F4052        relay      1
QF1      12M10AHC49HT   12M10AHC49HT    HC49U        crystal    1
R1       12K            R-EU_0207/7     0207/7       rcl        1
R2       10K            R-EU_0207/7     0207/7       rcl        1
R3       10K            R-EU_0207/7     0207/7       rcl        1
R4       10K            R-EU_0207/7     0207/7       rcl        1
R5       10K            R-EU_0207/7     0207/7       rcl        1
R6       100R           R-EU_0207/7     0207/7       rcl        1
T1       BD139          BD139           TO126        transistor 1
TP1      TPPAD1-20Y     TPPAD1-20Y      P1-20Y       testpad    1
Thanks for reading.
 

Attachments

Markd77

Joined Sep 7, 2009
2,806
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.
 

ErnieM

Joined Apr 24, 2011
8,377
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.
 

Thread Starter

nerdegutta

Joined Dec 15, 2009
2,684
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.


Yep base resistor is too low... 1K will ensure its fully on
http://www.arduino.cc/playground/uploads/Main/relays.pdf
I've tried with different resistor values. Same thing.

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.
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:


I've not tried this:


Could that be a better solution? With a 2N2222 and a BD238.
 

Attachments

Last edited:

mcgyvr

Joined Oct 15, 2009
5,394
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.
 

ErnieM

Joined Apr 24, 2011
8,377
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.

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?
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."
 

Thread Starter

nerdegutta

Joined Dec 15, 2009
2,684
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.
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.

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.
I got a bunch of 2N2222 and BC547, and some BD135/139.

If you are changing the circuit before you have confirmed it doesn't work you are in panic mode.
Not yet. But eventually I'll guess I'll get there...:eek:
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."
I'll measure the voltage later today, and go over all the wiring again.

Thanks.
 

Thread Starter

nerdegutta

Joined Dec 15, 2009
2,684
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.
 

ErnieM

Joined Apr 24, 2011
8,377
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.
 
Top