Author Topic: PCB Design and Mains Voltage Advice  (Read 10462 times)

0 Members and 1 Guest are viewing this topic.

Offline KugelBlitzTopic starter

  • Contributor
  • Posts: 17
  • Country: ro
PCB Design and Mains Voltage Advice
« on: November 13, 2017, 12:16:25 pm »
Hello, everyone!

I'm designing a circuit that uses a sensor to monitor temperature and switch a relay on or off based on that input.

Here is the electrical diagram of the

Also, the PCB design:
and
.

The brainbox will be an ESP8266-01 chip. The chip controls the Q1 transistor which, when on, will cause the relay to close the circuit. There's a switch (SW1) which would also turn on the transistor (backup in case the transistor / esp chip fries for whatever reason).
Powerwise, PWR1 is a SMPS converting 240VAC to 3.3VDC with an MOV in parallel on the input side, and 2 caps on the output side (or the input side of the chip): a 1u for filtering and 470u as a power reserve.

The relay switches power for a pump. It connects the live line on pin 3 of the screw terminal (J1) to pin 1 on the screw terminal.
The ground of the pump is connected to the ground for this circuit (pin 5 and pin 4).

I should also mention that I will be initially making the boards myself, atleast for testing purposes. After all is done and tested I will probably order some PCBs.

Regarding the mains voltage side of the circuit, my concerns are related to the width of the mains PCB tracks. It is my first PCB that deals with mains voltage and I'm not sure how wide to make those tracks. They are currently 3 mm wide.

The relay is rated for a max of 8A, but the pump itself draws a maximum of around 4. Just to be safe, I calculated the trace widths for 8A. Since I don't know the specs of my PCB boards, assuming a minimum of 1 oz/ft^2 of copper, I get a maximum trace width of ~15mm, and for 4 oz I get a minimum width of ~2.5mm.

I looked at several other circuits I have lying around that connect straight to mains and none of them seem to have tracks wider than 1.5 mm. Most notably, the PCB of a vacuum cleaner that draws 6 amps
at mains voltage whose traces seem to around 1.2 mm wide but are tin plated.

What are your recommendations regarding trace width and should I also tin them, just to be on the safe side?

Another concern that I have is the spacing between the mains tracks. The spacing between the high voltage 240VAC side and the low voltage 3.3VDC side is atleast 8mm at any point, which I believe to be sufficient but please advise. However, the minimum spacing between L and N tracks is of 2mm, the minimum that the screw terminals allow. Would this be enough, or are there risks of sparks between the tracks? I also added isolation slots in the PCB which can be seen in the PCB images in light blue.

Finally, any critical remarks or advice regarding the PCB in its entirety is welcome.
« Last Edit: November 13, 2017, 12:18:35 pm by KugelBlitz »
 

Offline capt bullshot

  • Super Contributor
  • ***
  • Posts: 3033
  • Country: de
    • Mostly useless stuff, but nice to have: wunderkis.de
