I use a dimmer module connected to an ESP07 which has Node MCU firmware.

I'm using the Z-C interrupt to skip sinusoidal pulses, however I only obtain flickering instead of dimming. The light is bulb is halogen based so it's dimmable.

Below is the code that I'm using. Do you have any idea what I should investigate?

--The Z-C pin
gpio.mode(2, gpio.INPUT)
--The PWM pin
gpio.mode(5, gpio.OUTPUT)

gpio.write(5, gpio.LOW)
pwm.setup(5, 1000, 0)

counter = 0;

local function zc_callback(level, pulse)

    counter = counter + 1;
    counter = counter % 10;

    if (counter == 0) then
        pwm.setduty(5, 1023)
        pwm.setduty(5, 0)

gpio.trig(2, "low", zc_callback)

You seem to be using PWM to try to control the dimmer. That's not how it works.

enter image description here

Figure 1. Phase-controlled dimming is done by turning the triac on at some point in the mains half-cycle.

enter image description here

Instead you should measure the time between zero-crosses at (1), start a delay at the next zero-cross and then turn the opto-triac (2) on. This will trigger the triac (3) which will stay on until the next zero-cross when the delay and triggering process can be repeated.

The longer the delay the dimmer the light.

|improve this answer|||||
  • \$\begingroup\$ Tried this, I understand the logic, but the result is that the light still flickers. This is my new code: pastebin.com/85vaZs21 . Anyway, I'm wondering why does this module have a PWM pin, a 0/1 pin would have been enough \$\endgroup\$ – Mihai Ionuţ-Cosmin Jul 29 '18 at 9:48
  • \$\begingroup\$ (1) Your new code is also using PWM which means that you didn't understand my answer. (2) The module does not have a PWM pin. There are four labelled 'DIMMER', 'ZEROC', 'GND' and '3V3'. The DIMMER pin is a 0/1 input. \$\endgroup\$ – Transistor Jul 29 '18 at 13:10
  • \$\begingroup\$ I got the same module and it does have a PWM pin instead of the DIMMER pin one you mention. Not sure if that means the module is only capable of PWM or not, but it's not working for me either. \$\endgroup\$ – diegoreymendez Aug 12 '18 at 3:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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