First ever project looking for efficiency improvements and guidance

2.5k resistor it is :grin:!!

The circuit I had working using a batery:

1 Like

A few more notes. Is J1 pin earth? Which is then connected to J2 pin 2.
And J2 pin 2 is GND.

As you said you will leave mains power for now but this is a bad idea. It’s too easy to get the wiring mixed up for earth/gnd on the same connector. Keep mains and low voltage on separate connectors and clearly label them so in a few years when you have long forgotten about how things are connected up on the project you don’t make any easy mistake and get things mixed up.

One other option to add in on the final PCB (Should you be getting this design made up on PCB) is to add in a ICSP. That way you dont have to keep removing the chip to reprogram. (Even if its a DIP) I use smd atmega’s in my projects so it’s not too easy to keep removing them. Far easier to add in a 2x3 pin header should you even need to reprogram and it doesn’t take up too much space even if its never used.

Also what is the function of the reset button. If you want to reset the microcontroller then this will not work. You need to connect the button to the reset pin.

Otherwise all you can do with the way its currently configured is to read the value of the reset button in the code and then try and reset using a software routine. Not very practical. If you want to reset the microntroller best is to do it in hardware, otherwise if it ever crashes you can never reset it.

Well that’s an appropiate use of the text function alright.

Indeed I believe someone also suggested that and it’s a very good call.

The reset button is not resetting the micro, it’s just resetting a flag, I should have given it a different name in order to not create confusion

I don’t see the:

  • Optocouplers.
  • Transistor.
  • Relay.

Such a simplified circuit may be useful for software testing but it’s far from complete.
Apparently you do not have much experience with electronics (yet), so it’s time to extend your breadboard with those parts and see how they behave.

Also:
Another thing that is missing is a 100nF ceramic capacitor.
Make a habit of it to always add a 100nF capacitor as close as you can to any pair of uC power pins. Such a decoupling capacitors, are just too cheap to not add, and such a capacitor does make your circuit a lot more reliable. (This is a simplified version).

I am sorry i do not have anything really important to add in this thread, but, the word mandatory brought me some thoughts.

Voltages above 50V AC and 120V DC are considered dangerous. Developing a product that reaches or exceeds those limits requires compliance with some standards that differ from country to country.

Some keywords for your research, SELV, PELV and FELV.
And one request from me(a nobody), as others mentioned, please stay away from dangerous voltages and GRID connections. At least until you have a complete understanding of:
what current is and how does that thing work,
what TN, TT and IT are and how do they work,
and how protection against short circuit and electric shock works.

Best regards!!

1 Like

Yes indeed, the purpose of that circuit was to test my programming, but me posting it was also to show the connection I mentioned above of the button connected to a 10k resistor and ground.

Unfortunatly I don’t have capacitors around the house so I can’t add them onto the breadboard, but I will add them to the real life circuit asap.

Thank you

Hi Aris_Kimi, for me any thought is appreciated since I still have a lot to learn :grin:

The end goal of this project would be to eventually obtain certification for it.

I will look into all of those, thank you

When dealing with the HCPL-3700, read the application note and be especially sure to fully understand the part about the series resistors on the inputs.
THE INPUTS SHOUD NEVER BE CONNECTED DIRECTLY TO MAINS VOLTAGE, without series resistors. (The component will blow up.)
I don’t see any series resistance in your schematic drawing, so they need to be added.
And resistors with enough voltage rating for mains should be used (mind transients!).

5V go to only first pin of 10k resistor. Its second pin is connected to GND so for microcontroller it is always GND. At PB2 microcontroller always see ‘0’.
You can connect SW1 one pin to GND and second to PB2 (without using any resistor). Microcontroller certainly has internal pull-ups (about 30k I think) you can individually switch on for each pin. Then if SW1 not pushed PB2 reads ‘1’ and when pushed PB2 reads ‘0’.

Forget for now.

Yes, the internal pull up resistors are 30k. And that seems like a cleaner way to do it, thank you.

For sure that will only be at my reach some time from now.

Indeed, I should do that for every single component, seems like a way to learn

100% right, thank you once again

I am sorry english is not my native tongue, with this you mean to consider “spike” voltages?