Re: PCB Design and Mains Voltage Advice
« Reply #1 on: November 13, 2017, 02:53:33 pm »
Layout looks OK, 8mm clearance is more than you need (5.5mm for double isolation on a 230V circuit).
I wouldn't use a MOV, they might explode at some point.
As someone stated at some other thread, 1.6mm distance between L/N should be okay (but don't nail me down on this). IMO isolation slots aren't necessary.

Depending on your load, some filtering (X rated capacitor across L / N, or a snubber R/C across the relay contact) may be necessary.
« Last Edit: November 13, 2017, 02:56:02 pm by capt bullshot »
Safety devices hinder evolution
 
The following users thanked this post: KugelBlitz

Offline KugelBlitzTopic starter

  • Contributor
  • Posts: 17
  • Country: ro
Re: PCB Design and Mains Voltage Advice
« Reply #2 on: November 13, 2017, 03:35:29 pm »
Thanks for the tips!

So 2mm or more between traces should actually be plenty? I have mixed feelings about the isolation slots. For testing purposes, the PCBs I make are made on a small CNC mill so it's not a big deal to use the 1mm endmill for cutting the slots, but they do limit my choice of PCB fab house so it would be good if I can safely omit them.

I was reluctant to place the MOV there but the spec sheet for the power supply says it "is required for 230VAC operation".

Also, it didn't cross my mind to add filtering as you mentioned, but it would be a good ideea. The load is a maximum of 4 amps, but this is usually only for a second or so. Otherwise, the load is around 1 amp.
 

Offline capt bullshot

  • Super Contributor
  • ***
  • Posts: 3033
  • Country: de
    • Mostly useless stuff, but nice to have: wunderkis.de
Re: PCB Design and Mains Voltage Advice
« Reply #3 on: November 13, 2017, 04:39:50 pm »
MOV: if they require it, leave it in
Filtering is intended for transient disturbances happening when the relay is switching, depending on the kind of load (motor, resistive, ...), not the load current.
Isolation slots like yours are really seldom to be seen in the wild. They do not increase the clearance, but the creepage distance and shouldn't be neccessary here.

Safety devices hinder evolution
 
The following users thanked this post: KugelBlitz

Offline woody

  • Frequent Contributor
  • **
  • Posts: 291
  • Country: nl
Re: PCB Design and Mains Voltage Advice
« Reply #4 on: November 13, 2017, 07:11:42 pm »
I would, out of habit, connect all pins of the pot.

Then there's probably very good reason that escapes me so soon after dinner, but why does the ON track switch planes?

I would turn the relay +90 deg and/or move it toward  Q1 to make the 240V tracks shorter. Something I always like.

Then again, this is not my PCB  :)
 
The following users thanked this post: KugelBlitz

Offline floobydust

  • Super Contributor
  • ***
  • Posts: 6979
  • Country: ca
Re: PCB Design and Mains Voltage Advice
« Reply #5 on: November 13, 2017, 07:50:01 pm »
Where is the fuse for this? - both the pump and RAC03 PSU and MOV need something to limit fault current. RESCOM app note has 1A fuse. Pumps always jam. Don't rely on the mains circuit breaker! I'd put in a 5x20mm fuse.

Your relay contacts will arc when switching inductive loads off. This shortens relay contact lifetime and the burst of EMI can crash an MCU.
I would have an RC snubber across the contacts, something like 47nF X-cap and 68R 1/2W resistor to start.

You can mirror PCB traces on both sides of the PCB to get higher current.
Look at backing off the ground-pours, they look too close to the SMT resistor pads.
You might want to move the temp sensor off board, local heating can give poor results for the temp reading accuracy. Maybe a connector for the DS18B20.
Having a PCB mounting hole by mains pads/traces can give surprises if the spacers/screws short to them. Watch creepage/clearance there. The RAC03 mains pins are the smallest clearance.
 
 
The following users thanked this post: KugelBlitz

Offline KugelBlitzTopic starter

  • Contributor
  • Posts: 17
  • Country: ro
Re: PCB Design and Mains Voltage Advice
« Reply #6 on: November 14, 2017, 06:29:41 am »
Thanks for the tips!

@floobydust: I didn't include the fuse because I initially wanted to use a different PSU that had over current protection and the pump is also fused so I thought I could get away without it. Unfortunately, they don't sell that PSU to individuals, just to companies, so I had to switch to this one. I falsely assumed this PSU wouldn't need a fuse either, completely overlooking the spec sheet, which was wrong.

I actually plan on using socket connectors for the temp sensor and the mcu. Would it be a good idea to also use such connectors (rated vor mains, of course) for the MOV? It would make it a whole lot easier to swap out if it goes all smokey on me.

Thanks for pointing out the mounting hole issue. The PCB will actually fit in a plastic housing. It just clips into place. But it's good that you mentioned it because the casing does have a couple of screws which would be beneath the PCB and I'll have to check the clearance on those.

@woody: The chip doesn't have an ADC so I'm using the wonders of RC time constants to get a rough reading from the pot. Given this, is there any reason to connect the rest of the pins?
I switched the NO plane to keep it as far away from the other 2 traces as I could but, as you all pointed out, it isn't necessary.

