AC Power Dimmer Notes

Active today
Viewed 12 times

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


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

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.

Here a graph to better illustrate the situation. Graph illustrating the luminosity of a led depending on the duty cycle

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 ?

  • the video uses an incandescent lamp … try using the same …. also, a 5 kHz refresh rate is not necessary – jsotola 2 hours ago
  • @Milow, Ah, let me see. I woke up this gloomy Sunday morning and found your question sun shining. First thing first, let me introduce myself. I am a smart home learning guy, but never heard of what you are talking about, a Rpi PWM controlled AC mains dimmer. So I am losing face and my bad friends are LOL at me. To save my face, I am going see what is going on and if I can make an answer. To start with, I watched the YT and found it good, but sadly this 2 year old tutorial has collected only 25 thumbs up, … 😦 – tlfong01 1 hour ago    
  • @Milow, “Why dimming nbot linear?” Well, perhaps the stupid human eyes are like the ears, highly non linear, actually exponentially evolved to have become logarithmic! 🙂 – tlfong01 59 mins ago    
  • @Milow, “Why max DC 86%, not 100%?” This has something to do with the characteristics of the AC main voltage which is much complicated than DC. (1) AC voltage is sinusoidally nonlinear, and change polarity every cycle (50Hz or 60Hz). And a traic (sort of bidirectional current switch) is used to cut power. A triac has two current switches, one each to switch on current at a particular point in time of the positive or negative phase. It is rather tricky to detect the cross over point (zero detection) and then use a “stop watch” to cut current according to the stupid human’s wishes, … – tlfong01 14 mins ago   
  • @Milow, I am getting off topic and diverting too far into electronics engineering discipline, which makes a lot of trade off’s to finally decide that it is cost effective and stupid human eyes pleasant (no flickering etc) to decide the max dc to be 86% (just an example). Anyway, I will now go back to the stupid human’s buggy brain’s creation – the buggy python program. Stay tuned to my answer! 🙂 – tlfong01 5 mins ago   Edit   



How come my Rpi PWM controlled AC dimmer on 7W LED has a weird dip at duty cycle 85%?

dimmer dip

/ to continue, …


/ to continue, …


(1) MPDM V4.1 Documentation

/ to continue, …


Appendix A – WARNING!! You will play with LIVE MAINS!! Deadly zone!! – NetEvo

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

mdpm v4

Appendix C – Zero detection and triac switching schematics

triac schematics

End of Answer

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: