8
\$\begingroup\$

I want to control an AC 220V relay with my Arduino Nano, and I want to place everything on one PCB. I worry about 220V tracks, their width is 2mm - is it enough for 220V? Can this create electrical interference to signal (5V) tracks placed nearby?


UPD:

  • AC 220 OUT will be connected to several LED lamps, nothing special
  • Yes, I will add flyback diode to this project, but it's still working without it

My PCB in KiCAD

\$\endgroup\$
  • 9
    \$\begingroup\$ This is not an answer to your question, but are you really trying to drive the relay coil directly from an I/O pin on the Nano and without a flyback diode? That probably won't work (pjc50 already mentioned this in his answer). \$\endgroup\$ – StarCat Nov 23 '20 at 11:50
  • 2
    \$\begingroup\$ What appliance is being driven by the 220V-out? \$\endgroup\$ – Reinderien Nov 23 '20 at 15:08
  • 8
    \$\begingroup\$ What is the manufacturer and part number for your relay? If it's the Sanyou SRD series as your PCB indicates (with a 5V coil) the nominal operating current for the coil is 71.42mA - your Arduino may be able to provide this for a short time, but eventually it will fail due to excessive power dissipation in the output stage of the GPIO pin - 40 mA max. \$\endgroup\$ – Adam Lawrence Nov 23 '20 at 16:27
  • 5
    \$\begingroup\$ I really don't like how you've switched line and neutral between your terminal blocks. It makes me think you don't think it matters, because it's AC. You've said you're a "noob at electronics". Can I suggest that you not try to make circuits involving line-level voltages, until you're more experienced? You're going to hurt someone, either with electric shock or with fire. There are plenty of off-the-shelf hardware solutions for line-level switching, you don't need to make your own PCB to play with this stuff. \$\endgroup\$ – Sneftel Nov 24 '20 at 10:55
  • 2
    \$\begingroup\$ When switched off, you don't want line on the lamp socket, so with just one connection switched by the relay, you have to get the AC-IN connected correctly, otherwise you keep line going through to the socket. And you want neutral on the outer connector of e.g. an E27 socket and line on the center. Not the other way round. Regarding lamps with reversible plugs: they should have a 2-pole switch, disconnecting both line and neutral. And before changing the bulb, you better unplug it. \$\endgroup\$ – Ralf Kleberhoff Nov 24 '20 at 14:28
32
\$\begingroup\$

The important thing is not so much track width (which must be rated for current, not voltage) but track spacing. See Clearance and Creepage.

For example, if you rotate the relay 180 degrees, you can keep the coil driving pins closer to the Arduino and not have to route them so close to the mains. You might also consider putting low voltage and high voltage on the opposite sides of the PCB.

(do you have enough power from the Arduino for that relay coil? Do you need a flyback diode?)

\$\endgroup\$
  • 1
    \$\begingroup\$ There's 5V relay, and it's controlled by arduino logical output without any problems. And yes, I do need a flyback diode, I just didn't knew about it before=) \$\endgroup\$ – Antonio Nov 23 '20 at 16:21
  • 5
    \$\begingroup\$ @Antonio you're missing the point about rotating the relay. You want to organise that PCB so that there's the maximum possible separation between the high and low voltage traces: having them interleaved like that is asking for trouble. \$\endgroup\$ – Mark Morgan Lloyd Nov 23 '20 at 21:30
  • 3
    \$\begingroup\$ If your Arduino survived being connected directly to your relay, it is probably a "digital" relay that has a built-in transistor and flyback diode. A "naked" relay will very likely destroy the digital pin it's connected to the very first time you turn the output to HIGH and then LOW. \$\endgroup\$ – Duncan C Nov 24 '20 at 0:33
  • 8
    \$\begingroup\$ I'd recommend using a different relay, one that keeps the coil on one side and the poles on the other. This one makes keeping the spacing between HV and LV more difficult than needed. \$\endgroup\$ – Pelle Nov 24 '20 at 10:29
33
\$\begingroup\$

Is it safe in theory? Yes. Is it safe for you? 100% not!

Other answers have focused on technical details of what might be required for safety. I'm going to take a step up from there.