I cannot rotate the relay as it would hit other components. This board replaces an existing, dumber board, and the pot and LED must remain where they are to fit. There is also a cutout in the middle for the wires which I can move around a bit, but overall it's the best layout I've managed to come up with so far.

In any case, the following require my immediate attention:
  • Add a 1A fuse
  • RC snubber across the relay contacts as bth floobydust and the captain suggests
  • Increase clearance of SMT pads
  • Get rid of the isolation slots

I'll make the changes and post back with my results.
 

Offline woody

  • Frequent Contributor
  • **
  • Posts: 291
  • Country: nl
Re: PCB Design and Mains Voltage Advice
« Reply #7 on: November 14, 2017, 10:45:25 am »
@woody: The chip doesn't have an ADC so I'm using the wonders of RC time constants to get a rough reading from the pot. Given this, is there any reason to connect the rest of the pins?

No reason other than 'out of habit'. It would cost nothing and prevents (the admittedly very small chance of) the runner floating due to a bad contact with the resistance material inside the pot. I like your use of the RC time :D
 
The following users thanked this post: KugelBlitz

Offline KugelBlitzTopic starter

  • Contributor
  • Posts: 17
  • Country: ro
Re: PCB Design and Mains Voltage Advice
« Reply #8 on: November 16, 2017, 07:42:44 am »
I ended up redoing the PCB. I moved the smd components on the other side because the PCB would lay almost flat against the plastic case but there are a couple of portruding screws that might touch them. I also rotated the screw terminal and moved the PSU down the board to give me more room for the fuse, mov and snubber.

My end result is this: top, bottom

Regarding the snubber, the more I read the more complicated it seemed to get. Every design I read about was different depending on the type of load. I then realized that I can study the old PCB and see what kind circuitry it has to deal with this issue. The old PCB has absolutely nothing between the 2 traces: L to NO and NO to pump and that's it. Maybe the pump itself deals with it?

In any case, I added a resistor and cap in parallel with the relay contacts like
.
Since i'm not sure what the heck is going on inside the pump I stuck with floodybust's values for the snubber. The resistor is off the shelf 68R 1/2W. For the cap I think I'll choose a PHE450PK4470JR05. Would this be a wise choice?

