Switching a relay with an AVR

Go To Last Post
49 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I know there are already a lot of topics relating to this, but I am a bit lost with what it all means. My knowledge is pretty limited and I was hoping someone can explain what I need in simple terms. As you will see from my questions, I don't know a lot about electronics.

I am using an Atmega16 and I need to switch a relay that has a coil with the following specs:-
Nominal Voltage - 5VDC
Resistance - 27ohms
Nominal Power - 930mW
Nominal Current - 185mA
I will be switching 240VAC with this relay. I am using a 5V regulated supply to power the Atmega16 so I was hoping to use the same power supply to switch the relay. But I have read about it being unwise to do this. So how do I get around this? I want to use the least amount of components as possible, would I really need to have 2 seperate regulated power supplies?

Now to switch the relay I was considering using a 4N28 optoisolator and a TIP115 transistor as I already have some of these. Would this combination be suitable? Or can someone suggest something better? With regards to the circuit, do I connect VCC to the Emitter and put the relay coil between the Collector and GND? I have some 1N4001 diodes, would one of these across the coil be required? Would I then connect the Base straight to pin 5 of the 4N28 with pin 4 to ground? I wouldn't mind lighting an LED as well, how would I work that into the circuit?

Any advice will be greatly appreciated. Thanks in advance.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Don't bother with the opto. That is not a good choice. I would choose a FET because it is so easy to drive, but you can use an NPN bipolar.

If its NPN, ground the emitter. Drive the base from a port pin. The relay coil current will be 5V/27ohms or the 185ma quoted. To saturate the transistor, you need 18ma of base current and you will just get that from a straight port pin, no series resistor.

The relay goes between the 5V supply and the collector of the transistor. Do NOT for get to add a diode (say 1N4000 series) across the coil as a transient suppressor, cathode to +5V.

Logic high on the port pin turns on the relay.

Make sure that you have the 240V AC well away from the micro. You are liable to have switching noise problems. Bypass the positive supply of the micro VERY well, especially right AT the socket.

You may also have problems with the 185ma of coil current. Make sure that the emitter of the switching transistor is routed directly to the power supply terminal and not just randomly connected to some local ground plane.
Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the super fast reply Jim, I think I understand most of what you are saying. Can you suggest a specific FET or NPN bipolar? I don't know much about them.

When you say

Quote:
Bypass the positive supply of the micro VERY well,
I am not sure how I do that. Can I do all of this from the one regulated power supply? Really appreciate the help.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Relays are tolerant of power supply variations - thus usually don't require a regulated supply. If your unregulated supply is 12V, use a 12Vrelays - they're probably cheaper and they will draw less current, thus keeping your 5V regulator cool.

The led and its resistor can be wired in parallel to the relay coil. some relays even have this built in.

As for suggested transistors - 2N2222, BD139,BC639

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Kartman, the 12V relays are a touch cheaper, but I was using a 6.3V - 500ma transformer as I can get them cheap. I can get another transformer for a little more that is 12.6V CT @ 1.9VA. Do you think this would supply enough current? Sorry for the stupid questions, I just don't have a very good understanding of this.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
you need 18ma of base current and you will just get that from a straight port pin, no series resistor.

Do not follow this advice.
You must put a resistor in the base drive circuit if using a transistor. The base voltage is clamped via the base emitter junction to 0.63-0.7v. Any attempted to drive the junction with an unregulated (current) at 5 volts will release nasty smell.
With a FET you do not require a resistor in the gate circuit.

Keep it simple it will not bite as hard

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
you need 18ma of base current and you will just get that from a straight port pin, no series resistor.

I don´t recommend this.

You overdrive the port and maybe also the base of the transistor.

Without lookoing into the datasheet:
I´d say the AVR output about 4.5V with 18mA.
he transistor´s base will be at about 0.6V.

So the resistor has to be (4.5-0.6)/0.018 = 217 Ohms --> use 220 Ohms.

Klaus
********************************
Look at: www.megausb.de (German)
********************************

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Or if you have a lot of relays to drive you get a relay driver chip which are way easy to work with I know there are several made out there.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Quote:
Bypass the positive supply of the micro VERY well,

I am not sure how I do that. Can I do all of this from the one regulated power supply? Really appreciate the help.

