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

A more refined driver example for the MPDMv4 AC MAINS Dimmer for Arduino Mega that will let you to adjust also the PWM frequency :

/*
MPDMv4 Ac Dimmer - PWM Library example.
 The library allows for a frequency range from 1Hz - 2MHz on 16 bit timers and 31Hz - 2 MHz on 8 bit timers. When 
 SetPinFrequency()/SetPinFrequencySafe() is calvcnt, a bool is returned which can be tested to verify the 
 frequency was actually changed.
 
 This example runs on mega and uno.
 
 modified 28 Sept 2017
 by TJ for esp8266-projects.com AC MAINS Power Dimmer MPDMv4 Driver
 This example code is in the public domain.
 */

#include <PWM.h>

//use pin 11 on the Mega instead, otherwise there is a frequency cap at 31 Hz
int vcnt = 11; // the pin that the MPDMv4 VCNT Voltage control pin is attached to
int brightness = 0; // how bright the Lighbulb is
int fadeAmount = 5; // how many points to fade the VCNT by
int32_t frequency = 2400; //frequency (in Hz)

void setup()
{
 // initialize the serial communication:
 Serial.begin(9600);
 //initialize all timers except for 0, to save time keeping functions
 InitTimersSafe();

//sets the frequency for the specified pin
 bool success = SetPinFrequencySafe(vcnt, frequency);
 
 //if the pin frequency was set successfully, turn pin 13 on
 if(success) {
 pinMode(13, OUTPUT);
 digitalWrite(13, HIGH); 
 }
}

void loop()
{
 int brightness;
 // check if data has been sent from the computer:
 if (Serial.available() > 4) {
 brightness = Serial.parseInt();
 Serial.print("Command received : ");
 Serial.println(brightness); 
 // set the brightness of the Lightbulb
 // use this functions instead of analogWrite on 'initialized' pins
 pwmWrite(vcnt, brightness); 
 } 
}

 

As you can see above, the only thing that you need is to provide a proper voltage control on the MPDMv4 VCNT pin, all the other stuff, phase detection, ZCD, etc, are done by the MPDMv4 module itself.

It is properly working with ESP8266, ESP32, Arduino UNO, Mega, etc.

Happy breadboarding,
TJ.

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

———————————————————————————————————————————

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

 


Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

AC Dimmer

MPDMv7.5 Arduino IDE driver example

For a more detailed description please take a look at the Part 1: MPDMv7.5 AC Dimmer devboard overview MPDMv7.5 AC Dimmer devboard is also available on Tindie Store A very simple MPDMv7.5 Arduino IDE driver Read more…

AC Dimmer

AC Dimmer DevBoard – MPDMv7.5 – Part 3 – DAC

For a more detailed description please take a look at the Part 1: MPDMv7.5 AC Dimmer devboard overview MPDMv7.5 AC Dimmer devboard ESP Basic program example for the Extra DAC version configuration: address = 96 Read more…

AC Dimmer

AC Dimmer DevBoard – MPDMv7.5 – Part 2

For a more detailed description please take a look at the Part 1: MPDMv7.5 AC Dimmer devboard overview MPDMv7.5 AC Dimmer devboard ESP Basic program example for the basic version configuration: 'write("starttimer",10) cls 'VCNT GPIO Read more…