Also, what do you think of the PCB layout? (don't mention the crooked cap, my OCD is going nuts over it but it gives me more room)
« Last Edit: November 16, 2017, 09:41:36 am by KugelBlitz »
 

Offline woody

  • Frequent Contributor
  • **
  • Posts: 291
  • Country: nl
Re: PCB Design and Mains Voltage Advice
« Reply #9 on: November 16, 2017, 09:37:09 am »
Also, what do you think of the PCB layout? (don't mention the crooked cap, my OCD is going nuts over it but it gives me more room)

I know the feeling, so I won't mention it. And the replacement of R3 etc made up for it :) Maybe exchanging R9-C4 gives you more room, but that probably would mean relocating R7 as well.

What I would do is put D1, Q2, R3 next to the relay; it enables you to route the track to R3 neater. I probably would relocate R1 and R4 next to the LED or next to their transistors for the same reason. Then I could regroup the tracks to R1, R3 and R4 to run right next to each other and remove the copper pours between them (like in your original)

I would make the vias a lot smaller and remove the floating copper pour under RAC03, next to +Vout. It does not harm but makes no sense.

Then there is no reason that track GPIO2 - D3 changes layers. I would route this track on the top layer and relocate the via needed for the connection between R2 and GPIO0. Or ditch that via altogether and lead that track under D3 if track size permits.

I would use the same track width for all HV tracks. Now the N tracks are smaller than the L and NO tracks.

And are you sure that the connections to the trimpot are correct? All the trimpots I have in stock (Bourns 3296) have their runner on the lead in the middle, which is not connected on your board.


 
The following users thanked this post: KugelBlitz

Offline KugelBlitzTopic starter

  • Contributor
  • Posts: 17
  • Country: ro
Re: PCB Design and Mains Voltage Advice
« Reply #10 on: November 16, 2017, 01:08:32 pm »
Thanks for the R9-C4 swap idea, the HV side looks much neater now, despite relocating R7.

I tried to group D1, Q2 and R3 and it was initially cleaner but then the area became too cramped as I tried to fit R4 and R1. Since I moved R4 and R1 I tried moving q3 as well and I just couldn't get them to align nicely. I then redesigned the whole thing all over and I think it is a bit cleaner.

The vias are this big because I will initially be making this PCB on a small CNC mill for testing on a bench supply and I can't DIY my own plated through holes. Once I'm happy with the design, I'll switch to proper vias and remove unnecessary traces to order a proper PCB. That's also why GPIO2 switches layers, i'll only be able to solder the socket for the chip on the bottom layer and I need to bring the traces to the top.
 
Quote
And are you sure that the connections to the trimpot are correct?
I forgot to connect the runner. I did change the electrical diagram for the pot as well. In my first post, it was designed so that the mcu would measure the time required for the pin to become high (VCC charging the cap). I realized that if instead I measured the time required for the pin to become low, I wouldn't need a VCC trace to charge the cap, only one trace from the mcu pin.

Here is the board: top, bottom. Any thoughts :D ?

Also, whaddaya think of the cap?
 

Offline woody

  • Frequent Contributor
  • **
  • Posts: 291
  • Country: nl
Re: PCB Design and Mains Voltage Advice
« Reply #11 on: November 16, 2017, 04:20:56 pm »
Nice PCB! Looks much better than the first version.

Unfortunately R1 and R4 are back in a 45 deg position, but hey, you can't win 'm all  :)

I have no idea of the values of the snubber; floobydust suggested these values and also an X class cap. I'm wondering if you need an X class in this case as these are allowed (although not meant) to fail short circuit, which would trip the fuse further up the river. In this case it would mean your relay is bridged and the pump will be always on, via R9. Y class caps are meant to always fail open if they fail. After a quick look at the datasheet I suspect that the cap you selected is neither X nor Y class. All this X-Y cap business is not really my cup of tea so you certainly need to verify. Complete X2 class snubber devices are also sold: http://www.kemet.com/P409. They're big, so there goes the PCB design again....

The place of R8 in the schematic makes more sense now, to prevent the MCU port from being connected directly to ground when the pot is set to minimum. Make sure R8 has a value that limits I to the max allowed for the port. I am curious to learn if you get the RC trick to work a bit stable with the ESP.

Quote
The vias are this big because I will initially be making this PCB on a small CNC mill for testing on a bench supply and I can't DIY my own plated through holes.

Ah, so. I own a PCB mill myself and have the same problem. Sticking little wires in small holes and then solder them both sides is no fun. And so far I haven't seen a workable thru-hole solution. My workaround was design the proto with thru-hole components, as you then get the vias for free, and when everything is OK design again with smd parts. That became a bit of a nuisance and with prices of PCB's nowadays I design 'm right away using SMD. Which has its own drawbacks, of course.
 

Offline KugelBlitzTopic starter

  • Contributor
  • Posts: 17
  • Country: ro
Re: PCB Design and Mains Voltage Advice
« Reply #12 on: November 17, 2017, 06:07:59 am »
Quote
Unfortunately R1 and R4 are back in a 45 deg position, but hey, you can't win 'm all  :)
Well, I think it adds character :) Actually, if I had the time, I would make the traces by hand and make them all curvy, sort of like the early, hand drawn PCBs, like this one from wikipedia.

Quote
Make sure R8 has a value that limits I to the max allowed for the port. I am curious to learn if you get the RC trick to work a bit stable with the ESP.
The pin can source a max of 12mA. At 3.3V, that's 275 ohms and R8 is 1K. What do you mean if I can get it to work a bit stable?

Anyway, can anyone chime in on this capacitor?
« Last Edit: November 17, 2017, 06:14:48 am by KugelBlitz »
 

Offline woody

  • Frequent Contributor
  • **
  • Posts: 291
  • Country: nl
Re: PCB Design and Mains Voltage Advice
« Reply #13 on: November 17, 2017, 03:30:23 pm »
Quote
What do you mean if I can get it to work a bit stable?

I meant that I haven't a clue how one would use and program an ESP. If it runs some sort of OS that you need to use to set and read pins it could be quite difficult to precisely monitor the RC time. I would get it to work on a PIC but not if that PIC would run all sorts of interrupts during the timing. So hence my remark.

