Tuesday, April 12, 2016

MPDMv4 - Universal AC MAINS Dimmer

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

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


And the story behind:


  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.

johnjore said...

Hi! Looks really nice. I'm thinking of replacing my existing dimmers with this one and hooking up to OpenHAB, but not sure if it would fit inside the electric plastic boxes in the walls.

Can you share the dimensions?

And just to be clear, if I have existing dimmers from the local DIY store working with my existing LED lights, then this one should also work?


Tracker J said...

Hi Johnjore,

The size of the MPDMv4 board is about 5x5cm.

Regarding LED lighbulbs, as long as they are true dimmable ones should work without any problem.

They are so many types around that nobody can give you a true 100% guarantee that that specific model is working OK, you need to run a test with or you can send it to me and I can run a test and post the results.

Market is also flooded with fake "dimmable" ones, not only online Ebay, Amazon, etc but also clasic stores. I have teardown such a stamped "dimmable" lightbulb that was not working OK with the MPDMv4 and found inside just a simple 85-245VAC constant current driver. As you can imagine, as that driver will keep constant current from 85 to 245 VAC, is quite impossible to dim it properly.

Do you have 110/60Hz, or 240/50Hz MAINS power there? Where are you located?

johnjore said...

Hi and thanks for this, 240/50Hz. (UK/Australia) I've just placed an order for 4x of these.

Maziar Hafezi said...

Hi Tracker,

Is it possible for you to send the Schematics and BOM of the board for me ?

My email is : maziar.hafezi@gmail.com

Tracker J said...

Hi Johnjore,

Found it, your order is already in the processing queue :)

johnjore said...

Hi again. What's the input range on VCNT, 0-2.8V? And tolerance is 0 to 5V?

And Vcc is 3.3 to 5v?


Tracker J said...

Hi Johnjore,

For Vcc = 3.3V and a standard lighbulb of 100W the dimming interval is between VCNT=0V (FULL ON) to VCNT = 2.85-2.9V (FULL OFF).

You can take this values as guidance and adjust if is necessary for your own Lightbulb.

Might help to take a look also to the Youtube related Videos:

- Voltage Control explained: https://www.youtube.com/watch?v=pZvemdrVvrE

- CNTRL connector explained : https://www.youtube.com/watch?v=vLMtwuF5GQA

Happy breadboarding,

Tracker J said...

For Vcc=5V and the same standard lighbulb of 100W the dimming interval is between VCNT=0V (FULL ON) to VCNT = 4.35V (FULL OFF).

This is normal as the dutycycle proportions remains the same only the voltage levels changes from 3.3V to 5V.

Happy breadboarding,

johnjore said...

Hm.. don't think these work for my lights, 4x LED's, GU10 (5W each I think)

@ 0.00V, lights off
@ 0.01V, lights fully on,
@ 2.00V, lights fully on,
@ 2.80V, lights fully on,
@ 3.00V, light flickering, slight dimming

Vcc is 3.3V and I'm using PWM mode on pin D5 on the ESP8266.

The only technical details on my current dimmer is 40-400VA transformer, PRI 230-240V, 330W Max. This is a cheap component bought from the local DIY store and has no issues dimming the lights.

Any ideas?


Tracker J said...

Hi JJ,

I really must admit that I cannot fully understand your setup. Can you please explain a bit your setup components and wiring please. Some pictures will be also a great add.

Do you have some 240VAC true dimmable LED lightbulbs or they are some 12/24V ones connected thru a transformer? "Dimming" a transformer or another dimmer as a load for the dimmer board is not a very good idea and for a lot of reasons can end up with some magic smoke :)

Also I really hope they are better that de GU10 killing-machines Julian Ilett is playing with here: https://www.youtube.com/watch?v=keaE7QTKTYE

Happy breadboarding,

PS: you can contact me anytime directly at the usual: tech (at] esp8266-projects {dot} com.

johnjore said...

:) I can assure you that no magic smoke has (yet) escaped. I'll take some pictures tonight and move this offline.

johnjore said...

Turns out I managed to flip Vcc and VCNT, so I was effectively regulating Vcc, not VCNT... Not my finest hour. LED is a Philips 5.5W Dimmable LED, no issues there. Effective range for dimming was ~2.2V to ~2.5V on VCNT with Vcc @ 3.3V.

All good!


Tracker J said...

Hi JJ,

I'm happy to see that you found and fix the wiring problem and all OK now.

All the best & happy breadboarding,

Nabendu Maiti said...
This comment has been removed by the author.
Nabendu Maiti said...

What is the value of P1? there is no p1 on tindle board?

Ali Raza said...

Hi tracker J,

Can i get the schematic and complete BOM for the circuit?


Stefan said...

Will this dimmer also work with traditional (magnetic, thus with windings) transformer for halogen spots. Anybody tried?

Jens said...

My Dimmer does not work properly. I am using a normal 60 W bulb, and a 10K potmeter between GND and VCC. The lamp is fully on af VCNT at 0 and dimmers down to nearly 0. But at VCNT=VCC, the lamp starts to flicker at half. What can be wrong?.

Tracker J said...

Hi Jens,

You need to find your MPDMv4 Dimming interval. You should expect to have FULL light ON at VCNT = 0V and FULL light OFF at VCNT = about 2.8-2.9V. As soon as you are out of the Dimming interval you lost sync and will start flickering. Go slowly from VCNT=0V up and you will see it.

What's your VCC value? 3.3V? Also be sure that you have proper GND connection.

Jens said...

Thank's for your quick answer.
OK, I did not realize that the Dimming interval was not the full Range from GND to VCC. Problem solved. My VCC value is 3.3V, but I have also tried 5V with the same result.

Unknown said...

Hi There, would you mind sharing the schematic?

Ali Raza said...

I too have asked for it multiple times at this blog post and some others. Looks like the developer is not comfortable sharing the schematic.

Tracker J said...

Available schematics above, for both, phase detection and ZCD and also triac control.

Ali Raza said...

Hi trackerj,

thank you for your response, but the schematics are for V3 and not V4. There are also some other components on board like that IC2

jer said...

Hi Tracker, nice project!
Could this board work without neutral wire to AC IN? I try to think how to integrate it into a house electrical configuration behind wall switch where there is only phase wire but no neutral. Neutral wire is connected only on the light side.

Unknown said...

I'm trying to hook up to a basic ESP-01 using GPIO0 as PWM output. ESP refuses to boot in this mode as dimmer seems to be pulling GPIO0 low and entering programming mode on switch on.

vadiraj kaveri said...

Hi Tracker,
Can this Universal Dimmer be used to control Single-Phase Motor Speed Control? For example "Ceiling Fan" up to 75Watt at 230V 50Hz.


Tracker J said...

Hi Jer,

Thank you!.Can you please send/post your wiring to understand what's exactly your intededed setup.

Tracker J said...

Hi Unknown,

You might want to try to use other available GPIO as GPIO0 has that boot mode special function implemented by default.

Tracker J said...

Hi vadiraj kaveri,

It really dependson the type of the motor you have there: if is universal type or any other type declared dimmable with Triac dimmer units then will work without any issue.
For other types, you just need to test it and see if you obtain the desired results. For example for the induction type ones, might work partially or not work at all, to drive this type of motors by the book, you need a VFD.

Giacomo Tanganelli said...

Hi, can you share your "complete, all in one" schematic as well as the BOM file? It will be really appreciated.

Post a Comment