2

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.

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 ?

  • 2
    the video uses an incandescent lamp ... try using the same .... also, a 5 kHz refresh rate is not necessary – jsotola Oct 13 at 0:17
  • 1
    Here is the LED spec : ledvance.com/appsinfo/pdc/… Coming back later to answer to @tlfong01 :) – Milow Oct 13 at 9:26
  • 1
    @tlfong01Question: is your mains power 50Hz or 60Hz? --> 50Hz. Are you sure the timing calculation in your code matches your mains frequency? --> Not at all ! Also, your answer show that the dimmer take a 200V input, I can't find this information in the specs. Are you sure about this value ? – Milow Oct 13 at 9:47
  • 1
    @Milow The LED specs state non-dimmable. Perhaps see if the instructable works with a normal lamp. – joan Oct 13 at 11:00
  • 1
    I thought every LED were dimmable... Ok. What does "Not dimmable" exactly mean ? Because I can dim this LED, the result is just not so good as expected. – Milow Oct 13 at 12:41
2

Finally, as said @Joan, I just had to use a dimmable LED.

To sum up what I found on internet : not all LED are dimmable. Even if you can dim a non-dimmable LED, it's still a bad idea because the LED might not made for this use. It can lead to several problems : 1. the dim can be unstable, and 2. it can cause heating problems.

-2

Question

I am using Rpi GPIO 18 PWM control to dim a 7W AC LED lamp.

led lamp

(A) Why there is a weird dip at duty cycle 85%?

(B) Why dimming not linear?

(C) Why use PWM frequency 5kHz?

(D) Why limit duty cycle to 86%?

(E) Why LED not completely switch off at duty cycle 0%

/ to continue, ...


Answer

(1) Short Answers

(A) There is no reason for a dip. Your program might be buggy. Try my bug free Rpi GPIO PWM python programs! :) (Refs 5, 6).

(B) Dimming not linear because your eyes are logarithmic, which is non linear.

(C) There is no reason to use PWM frequency 5kHz. AC mains frequency is 50/60Hz. So a "sampling" frequency 10 times of that should be flickering free. Try 1 kHz and try and error a pleasant frequency for your eyes only.

(D) There is no reason for a 86% duty cycle limit. Try and error higher. Nothing will explode.

(E) Perhaps there is sort of a "dead band" at AC mains voltage cross over. As soon as zero cross is detected, it take a little bit of time to tell the triac to cut off off current (just guessing, not very sure).

(2) Setup Mains AC Current Dimmer for Testing and Calibration

I would suggest to test and calibrate the dimmer in two steps:

(A) Use a type A (logarithmic) potentiometer.

(B) Use a python program to setup Rpi GPIO in PWM mode to control the dimmer.

Notes

Actually you can by hand use a jumper wire to connect Vcnt terminal to 3V3, Ground to see if dimmer is completely on and off. You can also use a cheaper square wave generator such as NE555 to control the dimmer. Using a digital pot is better than GPIO PWM because digital pot memorizes its setting.

dimmer

/ to continue, ...


References

(1) MPDM V4.1 Documentation

(2) Universal AC MAINS Dimmer MPDMv4.1 Catalog- US$17

(3) Universal AC MAINS Dimmer MPDMv4.1 Operation

(4) MPDM Triac Operation

(5) Rpi PWM GPIO pin #18 python program Example 1- tlfong01

(6) Rpi PWM GPIO pin #18 python program Example 2 - tlfong01

(7) LED Spec

(8) AliExpress RGB LED Bulb AC 110V 220V LED Lamp with IR Remote Control Dimmer - US$4

(9) RobotDyn AC Light Dimmer Module, 3.3V/5V logic, AC50/60Hz, 220V/110V

(10) AliEXpress RobotDyn AC Light Dimmer Module, 3.3V/5V logic, AC50/60Hz, 220V/110V

(11) BT137 Triac, 500V, 8A full sine wave - Philips

/ to continue, ...


Appendices

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


Appendix D - MPDM Traic Operation Explained - NetEvo

Triac operation


*Appendix E - Dimmer Testing Program (Version 3 ESP8266 LUA Version)*

References

http://esp8266-projects.org/2015/05/mpdmv3-wifi-mains-power-dimmer-switch-html/

