I am trying to make a 3kW triac based ESP8266 dimmer with zero detection for controlling boiler power, but the installation here in Belgium does not have neutral, so connection is to two live wires. I am using schematics from MOC3042 datasheet, without snubber circuit, applied to one live wire only. The problem is that for power values >0% and <100% test bulb just flickers randomly. Zero detection works ok as far as I can see on the scope, and even the whole circuit was behaving ok at 60VAC without load, but when testing it on 230VAC and with 40W light bulb goes bananas. Same flicker appears when testing with 2.5kW pool heater with led. Scope pics are with 33%, 50%, 70% power respectively, no load, 60VAC mains isolated.

  // Check zero-crossing by polling the zero-cross detection pin
  if (outputPower) {
    if (digitalRead(ZERO_CROSS_PIN) == HIGH && !pulseHigh) {
      pulseHigh = 1;
      period = micros() - zeroCrossedMicros;
      frequency = 500000.0 / period;
      frequency = round(frequency * 100) / 100.0;
      zeroCrossedMicros = micros();
    } else if (digitalRead(ZERO_CROSS_PIN) == LOW && pulseHigh ) {
      pulseHigh = 0;
    if (micros() - zeroCrossedMicros > pulseDelay) {
      digitalWrite(TRIAC_PIN, HIGH);
      digitalWrite(TRIAC_PIN2, HIGH);
      digitalWrite(TRIAC_PIN, LOW);
      digitalWrite(TRIAC_PIN2, LOW);

enter image description here enter image description here enter image description here enter image description here

  • \$\begingroup\$ Your zero-cross and load circuit need to be on the same phases or phase-neutral. "... and even the whole circuit was behaving ok at 50VAC without load ..." This is unlikely as triacs have a minimum holding current. How do you know? \$\endgroup\$
    – Transistor
    May 20, 2023 at 16:31
  • 1
    \$\begingroup\$ The devil is in the details. Depending on your triac, a 40W lightbulb might not be enough load to satisfy the minimum holding current. As well, timing is critical - triacs are relatively slow and you need to consider giving the triac enough time to turn off. To give a concise answer, we’ll need to see things like a schematic, code and actual timing. \$\endgroup\$
    – Kartman
    May 20, 2023 at 16:32

2 Answers 2


Neutral is not material to functionality here. Your circuit lacks the snubber, any other differences? Do you have pin 5 (substrate) on the 3021 open?

Your trigger current for the 3021 is pretty weak, the datasheet says as much as 15mA may be required (more at lower temperatures). You're giving it maybe 5mA on a good day. Your trigger pulses need to be of adequate duration.

I trust you know that if either opto is bridged in some way you could hurt or kill yourself and/or destroy your computer...

  • \$\begingroup\$ Thanks for the comments. Schematic does show 3021 but it's actually 3042. I also had to remove snubber altogether, because with it, triac never turns off without load connected. PIN5 is open on 3042. \$\endgroup\$
    – zdravke
    May 21, 2023 at 7:40
  • 1
    \$\begingroup\$ The MOC3042 is a zero-crossing optoisolator. That is a material difference- it will only work with the random kind. \$\endgroup\$ May 21, 2023 at 15:03
  • \$\begingroup\$ Tested with 2.5kW pool heater submerged in water, with led on it - same flicker on the led. No flicker when there is no load, scope graphs look clean. \$\endgroup\$
    – zdravke
    May 21, 2023 at 19:36

zdravke posted about this on another forum where, after a chance comment, it transpired that he was attempting to do phase angle control using a zero-crossing opto-isolator driver i.c.

Robert Wall, Chartered Electrical Engineer

  • \$\begingroup\$ Link to forum post? \$\endgroup\$ Jun 2, 2023 at 21:38

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.