I’m trying to dim a 7W LED with a Raspberry Pi Zero for home automation. However it doesn’t work as expected. I followed this tutorial : https://www.youtube.com/watch?v=wqY4-gHqvZI . I have the exact same connections between my raspberry and my led and I also have the same dimmer. I tried their test code that is supposed to dim the light bulb using the Pigpio hardware_pwm() function (documentation : http://abyz.me.uk/rpi/pigpio/python.html#hardware_PWM).
The Python script used to the test is :
import pigpio GPIO=18 pi = pigpio.pi() if pi.connected: print("Connected to pigpio daemon !\n") dm = 0 while dm < 860: dm = input("Enter Dimmer Value: ") dm = int(dm) pi.hardware_PWM(GPIO, 5000, dm*1000) # 5000Hz dm*1000% dutycycle print("\nOut of range. Exiting...") pi.hardware_PWM(GPIO, 5000, 860000) # 5000Hz 95% dutycycle pi.stop()
For my case, the led is acting strangely. With a 5000Hz frequency, changing the duty cycle from 0% to 70% doesn’t change it’s luminosity, 70% to 86% reduce the luminosity, 86% to 95% increase it and 95% to 100% reduce it again. But the led is always turned On, even if the duty cycle is at 100% the led emits a little light.
The Python code used is from the youtube tutorial, do someone understand why the max duty cycle used is 86% ?
Why is the dimming not linear ?
And why the led cannot be totally turned Off using a 100% duty cycle ?
How come my Rpi PWM controlled AC dimmer on 7W LED has a weird dip at duty cycle 85%?
/ to continue, …
/ to continue, …
/ to continue, …
WARNING !!! If you don’t have any experience and are not qualified for working with MAINS power I will not encourage you to play around!.
The author takes no responsibility for any injury or death resulting, directly or indirectly, from your inability to appreciate the hazards of household mains voltages.
The circuit diagrams are as accurately as possible, but are offered with no guarantees whatsoever.
There is no guarantee that this design meets any Rules which may be in force in your country so please check before your local rules/regulations.
Appendix B – MPDM v4.1 Universal AC Current Dimmer
Appendix C – Zero detection and triac switching schematics
Appendix D – MPDM Traic Operation Explained – NetEvo
Appendix E – Dimmer Testing Program (ESP8266 LUA Version)
-- *** Define used GPIO pin *** outpin=7 -- Select Triac Command pin - GPIO13 gpio.mode(outpin,gpio.OUTPUT) gpio.write(outpin,gpio.LOW) -- Triac OFF inpin=6 -- Zero crossing detector input - GPIO12 gpio.mode(inpin, gpio.INT, gpio.PULLUP) -- attach interrupt to ZCD -- *** Zero Cross *** function zero_cross() dt = 76*dim --print("Zero cross detected!") stat = "ON" tmr.delay(dt) -- Firing delay time calculated above gpio.write(outpin,gpio.HIGH) -- Triac ON - Zero cross detected tmr.delay(100) -- Triac ON - Propagation time gpio.write(outpin,gpio.LOW) -- Triac OFF - let's be sure it's OFF before next cycle tmr.wdclr() return stat end -- *** Fading function for testing mode *** function fading() if(dim_up==1) then dim=dim+1 else dim=dim-1 end if(dim < 10) then dim_up=1 dim=10 else if (dim > 120 ) then dim_up=0 dim=120 end end print("Dimmer level : " .. dim) print("Fading mode : " .. dim_up) tmr.wdclr() end -- *** Main *** dim = 120 -- Dimmer level - smaller value is brighter dim_up=0 -- Fading direction - for test run gpio.trig(inpin, "up", zero_cross) -- ZCD interrupt attached - trigger on falling edge tmr.alarm(0, 100, 1, function() fading() end) -- timer for testing mode -- *** Setup/Testing Notes *** -- For testing, just save the code on ESP as ‘dimmer.lua‘, restart ESP and run: -- dofile("dimmer.lua") -- Start the Dimmer Testing mode -- If you want the MPDMv3 software to start automatically when your CBDB module starts or reboots, then you neet to create and add some lines in your ‘init.lua‘ file: -- dofile("dimmer.lua") -- Start the Dimmer Testing mode
End of Answer