Bypassing means you need to put a capacitor to (in this case) +5V and GND. To eliminate voltage drops/peaks that could reset the processor. A 100n ceramic cap very close to the power pin of the processor (as close as possible, preferably smd), and a big electrolyt somewhere in the power supply.

Tell us the parameters of the regulated supply. But I think you can. If you'd ever needed to use more relays at one, I'd advise you not to bother with transistors, but use ULN2803A or similar roaches. (just google it). You don't have to use anything with them (no estra parts).

There are pointy haired bald people.
Time flies when you have a bad prescaler selected.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Can someone tell me how driving a transistor base is different from driving a LED? Forward drop of LED is higher, yes, but the port pins are current limited for LED driving and they should work just fine for transistor base.

With a transistor collector load of 185ma, the transistor needs to be driven hard to get it to saturate. In fact, it will need about 18ma of base current. That is not much below the natural port pin current limit, and the transistor will have no problem with a little extra base current if it will really handle 185ma of collector current. Switching speed should NOT be an issue with a relay; that is about the only thing that would suffer.

All that said, a FET would be much easier and the port pin would be much happier. Choose one based on steady-state drain current rating AND gate threshold rating (a "logic" device would be preferred); With a 5V processor supply, the FET gate threshold should be no larger than 3V.

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ka7ehk: Also the FET would require one less part: No resistor on its 'base' : gate. That is unless you plan to switch the relay at high frequencies ;-)

There are pointy haired bald people.
Time flies when you have a bad prescaler selected.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Actually the atmega cpu port pins can drive as much as 40ma. The spec limits the TOTAL output for ALL ports at 400ma, and the output for any one PORT (all 8 pins) at 200ma. Vo will drop as the Io increases, so there is a limit here. The ports will SINK more current than they can SOURCE as the current comes from 'elsewhere'.

