Tuesday, April 12, 2016

MPDMv4 - Universal AC MAINS Dimmer

UPDATE !!        Fixed broken Tindie link from below, now should be OK      UPDATE !!

--------------------------------------------------- DISCLAIMER --------------------------------------------------
WARNING!! You will play with LIVE MAINS!! Deadly zone!! 

      If you don't have any experience and are not qualified for working with MAINS power I will not encourage you to play arround!. The author take 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.
                                                             Creative Commons License

MPDMv4 by ESP8266-Projects.com is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.  


    For any new orders/requests please feel free to use as usual: tech at esp8266-projects.com. 
    MPDMv4 Boards are also available on Tindie: AC MAINS Dimmer - MPDMv4


  The next step in the MAINS Power Dimmer/Switch series.

   One of the main problem that people has been complained about was the fact that a simple MAINS Power Dimmer/Switch unit like the basic one presented last year is using sometime too much resources from a already overloaded application MCU/processor:

MPDMv3 - MAINS Dimmer/Switch with Phase detection

   One of the scenarios, directly related with ESP8266 is about the limited timers capabilities that you have. For example,  if you want to implement a proper web server to directly serve your webpages from ESP8266 you are automatically using one timer. If you want to start using the second one for your ZCD processing ...well...it's becoming very tricky. Very.

   Don't uderstand me wrong, a bigger, better MCU can do it probably very well, but even then if you have the chance to free some resources easily, do it!. And  I really cannot see a ESP8266 acting as a App MCU (webserver, data logger, MQTT client, etc, etc) and doing reliable also other demanding functions as  Processing Zero Crossing Detection.


    I can see only one, and it is a lesson learned many years ago: keep your real-time processing functions away from your Application MCU/Processor. To do that we just need to move the ZCD processing function from the ESP8266/whatever MCU you want to the MPDM Driver itself:

MPDMv4 - MAINS Phase detection and ZCD processing

   What means that? means that in this new configuration our ESP8266 will be free from any type of real-time ZCD processing that is related with the MAINS Dimming process, you just  need to send to the MPDMv4 driver a voltage (Vcontrol) in a pre-established range (0-3V for example) that will correspond with different desired Dimming levels.

 What we have obtained? A UNIVERSAL MAINS Power Dimmer driver that can be used with any MCU you might want or even no MCU at all. You can dimm it even with a simple Potentiometer at input, no programming, no code, no nothing!!

PURPLE  - Phase detector output
BLUE      - Reversed phase signal (normalised)
Yellow     - Triac Driver CMD signal (PWM)

Vcontrol = 0, CMD Duty cycle=6%

Vcontrol = 2V, CMD Duty=50%

Vcontrol = 2.8V,  CMD Duty=96%

  How can be done that? Easy. Use PWM or a DAC, your choice. For ESP8266 I will recommend you to use a DAC, like the MCP4726  or, why not , the MCP4728, for a full 4 Channel MAINS Dimmers solution. PWM in case of the ESP8266..let's say that is has some limitations that you will discover very soon that you don't like :)

The mains advantages of using DAC?


1. Very low to zero overhead on the App MCU
2. High precision (DAC from above are 12 bit!! - 4096 levels of dimming!!)
3. You can use the "set-and-forget" technique using DAC internal nonvolatile memory (EEPROM) and have the same level on the next power-off/on cycle.



    As the only functional difference between the previous MPDMv3 MAINS Dimmer and the new MPDMv4 is the presence of the ZCD function onboard, basically, without some small bits and pieces around like the MOV protection circuit, you can see it exactly as it is: a MPDMv3 with a ZCD circuit onboard:

MPDMv3 - Phase detection and Triac control

Zero crossing detector circuit

   MPDMv4 PCB:


   As you can see from the above picture, it was carefully designed with proper MAINS isolation from the rest of the driver, you can see even the extra isolation slots done for a even bigger Creepage distance.

And because I know this terms still creates some confusion, short definitions below:

CLEARANCE is the shortest distance in air between two conductive parts.
CREEPAGE distance means the shortest distance along the surface of a solid insulating material between two conductive parts.

 A creepage distance cannot be less than the associated clearance so that the shortest creepage distance possible is equal to the required clearance. However, there is no physical relationship, other than this dimensional limitation, between the minimum clearance in air and the minimum acceptable creepage distance.

And the new, freshly baked result:

MPDMv4 - MAINS Power Dimmer/Switch with Phase detection and ZCD Processing

Next time we will move on to the Software side, to see what is going on with our Webserver interface & stuff.


forlotto said...

I want to drive directly with espbasic on a nodemcu why will this not work? http://www.esp8266.com/viewtopic.php?f=40&t=7891 I have it working with a similar circuit but I have an issue of flicker at anything below full on.

Need your assistance here if possible I have reached out to you I believe on every website I see you on.

Tracker J said...

Hi forlotto,

I have no experience at all with espbasic coding and available functuons but as long as you can provide a proper VCNT signal to the MPDMv4 Board (by PWM or DAC or whatever other digital-to-analog function you might have available in the espbasic) it should work OK.
You don't need to do in software any kind of Phase detection/ZDC at all. This is the whole point of the MPDMv4 board, to make it deadly simple to be used.

