I am detecting 240 V AC mains using optocoupler. Here is my circuit.

enter image description here

When I am doing this my microcontroller resets every time I on/off the 230V AC circuit. I've seen response of the on & off switch in oscilloscope. It is looking like below image

enter image description here Because of this transient my controller gets reset as the same transient is being seen in the reset pin and power pin of the controller.

Can anyone help with how to reduce this transient. I've tried low pass filter at output side by adding 330Ohm resistor with 10uF capacitor. Did not worked.

I've tried same thing with Arduino ATmega328P which does not reset with same transient.

Any help would be appreciated

  • 3
    \$\begingroup\$ You need to show where in the circuit your 'scope is connected. \$\endgroup\$
    – Transistor
    Commented Mar 31, 2018 at 12:21
  • \$\begingroup\$ It has connected to the pin going to uC. I've updated the drawing \$\endgroup\$ Commented Mar 31, 2018 at 18:27
  • 3
    \$\begingroup\$ If your 'scope is 2-channel can you monitor the 3.3 V supply as well and give an image? There is much information that you are not telling us: (1) What is your load? (2) What current? (3) What is the layout? Is the load well separated from the micro-processor? (4) A schematic. \$\endgroup\$
    – Transistor
    Commented Mar 31, 2018 at 19:10
  • \$\begingroup\$ And at 100 ns/div, show your scope connection. \$\endgroup\$
    – winny
    Commented Mar 31, 2018 at 19:13
  • \$\begingroup\$ I've no load I am just checking my 230V line on/off (I've directly connected 230V line and neutral to the above pins) \$\endgroup\$ Commented Apr 1, 2018 at 12:49

2 Answers 2


Your circuit, as drawn, can't put more than 3.3V or less than zero volts on the uC pin. Yet, you're seeing that, so something else must be happening. It seems likely that whatever 230VAC load you're switching is injecting noise into the power supply for the uC. Try putting your scope on the uC power supply, as close to it as you can get, and see what's there. If you do see a transient there, that's the first thing to fix.

  • \$\begingroup\$ Thanks for the help but I am powering my micro-controller from the debugger which is powered by my laptop battery hence there should not be any problem with the microcontroller power supply. \$\endgroup\$ Commented Apr 1, 2018 at 12:51
  • \$\begingroup\$ I've disconnected micro controller and only giving power supply from USB still same results obtained. Please help \$\endgroup\$ Commented Apr 2, 2018 at 5:21

I've solved problem by having conversation with one of the Texas Instruments employee

In Texas Instruments MSP430FR2311 every I/O is having relationship with VCC and hence MSP430 will reset cause by the VCC fluctuation, and the VCC fluctuation was caused by the input IO signal.

While in ATMEGA328P or some other controllers don't have these kind of problems and they can sustain a good amount of these kind of smaller transients.

So we've finally moved onto the ATMEGA328P.

More information can be found here



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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