Spec's on the 2n2222 show a min hfe of 100 at a collector current of 150ma, so the 18ma base drive is in the ballpark. A small resistor in series with the base won't hurt, and it may increase the switching speed (don't think the relay cares). The protection diode is necessary to keep the back emf from the relay coil (when it shuts off) from blowing through the collector-base junction. the diode can go across the coil (cathode to +5 volts) or from the collector of the transistor to ground (cathode to the collector).
Or use two diodes.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What a second....beta of 100 and output current of 185ma... I think the base drive would be more like 1.8-3 ma here.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So you think we should start using the newfangled FETs that have only been around for 20 years instead of the old fashioned transisitors that have been around for 50 years?

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Actually the first on paper design for a transistor was actually a fet! Practical (working) fets didn't arrive until after point contact and bipolar transistors were perfected.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks everyone, I think I get the general idea now :D

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, a 2N2222 has a beta of 100 at 200ma. Problem is, that is when it is not saturated. To get the forward drop down, and hence power dissipation, you have to drive it hard into saturation. As it goes into saturation, the beta drops. The conventional guideline is to drive it until the beta drops to 10. Hence, 18ma of base current for 185ma of collector current, saturated.

This used to be standard fare in circuit design classes, pre-FET. Guess the academics have forgotten about such stuff. Ouch, I am one of those academics, some times.

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm not sure how to determine the drive point from the published specs, but it makes sense. BTW, it's also possible to drive the relay using a PNP transistor with the collector grounded and the relay in the emiter lead (emiter follower), but now a zero output switches on the transistor)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Actually the atmega cpu port pins can drive as much as 40ma. The spec limits the TOTAL output for ALL ports at 400ma, and the output for any one PORT (all 8 pins) at 200ma. Vo will drop as the Io increases, so there is a limit here. The ports will SINK more current than they can SOURCE as the current comes from 'elsewhere'.

I wouldn't advise using a avr port in parallel to switch a relay. The problem is that a relay is an induction. You'd need to add clamp (limiting, i don't know the right word, protection) diodes anyway, so in the end you'd have just as many parts.
If you switch an induction and then switch it off, you get a VERY high voltage on the coil, which CAN be a problem.

Quote:
So you think we should start using the newfangled FETs that have only been around for 20 years instead of the old fashioned transisitors that have been around for 50 years?

Well, maybe he should use a mercury arc rectifier, or a thyratron! They've been around from the very dawn of electronics ;-) ... or some other valves.

If you need a tranzistor with a high beta (h21e) you might wanna try a darlington tranzistor (BC517, smd BC817). beta = cca 10000.

There are pointy haired bald people.
Time flies when you have a bad prescaler selected.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For some applications, a Darlington is nice. They are not so good in saturated applications as you have too much Vce and more transistor power dissipation than you might like. If that really is an issue in this kind of application, a FET is a much better choice.

If you are going to use a PNP, then just turn everything up side down, and still keep the relay between the collector and its supply (now, ground). Operating a PNP as suggested is just an emitter follower and you will only get 4.3 across the relay coil, not 5V; in that case, at best, it would be marginal, and at worst, the relay might not pull in.

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@ka7ehk

Quote:
Can someone tell me how driving a transistor base is different from driving a LED? Forward drop of LED is higher, yes, but the port pins are current limited for LED driving and they should work just fine for transistor base.

I don´t know of what AVR you speak. Next to me there is the M128 datasheet. So I take a look at it:
In the "Absolute maximum ratings" section there is a DC current per IO pin given of 40.0 mA.
But this is NOT limited by the AVR. You have to take care of it.
So i look into the chart "I/O pin source current vs. output voltage"
The transistor base (without additional resistor) limits the output voltage to 0.6V up to maybe 0.75V
(I didn´t look into the 2N2222 datasheet)
The chart shows at VCC=5V and Vout = 3V an output current of 65mA !!!
The chart doesn´t show the value of 0.7V. I estimate it to about 110mA.

The limit of 40mA is at about 4.1V.

So in my eyes you definitely have to use a current limiting resistor.

the min. resistor not to run out of specification is:
(4.1V - 0.7V) / 0.04 A = 85R

One way to limit the IO current is to use the internal Pullup resistor. But the output currrent is only some 10s of uA.
Not enough to drive this transistor with 185mA load.

To save part count you can use so called "digital transistors" with built in base resistor.
"MMUNxxxxx", "PDTAxxx" or "PDTCxxx" or a FET.
The benifit of the FET is a usually lower dropout voltage (depends on type) and lower drive current.

The benifit of the digital transistors is the (often) built in pulldown resistor. When the AVR is in RESET state, the IOs are high impedance. With a FET one can not predict it´s output state. The digital transistors are allways OFF.

When using SOT23 types you can assemble FETs as well as transistors.

Klaus
********************************
Look at: www.megausb.de (German)
********************************

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Even when driving fet's isn't it a good idea to include a series resistor for noise reduction?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Even when driving fet's isn't it a good idea to include a series resistor for noise reduction?

Yes, you can use relatively high impedance resistors (>1kOhm) for slew rate limiting. (= lower noise)
The miller_capacitance of FETs make an about constsnt voltage rise/fall independent of load.

With high power applications a low impedance resistor (some Ohms) is recommended to avoid ringing while
getting high slew rate. With high power one wants high slew rate to get low switching loss within the FETs.

Klaus
********************************
Look at: www.megausb.de (German)
********************************

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I appreciate all of the input on this, but I don't really understand a lot of what is being said. I sort of understand how a transistor works, but obviously not well enough to know what all of the specs mean.

I have decided to go with a relay with a 12VDC coil now. The 12V coil has a resistance of 160ohm. My plan is to use a 12V transformer, pass it through a 5V regulator to power the AVR and LCD etc, and use the unregulated 12V to switch the relay. I have some 2N2222 transistors already so I was going to try and use them to begin with. Is it OK to connect the base of the transistor to the AVR with a series resistor, and have 12V passing through the collector/emitter to power the coil?

If it is better to use a FET I can get some MTP3055E. Reading the datasheet I think these would be suitable, not that I know much about what the specs mean. So would my circuit use the FET the same as using the transistor? ie, ground the drain and put the relay between 12V and the source? What size resistor should I use from the AVR IO to the gate? Hopefully I'll leave you all alone after this.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Is it OK to connect the base of the transistor to the AVR with a series resistor, and have 12V passing through the collector/emitter to power the coil?

Yes it is but you should fit a diode across the coil. This is fitted with the anode of the diode to the collector of the switching transistor and the cathode to the 12v side.

When the relay is switched off the magnetic field collapses generating a large voltage in the coil. This voltage is in reverse to the energising voltage that has just been switched off. The diode prevents this large voltage spike trashing the driving transistor, and possible disruption to other nearby electronic components. With this you are taking first steps into the wonderfull world of Electro Magnetic Interferance.
Have fun

Keep it simple it will not bite as hard

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
So would my circuit use the FET the same as using the transistor? ie, ground the drain and put the relay between 12V and the source?

NO. If it is an N-Channel FET you have to ground the SOURCE and connect the relay between 12V and DRAIN.

I can´t say if a transistor or a FET is better. It depends on price, power requirements, switching loss and a lot others....

3055 sound like a big one - a small one would do it also. VCC = a lot over 12V (>=20V), RDS-ON <5Ohms, VG-TH < 2.5V, ID > 200mA.
like the FDV303N.
Resistor: with ah FET you can use the internal pullup. Or use an external one >=1kOhms.
Again: Use an additional pulldown if you need the relay to OFF during AVR Reset.

Transistor. A BC556 (is it NPN?) or something similar does the job. R about 200 Ohms if VCC = 5V.

Klaus
********************************
Look at: www.megausb.de (German)
********************************

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks everyone for your help, I got it all working with a 12VDC relay, a 2n222 transistor and 220ohm resistor to base. I didn't forget the diode either. :D

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
I have decided to go with a relay with a 12VDC coil now. The 12V coil has a resistance of 160ohm. My plan is to use a 12V transformer, pass it through a 5V regulator to power the AVR and LCD etc, and use the unregulated 12V to switch the relay.

Well, transformers rated for 12 give a little higher voltages, but it's ok, since it's not a voltage sensitive device. Ofcourse, you have to rectify the voltage and also filter it out with a cap.
Your power suply might be like this:

                                     +12V to relays
                                        |
Transformer->rectifier->filtration cap--+-->voltage reg.---> cap-->+5V for the rest

There are pointy haired bald people.
Time flies when you have a bad prescaler selected.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hmmm, that was like reading some books from my childhood :-)

This board is definately great fun. But back to the track, why not using one of those logic-FETs including an avalanche diode and be happy without adding any addtional parts? I mean, these logic-gates include some pull-up or pull-down resistors too, and therefore guarantee the setup behaviour.

And additionally, why blowing ~20mA through a transistor base in a power controller? It only should control the power it shouldn't waste it, what will also ease up the power supply design for this thing. Smaller Caps, less EMI, whatever.

Ulrich

best regards

Ulrich
-------------------------->>> connecting to car mains means connecting to the power supply from hell....

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

daqq wrote:

Well, transformers rated for 12 give a little higher voltages, but it's ok, since it's not a voltage sensitive device. Ofcourse, you have to rectify the voltage and also filter it out with a cap.
Your power suply might be like this:

                                     +12V to relays
                                        |
Transformer->rectifier->filtration cap--+-->voltage reg.---> cap-->+5V for the rest

Yep, thats exactly what I have. Thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

uprinz wrote:
Hmmm, that was like reading some books from my childhood :-)
Ulrich