For all I know the ESP has an 'rctime' function like some Basic Stamps, and then it is straightforward.
 

Offline KugelBlitzTopic starter

  • Contributor
  • Posts: 17
  • Country: ro
Re: PCB Design and Mains Voltage Advice
« Reply #14 on: November 17, 2017, 03:49:57 pm »
I believe that they ship with nodemcu firmware but don't quote me on that since I throw that firmware out the proverbial window and flash my own. You can actually use the Arduino IDE and write arduino style c++ code and flash it on the esp8266. I found a guide on how to do this over here. I'm sure that since that guide was published, several other methods have popped up. In terms of the RC time, I don't know if arduino has any standard function for that. I coded my own to try it out and coded in a range from 5 to 30 degrees C. I get consistent results within a 0.5 degree margin. Granted, I haven't thought of disabling any interrupts that might cause different results, will look into it though.
 

Offline floobydust

  • Super Contributor
  • ***
  • Posts: 6979
  • Country: ca
Re: PCB Design and Mains Voltage Advice
« Reply #15 on: November 18, 2017, 04:53:47 am »
The board looks pretty good, sorry to suggest big snubber parts but they are worth it.
You could use a Picofuse for the power supply- the 5x20mm was if the pump was also fused; easy to replace.

Watch the antenna on the ESP8266 is not blocked by the ground-pour. I'm not sure how much range you need but it might have trouble radiating out the back side.

I used the Arduino IDE with the NodeMCU and was surprised a simple LED blink program took forever to download and was something bloated like 120KB. Most sample code was pretty bad; you get no error messages and things get stuck in a loop if the WiFi connection is not established- not good for I/O.
 

Offline KugelBlitzTopic starter

  • Contributor
  • Posts: 17
  • Country: ro
Re: PCB Design and Mains Voltage Advice
« Reply #16 on: November 18, 2017, 02:00:19 pm »
Thanks for the antenna advice. I cleared the area underneath and rerouted along the outline.

Quote
sorry to suggest big snubber parts but they are worth it.
I'd rather have a denser PCB and peace of mind than worry that my relay may fail.

Thanks a lot for the tips and feedback. I have to wait for some parts to arrive and then I'll build the board. I'll post pics with the finished board.
 

Offline rbm

  • Regular Contributor
  • *
  • Posts: 230
  • Country: ca
Re: PCB Design and Mains Voltage Advice
« Reply #17 on: November 18, 2017, 02:17:04 pm »
Just throwing a question out there.  D3 appears to be lying underneath the horizontal ESP8266.  During fabrication, you'll solder D3 in first and attach the ESP8266 board afterwards. 

If you ever have to rework a board because D3 failed, how will you get at the solder pads with the ESP8266 board in the way.  Could you move D3 to the right just a little to get it out from underneath the board?  It appears that you have enough room to do this.
- Robert
 

Offline KugelBlitzTopic starter

  • Contributor
  • Posts: 17
  • Country: ro
Re: PCB Design and Mains Voltage Advice
« Reply #18 on: November 18, 2017, 08:28:38 pm »
Quote
If you ever have to rework a board because D3 failed, how will you get at the solder pads with the ESP8266 board in the way.

Thanks for taking a look at the board. I will be soldering socket connectors on the PCB for the ESP chip and the temperature sensor so that if they ever fail for whatever reason I can just pull 'em out and swap another in their place (or to easily remove the chip if I ever want to reprogram it). I may even use a socket for the MOV if I can find one with the appropriate rating.
 

Offline KugelBlitzTopic starter

  • Contributor
  • Posts: 17
  • Country: ro
Re: PCB Design and Mains Voltage Advice
« Reply #19 on: December 27, 2017, 11:54:55 am »
I know it's been a while, but I've finally gotten to making the PCB. Here are a couple of pics: top and bottom

If anyone is wondering, the black stuff is just 690 degree C temp resistant paint that I use as a soldermask.
 

Offline JacquesBBB

  • Frequent Contributor
  • **
  • Posts: 829
  • Country: fr
