I'm trying to make dimmer for heater using Arduino Due. I'm using a variant of this very common scheme: enter image description here

My scheme has MOC3043 with zero-crossing detection.

I use two pins to control the dimmer: detectorPin to analyse input voltage wave and controlPin to drive optocoupler. The program is very simple thanks to zero-crossing MOC.

I attached an interrupt to the input detectorPin on CHANGE event. And controlPin is used as digital output. When I test detection with controlPin unplugged everything works fine. But when controlPin is connected, value which is read inside the interrupt becomes wrong! So my dimmer cannot detect any half-wave and reports errors. This happens at the moment when controlPin value is set to HIGH with help of digitalWrite() func. After nearly 40-50 milliseconds detected values go back to normal, so most of time my dimmer work as expected.

I measured current on the controlPin, it's only 3.2mA, which is lower than maximum possible current for Arduino Due.

I tested this with detectorPin = 51, and different controlPins: 52, 36, 31.

So, how do you think, what is the problem? Is my Arduino broken?

  • What happens if you remove the traic (T1)? Do you still get the error?
    – Gerben
    Feb 13, 2016 at 15:07
  • What is the mode of the control pin ? INPUT or INPUT_PULLUP? And the I/O circuits have common ground with your Due, right?
    – Jan Hus
    Feb 13, 2016 at 15:11
  • @Gerben, I don't know, I will check.
    – kelin
    Feb 13, 2016 at 19:43
  • @JanHus, mode is INPUT, there is external 10k pullup. Yes, right, circuits are attached to one of GND pins on Arduino.
    – kelin
    Feb 13, 2016 at 19:56

2 Answers 2


There are a few issues with your circuit.

First, you need to add a diode to your 4N25 circuit. See EDIT below. You should still put a diode across your 4N25 LED. Right now, your 4N25 diode (LED) gets a high voltage across it 1/2 of the time. Because you have 60K (30K+30K) in the circuit, the LED is likely not damaged, however the LED isn't really designed to handle reverse voltage more than 6 volts. Depending upon the reverse characteristics of the Bridge diodes (leakage current), your 4N25 LED could be experiencing greater than 6 volts. Using devices beyond their "maximum specification" can produce unusual side effects.

Place the new diode (1N4007 is good, almost any diode will work) across the LED on your 4N25. Wire the new diode with new diode anode to the LEd cathode. Now, the LED will turn on during 1/2 cycle of the AC, and be protected against overvoltage during the other half of the cycle.

Second, rearrange your circuit for the Triac. The data sheet for your MOC3043 triac driver shows a typical schematic.

enter image description here

Notice the 39 ohm resistor and the 0.01 uf capacitor in the circuit. This is called a snubber and will reduce interference and voltage spikes. This type of interference is famous for disrupting low voltage circuits such as micro-controllers.

Without seeing your code, I can't say much on that. However, I presume that you are trying to detect the zero cross, and then waiting a certain amount of time AFTER the zero cross to turn on the Triac.

I measured current on the controlPin, it's only 3.2mA

Your 3.2mA may not be enough to drive the LED in your dimmer circuit. You will likely need 10mA to assure proper operation. You can reduce the resistor to achieve higher current to the MOC3043.

EDIT : I just realized that your bridge rectifier protects the LED (4N25) from reverse voltage.

  • Hi, thanks! First of all, this is not my scheme, I have different resistors and bridge, this is just example image from the internet. Second – all your notes are not concerned with problem in question. And I know that current is too low, I write this information to emphasize that there is no overcurrent through the pin.
    – kelin
    Feb 13, 2016 at 19:56

The problem with wrong input was caused by floating base of optocoupler: enter image description here

100k pull-down will fix it.

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.