That's about the level of my understanding, childhood :P

I am just working with components I have or can get easy at the moment and the transistor is working for me. If things start to go wrong I'll look at some FET's as suggested.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I would not concider looking at FETs, if things go wrong, as some sort of wonder cure. A transistor is more than adiquate for this job and I would also expect cheaper. So long as you have the diode across the relay coil then I would expect no problems. Also an advantage of the transistor is that when the output of the Mega is floating the transistor will be off as there should be no current to drive the base.

Keep it simple it will not bite as hard

Last Edited: Fri. Dec 22, 2006 - 01:11 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
why not using one of those logic-FETs including an avalanche diode and be happy without adding any addtional parts? I mean, these logic-gates include some pull-up or pull-down resistors too, and therefore guarantee the setup behaviour.

Do you have partnumbers by the hand?

Klaus
********************************
Look at: www.megausb.de (German)
********************************

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi!

Partnumbers...
Ok, if you'd like to select pull-up or pull-down resistor yourself, then try farnell.com and search for 'logic fet' and you get results like BSS138N from Infineon or IRLML240x or IRLML280x from International Rectifier.
Former Philips Semiconductor, now NXP.com has such parts too, but they include the pull-up/-donws. Just have a look at their page, I didn't use them as I needed to select the pull-up/-downs myself.

