220V Switch Controller with a triac

Hello,

I have designed a PCB to control a 220v socket with a NRF24L01+ and a atmega328p. I want to know if my design is secured ?
I will appreciate if you have any recommendation.
Thank you for your help.



I don't know what you mean by "secured" but it's good to see that your TRIAC is optically isolated.

I want to be sure that all protections are respected to avoid the device to take fire or blow up.

328p do not have built-in USB capability?
Unless you plan on a external programmer, sure. If you don't, either stick in a USB-TTL convete (like that one of the arduino) or use a mcu that have built-in USB functionality, like ATmega32U4.
In fact you can probably go cheaper and use a ATmega16U2 (or other smaller chips) or even a attiny (with usb-ttl chip)

Indeed, it doesn't. So the circuit around connector USB1 suggests this will run virtual USB. Frankly, I'd just stick a 4-pin header onto that board and use an external USB<>UART bridge to program the device.
Of course the chip will need to be programmed with a bootloader before putting it into this circuit as there's no provision for an SPI programmer (and the nRF24 module will f** that up the way it's connected anyway).

Also, no zero cross detection, so you're going to fire a pulse train through PD5 at the triac? Just checking!

I guess the 20mA or so current sourced by PD5 won't do much harm, although it doesn't seem particularly elegant to me to do it this way. Not necessarily wrong as it is, but well...

Not all that much bulk capacity on that board btw, unless the AC->3.3VDC converter has it onboard. Why not make C2 something like 47U? Although C5 will of course shoulder the grunt of the peak power demand by the RF module whenever it ACKs back to the other device.

When laying out the pcb, make sure to follow the layout guidelines for RF antennae - assuming you'll be using the type with the etched antenna. You won't want to kludge it up and restrict the range to 75 centimeters or so because you laid a nice and beefy ground plane right underneath it. So I assume it will be the kind with an external antenna and perhaps a PA?

Btw, good job on at least including F4!

That depends on the pulse train thingy. You have the unique opportunity to smoke this one up with bad software :wink:

Just on the use of the HLK-PM03 to power the unit...

You may want to consider some of the design features in this thread (this uses the 5v version, but the same considerations apply).

I see you added the PCB layout.
A few things:
1: In a few places clearances are small. Sometimes dangerously so, even.
2: The metal shroud of the USB connector will partly block the antenna on your RF module. It will affect usable range, although it may still be good enough. Just hope for the best.
3: Keep in mind that creepage also works through a board when routing high voltage traces.
As it is, the board will likely work, but IMO it would benefit from a night's sleep and a revision in the morning :slight_smile:

Pads for Q1 will be sparked. Just like that (snaps finger).
At least 0.1 inch separation between ALL conducting parts between the positive and negative rail (0.2 inch center to center). Pads, traces (even covered traces) and consider solder joints.

I do NOT like the way you pass the fused/filtered current to the regulator.
Put the connector at the very edge of the board. Fuse immediately behind it and then the filter cap.

It's not as significant (compared to some deadly ones like Q1) as it's not very easy to directly put positive rail on top of negative rail, and the breakdown voltage for FR4 is decently high. Still.

That's one of the reasons most high-voltage boards are single-sided.

And lastly, I do not think MOC3041M will be happy. It probably will work, but I don't think it will be happy.

Yeah. If you actually do the calculations for creepage, which are influenced a lot by requirements, environmental conditions etc, it's remarkable how quickly you get to distances like 7mm - a requirement that isn't even satisfied by the pin placement on the parts themselves. Go figure...I agree that for instance the pads on Q1 are an accident waiting to happen the way they're laid out. I would serious consider offsetting the middle pin a couple of mm ; it's a TO220 part anyway so the leads are long enough.

A TO-220 should not be used to switch 250V. Not AC. Especially not mains-AC.

It's amazing how people seem blatantly ignorant of the dangers they are putting their designs into.

It depend on what material it's going through. Regardless, the current implementation of his is just ... wrong

Thank you every one for all your good advice :+1:.

Yes maybe i should add a pull down resistor to avoid the triac to be on when the atmega is starting

I don't understand ? What can i do ?

I never know the value of a condensateur to use. I will replace C2 by a 47uF

Do i need to add also a 300mA fuse has a input of the HLK, because i already have a 3A fuse ?
Do i truly need a varistor ?

I don't understand why the MOC3041M will be unhappy ?

Ah, just leave it at this, I'd say. You could buffer the output from PD5 to the optocoupler; that's what I would have done, but it's not really necessary.

I generally run a Spice simulation for this kind of thing, modeling the microcontroller as an intermittent current sink.
Actually since your 3.3V power supply is likely an SMPS (didn't check, just assuming) and it'll have a switching frequency of at (the very) least 1.5kHz, 47u should be ample. Doesn't hurt to have it there. Just don't make it unnecessarily big (1000uF or so) because the inrush current can force the SMPS into lockdown.

I would be tempted to do so. Your current 3A fuse still allows nearly 750W to be dissipated in the logic part of your PCB if things somehow go horribly wrong. That's a neat little fireball.

400V blocking voltage is quite close to 230VAC.

I try to take into account your recommendation to do a better version :

  • 2mm AC track width
  • 2.5mm AC track clearance
  • AC track only on bottom layer
  • offset the middle pin of Q1
  • move the usb connector away from the NRF module
  • add 200mA fuse
  • add pull down resistor at PD5 pin
  • change C2
  • add a varistor

At the end the PCB is very big but i don't know to make it smaller :roll_eyes:


Capture d’écran 2022-03-24 182520

Now your rf antenna is right on top of/below the oscillator of your microcontroller. I'd try to prevent that as well.
There's some opportunity for space savings, but it's not much. U3 is pretty big; if you use header pins you could always suspend that partly over your low voltage circuitry to reduce surface area, but you'll of course need more space on the z-axis.

I was thinking it is only the usb connector. Thanks, I will put away the oscillator too.