Re: PCB Design and Mains Voltage Advice
« Reply #20 on: December 27, 2017, 01:46:39 pm »
How did you do the PCB ?

Did you etched it by yourself ?
 

Offline KugelBlitzTopic starter

  • Contributor
  • Posts: 17
  • Country: ro
Re: PCB Design and Mains Voltage Advice
« Reply #21 on: December 27, 2017, 04:20:05 pm »
How did you do the PCB ?

Did you etched it by yourself ?

CNC milled
 

Offline woody

  • Frequent Contributor
  • **
  • Posts: 291
  • Country: nl
Re: PCB Design and Mains Voltage Advice
« Reply #22 on: December 29, 2017, 01:43:23 pm »
If anyone is wondering, the black stuff is just 690 degree C temp resistant paint that I use as a soldermask.

I am interested in what paint you used and how you got that paint on the board. It looks neat! I use a mill regularly but never bothered with a solder mask as it looks like a lot of work.
 

Offline KugelBlitzTopic starter

  • Contributor
  • Posts: 17
  • Country: ro
Re: PCB Design and Mains Voltage Advice
« Reply #23 on: December 29, 2017, 06:10:21 pm »
    If anyone is wondering, the black stuff is just 690 degree C temp resistant paint that I use as a soldermask.

    I am interested in what paint you used and how you got that paint on the board. It looks neat! I use a mill regularly but never bothered with a solder mask as it looks like a lot of work.

    The PCB was done with a V bit, a cut depth of 0.16mm and a feed rate of 100mm / min. Took around 30 min per side.

    The paint is just regular high temp spray paint, this is the actual can I used for this PCB.

    As far as getting it onto the board, well there is the easy way and the hard way:
    • Easy way
      There is a shop in the city I live that makes custom decals for advertising purposes. Using the soldermask gerber file, I save a bitmap version that I then send to them and they cut a plastic decal with my design. Depending on how busy they are, this can take from half an hour to half a day.
      This decal is actually just a plastic foil with adhesive on one side and a paper backing on the other.
      I then align the decal with my pcb, stick it to the PCB and peel back the paper backing.
      After that, I paint the board with the spray can and then, with a blunt needle or tweezers, I remove the decals and at this point I have a PCB covered with high temp paint everywhere but the pads / pins
    • The harder way
      The first method requires a shop to make these decals but, alternatively, you could do what I did before I found out about this shop which is to use regular nail polish or corrector fluid to mask the pads before painting. Obviously, the smaller the brush the better job you can do at masking just what you need without smudging the PCB with nail polish.
      I used to dip a wooden toothpick in the nail polish and use that as a brush to mask the pads.

    In the future, I would also like to see if I can use the toner transfer method to mask the pads with toner.

    I do have a small advice. The paint I mentioned above requires that you bake the paint in an oven for an hour. In this case you have 2 options, remove the decal / nail polish before baking in which case the copper will oxidize and you will have to remove the oxide layer, otherwise the solder won't take. I just used a small fine file and I have gone over each pad to remove the oxide layer. Alternatively, you could use vinegar or some commercial copper cleaner / polishing compound if you fear you'll damage the copper.
    Otherwise, you can leave the decal / nail polish on the PCB and bake it as is.
    For this PCB I chose to leave the decal on the PCB and you will see on some pads that the paint looks sort of bubbly probably because of the way that the decal reacted to the heat. It made the decal brittle and crumbly and I had to scrape it off.

    Also, ensure that the temp you use to bake the paint is not greater than required because, depending on the quality of your PCB and how thin your traces are, the copper may delaminate or peel off of the PCB.
    Whatever paint you choose, you should check that the paint can handle the soldering temperature you use. This paint is good up to 690C, but I know there are paints that go higher or lower.

    The beauty of this method is that (at least for the second method) all the materials can be found at a hardware store. You don't have to order anything online, which in my case takes weeks to arrive, and you don't have to mess with transparency sheets, UV curable pastes, UV lamps, tricky exposure times and other chemicals.[/list]
    « Last Edit: December 29, 2017, 06:12:56 pm by KugelBlitz »
     


    Share me

    Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
    Smf