There are also some solid-state relais including zero crossing detector for AC switching. But I think that is to expensive and may be oversized. These parts are controlled like any Optocoupler so the AVR only needs to drive an LED. But that's only to complete the list of possible solutions for your problem.

I use the BSS138 for driving high-speed / high-power opto-fet-drivers to PWM control 20V/15A Testframes for automotive lamps. They work stable.

Ah, and don't misunderstand me, you don't have to order at farnell as they seem not to love small ordering from private persons, but they have a good database for searching and you can order most standard parts at your local dealer round the corner.

Ulrich

best regards

Ulrich
-------------------------->>> connecting to car mains means connecting to the power supply from hell....

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why not just use a ULN2003/2803. Diodes inbuilt so the whole operation becomes a no brainer. And you've got drive for 7[8] relays. Just got to watch that you don't try to pull too much current from them. The average relay pulls around 40-80mA at 12V so well within the specs. Job done.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well I have gone a lot further with my project and thought all was good until a friend was using it to switch a 240V solenoid valve and I have had all sorts of problems. I am obviously getting some bad feedback from the device being switched.

The circuit runs forever just switching the relay or something of low power, the problems occur when the relay is switching the solenoid. I am waiting to get it back from my friend but it sounds like the flash memory has been corrupted too as he says the program no longer runs properly.

This is my power supply which is powered from a 12.6VAC 150ma transformer, the C3 cap is mounted right next to the AVR VCC and GND.

and this is the relay section

I have added a MOV to the mains supply but that made no difference. Just wondering if anyone can point out some major error.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

is the problem when the relay is closing or opening?

If opening: Try a suitable varistor across the relay´s switch.

Your relay-section: Isn´t the LED the other way round?

12.6V AC may give you 16.5V after rectifying, even more if load is below 150mA. Check the voltage.

Is your relay rated for isolating voltage 240V (switch to coil)
How much minimum spacing(layout) do you have between 240V and 5V/12V?

Klaus
********************************
Look at: www.megausb.de (German)
********************************

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Klaus is right on as usual. I would add: Check your GND routing. Make sure the relay return current is not going near your micro.

Go electric!
Happy electric car owner / builder

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

MegaUSBFreak wrote:
Hi,

is the problem when the relay is closing or opening?

If opening: Try a suitable varistor across the relay´s switch.


I think the problem occured when it is switching the power off, so that would be when it is opening? I will try a varistor across the relay switch. You do mean across the 240V part of the relay, not the coil? I have put one at the beginning of the mains supply, would I need 2, or move it to the relay? There is a possibility of other high load devices being plugged into the same power outlet as my device.

MegaUSBFreak wrote:

Your relay-section: Isn´t the LED the other way round?

Am I showing the LED the wrong way around? :oops: I am pretty sure I wired it the right way around. The long leg of the LED is connected to the +12 and the short leg to the resistor.

MegaUSBFreak wrote:

12.6V AC may give you 16.5V after rectifying, even more if load is below 150mA. Check the voltage.

I did check the voltage and it is supplying around 15V to the relay coil when it is switched on. That is just within the coil specs but I am going to add a zener to reduce that. I am also adding a heatsink to the 7805.

MegaUSBFreak wrote:

Is your relay rated for isolating voltage 240V (switch to coil)

I sure hope so. I can't see anywhere in it's specifications where it says. It is suitable for switching 240V @ 40A.

MegaUSBFreak wrote:

How much minimum spacing(layout) do you have between 240V and 5V/12V?

Initially the 240V was running too close to my LCD but I changed it. The closest 240V is about 15mm from the 5V/12V. In future I am going to move the 240V relay completely off the board and have about 15cm of twisted wires to the coil. Should this help?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sgomes wrote:
Klaus is right on as usual. I would add: Check your GND routing. Make sure the relay return current is not going near your micro.

I think I have done everything wrong with my pcb design. It is my first attempt and I had no idea there were so many things to consider.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

daqq wrote:
Well, transformers rated for 12 give a little higher voltages...

For full wave center tapped rectification:
(VAC transformer - forward diode drop) x 1.414 = (12 - 0.65) x 1.414 = 16.876DC peak.

or:

For full wave bridige rectification:
(VAC transformer - sum of the forward diode drops) x 1.414 = (12 - 1.3) x 1.414 = 15.1298DC peak.