https://www.youtube.com/watch?time_continue=6&v=kw8u4zBOIRs

https://www.youtube.com/watch?v=mQ5bhTV9Uu8

-- *** 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

Appendix F - Dimmable and Non-Dimmable LED Lamps emphasized text

Many retrofit LED lamps are sold in two versions; dimmable and non-dimmable. You will need to choose the correct type for your lighting circuit.

Dimming LED lamps can save energy and changes the visual appearance and mood of your space. You can use a dimmable LED lamp in a non-dimmable circuit.

You should NOT use a non-dimmable lamp in a dimmable circuit as it may cause damage to the lamp and or circuit.

Integral lamps are clearly marked as dimmable or non-dimmable on the packaging and on the lamp.

Matching old and new

Most dimmers installed today are designed to be used with high-power circuits to drive traditional filament lamps which were all quite uniform and dimmable by just a voltage change.

LED lamps on the other hand are low-power and more complex. An LED bulb is a solid-state product that has built in circuitry (called a driver) that takes high-voltage AC input current and converts it to low-voltage DC current to drive the LEDs. Furthermore driver specifications are not uniform across the LED industry.

They are many different types of dimmers installed in homes and offices of various specifications (e.g. resistive; leading-edge and trailing-edge and electronic). So when using new LED lamps with existing dimmers there is a matching of old technology with new which can be challenging.

The driver in dimmable LED lamps may work with many types of dimmer but not all, for instance LED lamps tend to work better with trailing-edge dimmers rather than leading-edge dimmers, but an existing dimmer may have a minimum load that is too high for an LED lamp, e.g. A 60W filament lamp may use a dimmer that has a minimum load of 25W the replacement LED has a power rating of 6.5W - below the level required by the dimmer. Dedicated LED dimmers have a very low minimum power rating.

The dimming experience can be different with LED. Overall the LED dimming performance is regulated by the capability of the LED driver/chip and the compatibility of the dimming circuit. Since there are a huge number of possible combinations of lamps and dimmer, it is very difficult to produce an LED lamp that works in all dimming environments.

LED currently have a lower dimming range than a filament lamp –

LEDs currently dim down to about 10% of the total light output whereas filaments may go down to 1-2%.

Low-voltage transformers as used with MR16 12V spotlights also add to the complexity

Some of the issues that may occur when a dimmer is incompatible with an LED lamp are:

Flickering - Lamps will flicker (can also occur if a non-dimmable lamp is used)

Drop-out - No light output at the end of the scale

Dead travel - When the dimmer is adjusted there is no matching change in light output (light may not dim to acceptable level)

Not smooth - Light output may not go from dim to bright linearly

Multiple lamps - issues may become apparent when multiple lamps are added

Damage or failure - LED driver, circuit or LED is damaged or fails.

Load below minimum - The power load of the LED lamp is below the minimum required by the dimmer

Mixed models- Different models of LED will likely have different drivers - since drivers behave differently this could result in dimming issues.

What can I do about dimming LED bulbs?

Ideally upgrade your dimming circuit with good quality dimmers designed for LED - easy to do for new LED installations. This is a good investment for the lifespan of your LED lamp.

Make sure you purchase the correct dimmable or non-dimmable LED for your type of circuit

Use a compatible dimmer - We recommend using specific LED dimmers from "VARILIGHT"

Change your circuit from dimming to non-dimming if not used much

Remove transformers used with 12V MR16 lamps and convert to 240V GU10 lamps in the same fitting by changing the lamp holder (should be completed by an electrician)

You should consider buying the same model and brand of LED lamp for all the fittings in an area of a room (all lamps will have the same driver)

Invest in brands that have a testing lab and use high quality dimming chips -like Integral LED. Many cheaper quality bulbs do not use proven dimming components and for the small difference in price it's not worth the hassle.

It would also be a good idea to buy spares - LED technology (as with other technologies such as mobile phones) is always improving and changing.

Dimmable bulbs will work with non-dimming circuits (Non-dimmable bulbs will NOT work in dimming circuits). Since LED bulbs last a long time and if you are thinking of upgrading to a dimmable circuit in the future it is worth initially considering dimmable bulbs.


End of Answer

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.