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