View Full Version : PIC relays control
flipper_md
- 27th July 2007, 04:12
Hi All
I'm starting a little projet with a PIC chip, since I discovered that PIC Basic can make it easy for me ;)
I have some programming skills, but I'm very poor at selecting components, so may someone more aware of the electronical side help me?
I'm want to use a 16F84A or 16F628A (i have both actually), and If possible i want to drive some low power relays directly from the chip!?
Panasonic and Omron makes 5V, 20mAh, 250ohm relays that are close to the output power of the PIC pins, but anyone ever made it work?
I'd like a single coil latching relay, maybe the TN2-K-5V of Panason..
Next thing is how to drive it safely, knowing that I should add zener diodes somewhere to dampen the coil release.
Being a single coil latching relay, I will need two pins and so, current will flow both direction.
I would prefer a relay that changes state everytime it get a pulse, so driven by only 1 pin, but I haven't seen that anywhere.
k, enought on the relays, it's already scary long :)
ttl
Dom
paul borgmeier
- 27th July 2007, 05:43
Flipper,
Where are you? In the states you can get these (below) .. they work great using one output pin but they do not latch. I used them in testing equipment years ago and they were perfect. No zener needed, just a flyback diode across the coil. I drove mine direct from a PIC output at 5 volts since the coil resistance is 250 ohm.
http://www.radioshack.com/sm-compact-5vdc-1a-spst-reed-relay--pi-2062478.html
bill12780
- 27th July 2007, 07:48
Ok here is the deal,
You MUST use a diode across the coil of ANY relay (unless its got one built in) Its for the back EMF (colapsing magnetic field) of the coil when you un-energize it.
If your looking for a latching type of switch depending on what your doing you have lots of options. relays with NO and NC contacts (probly your best bet), scr's, Triacs etc..
If your worried about not being able to drive the coil from the PIC. You can just use a FET. The input impedence of the gate of a FET is really high and takes almost no current to turn on. Just make sure to use a series resistor in the gate circuit in case the FET ever fails (If the fet ever shorted gate to whatever it could hurt the PIC)
Oh, one other thing to consider is what your switching. If your switching AC with lots of current you will need a snubber circuit to reduce the arching on the relay contacts. I just went through this on my predesesor's motor control circuit at my work. His "new" design would fuse the contacts together about the thrid or forth time the motor started.
Well that is my two cents (probly all its worth) hope it helped. If you want to post a schematic of what your doing I would be more then happy to look it over.
Best!
Bill12780
ohararp
- 27th July 2007, 15:37
Bill, do you have a schematic or part number for this control circuit with snubber by chance?
flipper_md
- 27th July 2007, 23:32
hi folks
i'm happy to know that it's at least possible to do :)
Radio Shack has become CircuitCity around here, and they don't carry much of electronics anymore...
I will probably make an order at Digikey.
I'm looking to drive two 12v (DC) HelmetCam, who drink 130mAh approx. each.
(but it runs very hot... I wonder how it can only be taking 130...)
At first I wanted to have some kind of soft power switching, because that whole thing is plugged into a camcorder, but this sounds very complex to me so I will use Zener diode in the circuit to prevent overvoltage peak.
KIS system ;)
I need Latching because I won't be switching too often, and the circuit can run for more 6-7hours non-stop.
thanks all!
Dom
Pic_User
- 28th July 2007, 01:38
Hi Dom,
As I see it:
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1883&stc=1&d=1185582631" />
You would need a 5V relay to drive it directly.
The PIC 25mA limit would drive 200 or more coil Ohms.
Not:
Mono-stable Relay, normal relay that stays energized while a voltage is on the coil.
But:
Magnetically Latching, or Mechanical Latching Relays
Bi-stable Relay, “Latching “, usually means a pulse turns it on, a second pulse turns it off.
Single Coil Latching (1 coil latching), usually means the second pulse goes to same connection.
A single PIC I/O could give a pulse to turn it on, then later a second pulse would turn it off.
Dual Coil Latching (2 coil latching), usually means a pulse on coil A turns it on, a pulse on coil B turns it off.
This would require 2 I/O pins for control.
Here is a hook-up if you want to use a 12V relay.
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1884&stc=1&d=1185582906" />
You could also use a SCR that would latch with an impulse from a PIC I/O pin. It would be more difficult to un-latch.
-Adam-
Pic_User
- 28th July 2007, 01:53
Hi ohararp,
Bill, do you have a schematic or part number for this control circuit with snubber by chance?Here is a simplified example of a snubber for AC.
And a “fly-back” diode for DC. Note polarity.
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1885&stc=1&d=1185583580" />
-Adam-
bill12780
- 28th July 2007, 05:57
OK...
The snuber I spoke of actually is acrossed the "contacts" of the relay. You only need this if your driving an inductive load or a really high current circuit. Like say a large motor or amplifier.
the "flyback" diode is used across the "coil" of the relay (reversed biased) to stop the colapsing field in the relay coil...Not in the load. (Although if your load was a DC inductance I supose it would work there too...)
You can use a Zener to clamp the voltage if your concerned about spikes. But if your power supply is well regulated you should not have any problems swithing 130 mills. Just make sure you have good decoupling.
You could use a SCR like was mentioned. You will need to remove the source voltage to get the scr to "unlatch" or turn off. This might be a good option but would require more engineering. (transistor to remove the voltage from the Anode long enough for the SCR to turn off and slow enough that it does not trigger itself)
For the kind of current your looking at. I would use a n-channel FET. I dont really have any easy way of making a schematic for you but I will try and explain.
Take the HIGH from the pic and run it through a series resistor that will limit the current to about half the Imax of the PIC (about a 100 ohm should give you about 12mA off the top of my head) hook the resistor to the gate of the FET put the load (your camera) in the source circuit and ground the drain.
Oh...And this is assuming that your cameras run on DC. If your switching AC then you will need a triac.
By using a FET you will reduce your overall Current drain. It takes alot less current to keep a FET on then it will to hold a realy.
If you look you can find a latching Relay. I personally have never used them so am not to familar with them. But I would bet they are more expensive then using a standard realy or FET.
If you would like I will look at my schematics tommorow at work and get the actual values I used for my snubber. I think it was .01uf and 10K if I remember right but don't hold me to that.
Hope I have helped....
Bill12780
Pic_User
- 28th July 2007, 19:23
For the kind of current your looking at. I would use a n-channel FET. I dont really have any easy way of making a schematic for you but I will try and explain.
Take the HIGH from the pic and run it through a series resistor that will limit the current to about half the Imax of the PIC (about a 100 ohm should give you about 12mA off the top of my head) hook the resistor to the gate of the FET put the load (your camera) in the source circuit and ground the drain.
Hope I have helped....
Bill12780<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1886&stc=1&d=1185646520" />
5 V/100 Ohms = 50 mA
5 V/400 Ohms = 12.5 mA (half the Imax of the PIC)
flipper_md
- 28th July 2007, 21:52
Bi-stable Relay, “Latching “, usually means a pulse turns it on, a second pulse turns it off.
I would really like a relay that behave like that!
If it exist and the PIC can run it, that's what I want !!
But the spec sheets aren't very descriptive in that manner...(attached Panason TN spec)
double coils latching relays ask for 40mAh, and need 2 pins...
About FET and other electronics switcher, i'm trying to avoid tehm because they draw some power just for operating.
About Diodes, let's say I want to protect the PIC from the relay, I would use a 5V Zener?, or I need to add a safety margin? 4.5V?
Lots of Amps in the coil effect of a relay?
Thanks for all added info, i'm slowly but surely getting somewhere! 8)
Pic_User
- 29th July 2007, 03:13
Hi Dom,
I would really like a relay that behave like that!
If it exist and the PIC can run it, that's what I want !!
But the spec sheets aren't very descriptive in that manner...(attached Panason TN spec)
double coils latching relays ask for 40mAh, and need 2 pins...
About FET and other electronics switcher, i'm trying to avoid tehm because they draw some power just for operating.
About Diodes, let's say I want to protect the PIC from the relay, I would use a 5V Zener?, or I need to add a safety margin? 4.5V?
Lots of Amps in the coil effect of a relay?
Thanks for all added info, i'm slowly but surely getting somewhere! 8)from the data sheet:
Panasonic TN Relays
1 Coil latching
TN2-L-5 V
5V 20mA 250-Ohm coil
The TN2-L-5 V should work directly from standard (25mA) PIC I/O pins.
I gave incorrect / incomplete information about latching relays in a previous post.
A single coil latching relay changes state when the polarity on the coil is reversed.
+++++ Info +++++
Single coil latching relay
DC Power to coil transfers contacts.
Contacts maintain after coil power is removed.
To transfer contacts to original position, DC Power to the coil is reversed.
Contacts maintain after coil power is removed.
+++++
Coil suppression circuit:
Circuit to reduce the inductive switch off voltage peak of the relay coil (EMC protection)
The latching relay protection diode would have to allow either polarity.
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1889&stc=1&d=1185674954" />
Then your PIC would Make I/O A high and I/O B low or I/O B high and I/O A low, to latch or unlatch the relay.
We should mention that using the transistor in place of the relay does not use very much battery power.
But, the PIC has to remain in control of the pin driving the transistor.
I would consider using a logic level CMOS power transistor.
-Adam-
bill12780
- 29th July 2007, 18:23
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1886&stc=1&d=1185646520" />
5 V/100 Ohms = 50 mA
5 V/400 Ohms = 12.5 mA (half the Imax of the PIC)
oops....Sorry....it was late when I posted that. I think I was going for the four(4) key on the keypad and fat fingered it to the one(1) right below it.
(I mean 5/.0125 is easy math I do in my head all the time...had to be a typo...cant belive I was that tired! hahaha!)
Pic_user...You obviously have WAY more experience with this.
I will yield to your expertise here and bow out. I just thought that I could return the favor for all the help that I get here.
Thanks for correcting that.
Bill12780
Pic_User
- 29th July 2007, 21:20
Hey Bill,
I do exactly the same thing with resistors. I think in current, and sometimes go down in resistance value, to lower the current, oops. I also say “bigger resistor” when I mean a bigger current, oops. We all do that type of mis-speak, don’t worry about that.
You are more than welcome, to discuss alternate ways to do things. There is usually more that one way to solve electronics problems. Just as there is more than one way to program an algorithm. The fun of the forum is the multiple solutions discussed. Let the user decide which way they want to go. Or let their electronic junk-box decide for them. Please, always put your ideas into any thread that you want to help with. Your electronics experience is of great value.
I posted that CMOS schematic from your description. You had said you didn’t really have any easy way of making a schematic. If you look for a drawing program called “paint.NET” it is free and way ahead of MSPaint.
We are all in this together,
-Adam-
bill12780
- 30th July 2007, 00:52
Thanks Adam,
I appreciate your kind words of encouragement.
I just kinda felt like a dumb A** if you know what I mean. I feel like a leach around here most of the time because I am still very new to the PBP and the digital world in general. always asking question that I am sure to some are so elemetry they are bored to tears! I have not had to use it this sort of thing much in my career. Hence...Ignorance...
I will spout-off when I think I can help. But PLEASE if I am wrong just swat me on the nose with a rolled up newspaper!
Maybe one day I can actually be of some help! hahahaha
Thanks for the tip on the proggie...I will check it out. If I was at my work I would have just slapped something together in Eagle really fast. But I have never download it here at home.
Thanks again! (I need to program an F-key for that line)
Bill12780
flipper_md
- 30th July 2007, 02:31
thanks Gentlemen
all of this end up being very constructive for me, and now I just need to set my mind on what parts I will order to get things started!
My programmer is dead anyways, I've got plenty of time till the new one comes back :p
the double way diode, that's pretty funky stuff!
I'm using DesignWorks Lite for schematics, and it's pretty good for me so far...
flipper_md
- 30th September 2007, 16:37
just a little follow up on this
Finally ,I had to order 4.5V relays cuz order 5V we're not stock.
By time things arrived, I spoke with a few people and one told me that some relays were designed to be driven by IC, without anything special requd for protection.
I then decided to give it a chance, and it work! First without a bi-color LED on the pins of the coil, but this would take to much power and only the led would light up.
Removed the led, relay started switching, and kept going :)
since then I've being debugging/coding for a while, and no problem to report, for the relay.
Coding is another challenge ;)
relays PN is AGN2104H
Pic_User
- 1st October 2007, 16:08
just a little follow up on this
Finally ,I had to order 4.5V relays cuz order 5V we're not stock.
By time things arrived, I spoke with a few people and one told me that some relays were designed to be driven by IC, without anything special requd for protection.
I then decided to give it a chance, and it work! First without a bi-color LED on the pins of the coil, but this would take to much power and only the led would light up.
Removed the led, relay started switching, and kept going :)
since then I've being debugging/coding for a while, and no problem to report, for the relay.
Coding is another challenge ;)
relays PN is AGN2104H
Hi Dom,
Glad to hear you are making headway. Thank you for the follow-up information. We are all on the learning curve of life.:)
It is good to get technical advice from knowledgeable people.
Always double check information, at least till you find out which information sources are reliable.
Always read the data sheet.
Always “do your home work” with the technical briefs.
AGN2104H Relay
4.5V nominal 6.75V maximum
If you look at the AGN2104H data sheet:
http://pewa.panasonic.com/pcsd/product/sign/pdf_cat/gn.pdf
For Cautions for Use, see “Relay Technical Information”.
That brings us to here:
Relay Technical Information (PDF:400KB)
http://pewa.panasonic.com/pcsd/product/re/rti.pdf
Countermeasures for surge voltage of relay control transistor
If the coil current is suddenly interrupted, a sudden high voltage pulse is developed in the coil. If this voltage exceeds the voltage resistance of the transistor, the transistor will be degraded, and this will lead to damage. It is absolutely necessary to connect a diode in the circuit as a means of preventing damage from the counter EMF.
In the Technical Brief, they are assuming you are driving the relay with a discrete transistor. If you are driving from a PIC then the “transistor” is really inside the PIC. The same precautions apply.
Hope this helps,
-Adam-
flipper_md
- 2nd October 2007, 03:40
Thanks much for the check Adam!
I admit I'm a bit lazy at reading tech stuff, and I kinda trust a lot electonic components, just like mechanical parts :)
I fear only things when they start to smell weird, burn my fingers or don't light up anymore.
Further more, i'm not skilled at welding so less means better!
I understand I might be hurting the poor PIC now, but I'm just so curious to see how long he will take it that I can't get myself to puts some diodes in.
By caution I measured the peak voltage on my fluke(112), it says 3.3V peak after a couples switch, but is that reliable? The FLuke alone may buffer the voltage?
those tiny processor are heck of fun to play with, it's never ending!
... if I had a girlfriend, she d probably wish to be a PIC 8)
Kalind
- 1st October 2008, 15:19
I need to know how to write the code to switch on/off a relay when a temperature setpoint is reached. The output pin im using is RC1 of a 16f873. Please, someone help me!!
skimask
- 1st October 2008, 15:22
I need to know how to write the code to switch on/off a relay when a temperature setpoint is reached. The output pin im using is RC1 of a 16f873. Please, someone help me!!
main:
if temp > setpoint then
portc.1 = 1
else
portc.0 = 0
endif
goto main
You write code by typing at the keyboard.
earltyso
- 1st October 2008, 16:03
I have been using the OMRON G3MB-202PL DC5 solid state relay for my AC christmas lights controller. They only pull ~15mA (input impedance is 440ohms +/- 20%) and work great for switching. The voltage input is 4-6V for on. I drive them directly from my pics and have had no problems. I can tell you that it is a GREAT idea to include fuses in your circuit when you use these if you are planning on large loads 1A+. The best part is that the snubber is built right in the SIP package. They go for 4-5.50 from DIGIKEY part #Z915.
From this forum I learned how to hold the state on or off with a simple counter.
I use this to
main:
if button = 0 then
i = i +1
'blah blah
endif
gosub choice
goto main
choice:
if i.0 = 0 then
high relay1
endif
if i.0 = 1 then
low relay1
endif
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.