As other answers have made totally clear, you don't have any experience whatsoever with higher voltages and currents. You don't even have the electronics experience to recognise that you don't know this, or to recognise where those risks are. There's a basic principle at stake here. If you can't recognise what a dangerous situation looks like, you shouldn't do it.

Just to be clear, the risk is that you kill yourself, burn the house down, and kill your entire family. This is not hypothetical - sadly it happens regularly as a result of incompetent amateurs playing with mains electricity. Do you genuinely want to murder your family?. If the answer is "yes", there are more guaranteed ways to do it. And if the answer is "no", as I hope it should be, then stop work on this right now.

Of course you can upskill yourself. If you read the appropriate books to learn how to do this safely, then that's fine. SE is not a resource which can teach you this. Other answers can actually make this worse, because they may give you the impression that if you do what they say, you'll be OK. You won't be.

\$\endgroup\$
  • 2
    \$\begingroup\$ Graham, you're absolutely right. We can clearly see that the OP lacks the knowledge to work with mains electricity safely. \$\endgroup\$ – Ralf Kleberhoff Nov 24 '20 at 11:40
  • 5
    \$\begingroup\$ @RalfKleberhoff For me, it's the general principle of if you have to ask whether it's safe then you shouldn't be doing it. When getting it wrong is no big deal, that's fine. I've fixed water pipes myself, got a leak, got it right the second time. :) But you can't learn from experience with mains electricity and gas, because getting it wrong the first time has a good chance of killing you. \$\endgroup\$ – Graham Nov 24 '20 at 11:48
  • 8
    \$\begingroup\$ @user253751, you said 'At some point you have to decide "okay, I'm going to try mains voltage now". ` No no NO. When is the right time to do that? When you have somebody who knows what they are doing check your work and you get it right, over and over. Mains voltage, like natural gas lines, is not something to learn "on the fly". As Graham says, a single mistake can kill your whole family. Electricians have to get certified before they are allowed to work alone, and there is a good reason for that. \$\endgroup\$ – Duncan C Nov 24 '20 at 18:25
  • 5
    \$\begingroup\$ @user253751 When you know what the risks are and you know you have the skills to deal with them. It's really that simple. For a non-electronics PoV, I used to do a bit of rock-climbing, but I was never very good. I knew enough to set up a reasonable belay point; but I also knew enough to get a more experienced person to check it. The scariest things though were always perpetrated by people who didn't even know enough to recognise the dangers. But anyone sensible should be able to recognise that falling to your death is bad; and likewise with electrocution and burning your house down. \$\endgroup\$ – Graham Nov 24 '20 at 18:26
  • 2
    \$\begingroup\$ @user253751 Not quite. When someone who knows what they're doing has taught you how to do it properly, and when someone can inspect what you've done to make sure you did it properly. When you never get it wrong, then you're ready to do it without supervision. \$\endgroup\$ – Graham Nov 24 '20 at 18:30
11
\$\begingroup\$