forlotto said...

lol basic just won the award for best project on the esp8266 forums may want to check it out only 2 devs currently working on the project but I am sure the more folks that jump in the better it will become.. I am certain if you have any programming knowledge at all you will find basic super simple to use.

The example code I use for my dimmer is as follows it provides 5 buttons for different levels of dimming as well as a scaled dimming that will bounce through different levels of dimming via pwm if you checked out my response you would see that I am aware of what you have told me already and I used a similar circuit. The circuit was made by thewp122 before this circuit was released. Krida also has an interesting 3bit circuit where you can just use 3GPIO's depending upon their state 3bit it sets different intensity levels which requires no pwm control at all I like this solution as well because there is no worry about the pwm signal you just set pins to high or low to obtain the level of dimming you wish. This would likely eliminate the flicker issue I am having.

Come on over and join us run some basic once I promise you'll love it!

Tracker J said...

Hi forlotto,

Joined you on the esp basic forum, we can continue the discussion also there.

forlotto said...

Excellent I really appreciate all your hard work I will be placing an order for a couple of units here to start with look forward to getting them in the mail is there a specific place you would suggest ordering from or should I use tindie ?

Tracker J said...

Hi forlotto,

For more details you can contact me directly at tech (at) esp8266-projects (dot) com

Rak said...

Can you give the name / type of MOV protection circuit and IC2 ?

Tracker J said...

You can use for MOV a 275VAC one. Important is to have a proper size/type of MOV paired with the type of Fuse you use. The idea behind is to blow fuse asap when needed.

Bad size/type of Fuse or bad quality one and the results can be unacceptable. Size/type of the Fuse really depends on the Load that you want to have.

IC2 is a standard AC optocoupler like the SFH620 presented before in MPDMv3 Article.

Rak said...

Thank you for your fast reply. Yes, in MPDMv3 IC2 is a SFH620, but in new MPDMv4 SFH620 is a IC3, and what is IC2? Some type transistor? :)
Are equivalent chips IC1 and IC2 in DIP package?

Fabricio Stein said...

Hi, can you send me a components list? There's some things that on the schematics didn't get quite clear.

Сергей Романов said...

IC1 - timer 555
IC2 - dual transistor BC847BPN
excellent use 555 timer!

Tracker J said...

I will do a complete BOM list for the board, just need some time, busy like hell these days :)

Unknown said...


Are you releasing the board on dirty PCBs like the last version?

Tracker J said...


For now no, but full kit is already available on tindie. I was asked so many times for providing full kits, not PCB's only, so, done it :)

Unknown said...

I agree that some people may prefer a Kit but if you want to make 10 pieces it is way too expensive.

Tracker J said...

Depends on how do you define expensive. Good quality parts from trusted adn certified sources are not so cheap. If you need 10 or more you can contact me directly at tech (at) esp8266-projects (dot) com.

Yakman said...

I looked at AN954 from your previous article and still don't see an easy way to provide 200 ma of DC directly from the mains to power the ESP8266.

forlotto said...

Wow this thing slays all!

Works excellent I have been able to do some testing finally this weekend I can say that it is one of the smoothest flicker free dimmers I am using 100w equivalent Great Value Daylight LED bulbs Dimmable from Walmart. Excellent dimming nice clean lighting. All other dimmer boards I have tried I've spent hundreds of dollars doing testing until finally I found something that works!

Thanks Tracker J I will put out a video as soon as I upgrade my code a bit as well as my firmware I am going to go ahead and do a real time example people will be complete fools not to purchase this product. One thing I will say is make sure your bulb is indeed dimmable and not just a three way bulb or non dimmable or you will have issues. Works great with halogen, dimmable CFL, dimmable LED, any bulb that is truly dimmable.

Gimme about a week or so and I will put together a good post and video on how I went about everything.

Tracker J said...

Hi Yakman,

For such a power consumption as needed for ESP8266 to proerly work with WIFI on you can use a small SMPS PSU.

Tracker J said...

Hi forlotto,

I am very ahppy to see that your last experiments were successful! Yes, you have right, beside the MPDMv4 board (or any other dimmer board out there) you NEED a PROPPER Dimmable lightbulb. Unfortunatelly market is flooded with cheap ones, fake presented as dimmable. You can have the best dimmer in the world but if your LED lightbulb is not dimmable the results will be at least dissapointing. From my research 90% of the LED lighbulbs comming under generic names from Chine are NOT dimmable. Their desig have behind a standard constant current source with a wide MAINS AC input interval (85-265VAC) that make them working on both US/EU 110/240 VAC MAINS lines but not dimmable at all!

Rak said...

can you give me a full scheme and full BOM?

forlotto said...

I went a step further and made the adoption of this totally simplistic using espbasic. Excellent product by the way!

Visit http://www.esp8266.com/viewtopic.php?f=41&t=10958

for more information

Unknown said...

Thanks for the excellent design and implementation. Please share schematics and BOM for MPDMv4.

Unknown said...

Thanks for the excellent design and implementation. Please share schematics and BOM for MPDMv4.

Post a Comment