Regarding the input resistors on the HPCL3700’s AC side: input current can be up to 4mA! So be wary of the resistor’s required power rating.
For this reason I use the HPCL3760 which needs only ~1.6 mA input current.

1 Like

Yes, transients are voltage spikes which can be quite much higher than the normal 230V (115V) RMS mains AC voltage (which peaks somewhere around 325V.
Usually spikes of 2,5kV or 4kV are considered possible on normal household AC, and the isolation distances and voltage ratings of optocouplers etc. should be chosen accordingly.
But the corresponding standards should always be consulted to be certain of conformity.

Makes sense, will remember that one!

Regarding the “almost mandatory”. If you put line voltage on your assembly then it will be mandatory that you learn how to do so safety per regulatory requirements for every market into which you wish to sell even one unit. Here in the USA that would be UL950 (Or what every it is called these days). There will be requirements on spacing of traces and tests for what happens when components fail to demonstrate your product will not be a shock or fire hazard.

You will be much better off using a 2.1mm power jack such as:
https://www.digikey.com/en/products/detail/tensility-international-corp/54-00166/10459294
There are SMT version too.

No mater what you do you have to consider the enclosure and how you will connect the power. There are safety requirements the enclosure and you assembly methods will have to meet if you bring the AC line into it.

You will have FCC line conducted requirements and FCC radiated emission requirements too.

Hope this helps.

Another kind of voltage spike is the Electro Static Discharge that we get for example when the weather dry and we walk across carpet (often plastic) and touch something making a spark. To counter this every connection to the outside world (through the enclosure should have as much capacitance to the device common (ground net) as is compatible with the device normal operation. Then a series resistance as high in value as is compatible with normal operation. For the capacitor and resistor you must figure that out on a case by case basis.

Hope this helps

I want to second what gmc says above.

Your wiring (as I see it on 20220419) for the relay primary coil is not going to work. The application note he provided is the right way to do it. The diode needs to be wired per the application note.

The current must go through the coil. The current is found in the specification.

For example, the 5V relay will have something like 5V divided by the coils resistance which is 167 ohms in the specification. When calculated that is just about 30 mA. So you have to connect one end of the coil to 5V and the other end to ground (through the transistor which acts like a switch when correctly wired.)

Hope this helps.

Hello!

I built a similar circuit with RAC, HCPL-3700 and relays:

HCPL:
Don’t use HCPL for mains. The input require very low resistances (39k x 2) which means in the worse case they will be dissipating a lot of heat (1.4w). I have tried with SMD and THT 3w resistances and they all get very hot to the point you cannot touch them. My conclusion is that HCPL is not made for mains, but instead for low voltage AC signals.
I switched to using an LDA210 with capacitors to rectify the wave, that allows me to use very high input resistances, like 500kΩ

RAC:
I am using a 05-05SK. Even when they are quite protected, I think it is a good idea to add at least a varistor and a fuse before to make sure they won’t catch fire on high voltages. Also, This modules produce noise, so you have to add capacitors in the DC part, and maybe something in the input AC part

Relays:
Consider using a relays driver instead of transistors. I am using ULN2003A. It makes the design easier

Mains:
Separate them as much as possible from the low voltage stuff. For example:

  • Don’t share the connector between mains and GND
  • Add fuses everywhere if you have a mains terminal. You need to make sure you are controlling and limiting the Amps going through every part of the PCB.
  • When you build your PCB you need special attention to track size, clearance and creepage
  • Consider adding a comformal coating
  • Add slots to the PCB, you need to have mains sectors and low voltage sectors. Traces should not be in the same region

My latest design: electronics-homeassistant-lightscontroll/PCB/schematics-v18 at main · crgarcia12/electronics-homeassistant-lightscontroll · GitHub

I don’t like when people says “stay away from mains” because that gives not path-advice on how to learn. In the other hand, they are actually giving you a very good advice, there are many topics you need to master in order to do a safe mains design and mistakes can be very expensive.

I disagree here, learning requires a safe environment, and “mains” is definitely not one.

Also has to be noted that even lower than mains voltages are considered dangerous.

I am not confident at all to help anyone expose themselves in danger. (This includes the end user of a product)

Basic electrical/electronics courses are available for free out there in a lot of places, but learning takes time