You will destroy your Arduino if you try to drive your relay coils directly with a digital pin. (Note that some "Digital" relay modules are made to be driven from a logic-level signal. These have built-in transistors and flyback diodes, and are therefore ok to drive directly with a Arduino digital output. They take 5V power as well as a logic-level control signal. {There are also 3.3V versions.} Here is a link to a typical "digital" relay. If you're using a "naked" relay, those are NOT ok to drive directly from a digital pin.)

First, a relay coil almost certainly draws more than the 20 mA that an Arduino pin can source.

Second, inductive loads like relay coils exhibit a property known as "back-EMF", where when you disconnect them from power, they output a large surge of current backwards from they way they were powered. The back-EMF will almost certainly burn out the digital pin, and could destroy the entire board.

You should drive your relay with a transistor (a MOSFET with logic-level gate voltage is an excellent choice) and you should protect the transistor with a "flyback diode" (A diode wired in parallel with your relay coil, reversed from the normal flow of current.) Search on "flyback diode" for info on picking the right sized diode. (You want a power diode, not a signal diode. Signal diodes can't handle the current needed.)

As others have said, you should take care to isolate your mains traces from your logic-level traces. You want enough space on the board for proper isolation. You should try to design your board so the mains traces are on one side and the logic level traces are on the other, with a wide blank space between with nothing on it.

You also need to make sure the traces are wide enough to carry the current you need, with a little buffer.

\$\endgroup\$
  • \$\begingroup\$ I assembled this project on a soldering breadboard and it works good (220V part is outside breadboard of course). Arduino's digital pin is handling the load, but I will add transistor ASAP. Thank you! I'm noob on electronics=) \$\endgroup\$ – Antonio Nov 23 '20 at 16:38
  • 3
    \$\begingroup\$ Is this a 5V "digital" relay module that's meant to be driven directly by a microcontroller? Those contain a transistor and flyback diode already. \$\endgroup\$ – Duncan C Nov 23 '20 at 16:51
  • 1
    \$\begingroup\$ @Antonio It's not unusual for things to keep working when you go past the specs, but it's not unusual for them to break, either. The Arduino says 40mA max, the relay says 70mA min. One of those things isn't going to happen. There's a risk of damaging the Arduino. Maybe you have an unusually strong Arduino, or maybe they added some safety margin already, or maybe your Arduino only manages to drive 55mA but your relay is particularly good and can work with that. But a good designer pays attention to these things and will sure make the circuit works with every Arduino and every relay. \$\endgroup\$ – user253751 Nov 24 '20 at 17:44
  • \$\begingroup\$ Drawing more than the max current might not kill a pin, but hooking up an inductor without a flyback diode almost certainly will. The back EMF dumps a massive surge of current BACKWARDS through the pin. \$\endgroup\$ – Duncan C Nov 24 '20 at 18:21
  • \$\begingroup\$ @Antonio Just because it seems to work after some casual testing doesn't mean it will keep working for long. You're running way outside of the spec. It's typically not even reasonable to load something to the absolute maximum rating, and you're working at roughly twice that value. That pin will eventually burn out. If it didn't burn out on the first cycle, just wait for what happens on the 10th or 100th attempt. \$\endgroup\$ – TooTea Nov 25 '20 at 9:09
3
\$\begingroup\$

You should keep the mains and the low voltage traces apart. There are standards out there for commercial products but for a hobby design I would simply keep them as far apart as reasonably possible with the components you are using.

I don't like that style of relay that mixes up the coil and contact terminals, I'd much rather have a relay with the coil terminals at one end and the contact terminals at the other. If you must use that style of relay then I would suggest rotating it by 180 degrees from where you have it and taking the trace from the common contact straight out under the relay towards the other mains-side terminals.

And you should not drive a relay coil directly off a micro-controllers IO pin, you should use a transistor switch of some sort and should have a protection diode across the coil to absorb any back EMF.

\$\endgroup\$
2
\$\begingroup\$

Before proceeding with the PCB layout I would check with the appropriate agencies in your country and see what the rules are. Maybe UL, CE and others. From what I see in your PCB layout expect it to fail for noise and EMI reasons, there is no bypass capacitors or other protection devices. I would also consider a different chip such as something in the ATTiney class.

\$\endgroup\$
1
\$\begingroup\$

Yes, it mostly depends on the current you want to sent through these AC lines and the copper track diameter, see for example https://www.4pcb.com/trace-width-calculator.html for a calculator. Note there are many other calculator, all more or less similar.

Although the AC lines probably will not change often, it might be useful to keep the track distance at least equal as the distance width.

\$\endgroup\$
-1
\$\begingroup\$

If you only want the 220V to pass through the relay then it is totally safe but keep in mind that you must put the 220V tracks in much distance from all the Arduino pins. Also, please use a transistor to trigger the relay. Triggering it directly from the Arduino may cause current overflow as a pin of Arduino has maximum 40mA output but relay needs 5V and 70mA which can probably damage the pin of Arduino.

\$\endgroup\$
  • 9
    \$\begingroup\$ "It is totally safe" Err, no. As mentioned in one of the other answers, there are various electrical safety standards that govern how much seperation you need between high and low voltage circuits, and this doesn't appear to meet many of them, if any. \$\endgroup\$ – Mike Brockington Nov 23 '20 at 20:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.