So, for a transformer that that has a rectifier and a capacitor, the capacitor will charge to the peak voltage of the transformer, minus the sum of the diode drops in the rectifier.

You can avoid reality, for a while.  But you can't avoid the consequences of reality! - C.W. Livingston

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Taipan wrote:
This is my power supply which is powered from a 12.6VAC 150ma transformer, the C3 cap is mounted right next to the AVR VCC and GND.

and this is the relay section

I have been known to put the LED in the base of the transistor, saving the use of one resistor.

You can also put the LED in the emitter circuit and gain a little noise immunity. The catch here is that, the relay must operate using 20mA or less.

You can avoid reality, for a while.  But you can't avoid the consequences of reality! - C.W. Livingston

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

...and don't forget a snubber circuit across the relay contacts as you are switching mains especcially if you are switching inductive loads like a motor.

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:
...and don't forget a snubber circuit across the relay contacts as you are switching mains especcially if you are switching inductive loads like a motor.

I have read about using a snubber circuit with a TRIAC, I didn't realise I needed one for a relay. I thought I could just switch the 240VAC straight through the relay. Can someone show me how to build a snubber circuit?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
I have put one at the beginning of the mains supply, would I need 2, or move it to the relay?

varistor directely connected to the mains(input) is only in a few cases usefull. --> move. Use it across the switch or across the load.
Here i´d prefer across the switch.

Klaus
********************************
Look at: www.megausb.de (German)
********************************

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi

Addition to daqq circuit.

                                     +12V to relays
                                        |      
Transformer->rectifier->filtration cap--+----|>|----+---->voltage reg.---> cap-->+5V for the rest
                                             Diode  |
                                                    = Cap ~ 470uF
                                                    |
                                                    . Gnd 

This one of the method I use by inserting a diode before the regulator.
After the diode, cap (~470uF) to ground.
Make sure you still have the decoupling caps around the regulator to.

Ken

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

MegaUSBFreak wrote:
Quote:
I have put one at the beginning of the mains supply, would I need 2, or move it to the relay?

varistor directely connected to the mains(input) is only in a few cases usefull. --> move. Use it across the switch or across the load.
Here i´d prefer across the switch.
Please excuse my stupidity. I am not sure how to use a varistor "across the switch". Across the load seems simple enough, it is just parallel to the load. Across the switch confuses me. Do you mean across the 240V switch part of the relay? Won't this just short the switch?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
not sure how to use a varistor "across the switch".
In parallel with the switch (ie relay contacts)
Quote:
Won't this just short the switch?
Only for voltages above the varistor's threshold, think of it as an ac zener.
How much electronics knowledge do you have? You haven't said (I don't think) what sort of load you are switching, if you are switching a lamp then don't worry about the snubber network or tranzorb. If you are switching a motor or other inductive load, do you understand what happens to the magnetic field stored in the coil when you turn the power off? Also is this equipment something for your own use or is it a commercial product? ie will you have to submit it for EMI/EMC testing?

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:

How much electronics knowledge do you have? You haven't said (I don't think)

Very little I am afraid. I have played with electronics a fair bit as a hobby but I am far from really understanding what is going on. I have recently read some books on basic electronics and can understand a lot of the simple stuff, but there is a point where it turns to gibberish for me.
js wrote:

what sort of load you are switching, if you are switching a lamp then don't worry about the snubber network or tranzorb. If you are switching a motor or other inductive load, do you understand what happens to the magnetic field stored in the coil when you turn the power off?

The load would usually be an electric motor, but I need it to handle just about anything that can be plugged into a 240V outlet. The problem occured when a friend was trying it with a solenoid valve.
js wrote:

Also is this equipment something for your own use or is it a commercial product? ie will you have to submit it for EMI/EMC testing?

The hope is that I can eventually sell it so I probably would have to submit it for testing at some stage. I have no idea about all that at the moment. Maybe the whole idea was something that was a bit outside my abilities but I have sort of committed to the project now. I have a small market that is waiting for something like what I have designed and I am hoping to make a partial income from it.

I really don't have a lot of money, but I am willing to pay for someones time if they can seriously help me get the problems ironed out. I have tried to find someone in my local area to help but noone seems interested. I certainly appreciate everyones generosity with their time and knowledge on these forums.