AC DIMMER USING M0C3021.


AC DIMMER USING M0C3021.

 I'd been messing around with low DC voltage projects for some time so wanted to experiment a bit with AC dimming controlled by a microcontroller.

This experiment was with phase control (as opposed to voltage modulation).

The idea is that you detect when the AC phase crosses zero volts (zero cross) at which point the triac in the circuit remains off for a certain period of time and is then turned back on by the microcontroller.  The longer it remains off then the less power the AC circuit gets and thus is more dim.

Theres lots of info online about the theory of all this.  E.g. AC Phase Control.

I looked around quite a bit online at various people having done the same sort of thing.  Here's one.  If what I did looks similar to someone elses work then chances are I had a look at it.  I also got some input from various sources.  My thanks to those people! :)

Here's the circuit I made for it:


And the board that I made based on the circuit:


Back of board after soldering:

Front of board after soldering components:

TESTING PART

First I controlled it with an arduino and here's the software for that.  I also controlled it from an ESP8266 module.

In this program I skip every 2nd zero cross detection and just wait out a poredetermined amount of time to fire it again.  This seemed to work better but I'll certainly need to revisit this in the future when I make a "real" version of this (which would include a varistor and fuse for safety and protection).

#define ZERO            2
#define GATE            3
 
#define GATE_DELAY      9
 
/* range 0 - 255 : 0 = off    255 = on */
volatile uint8_t  dim = 127;
volatile uint8_t skip = 0;
void setup() {

  pinMode(ZERO, INPUT_PULLUP);
  pinMode(GATE, OUTPUT);
 
  attachInterrupt(digitalPinToInterrupt(ZERO), dimmer, RISING);
 
  Serial.begin(9600);

}
 
void loop() {
  /* dim test */
  int i=0;
  for (;i < 256; i++){
    dim = i;
    delay(100);
    Serial.print("dim value: ");
    Serial.println(i);
   }
   for (;i >= 0; i--){
    dim = i;
    delay(100);
    Serial.print("dim value: ");
    Serial.println(i);
   }
}


void dimmer() {

  if (skip == 0){

      dim = 180;

    /* (1000ms / 120hz) = 8.33 */
    float waitMillis = (8.33 / 255) * (255 - dim);

    uint16_t waitMicros = (uint16_t)(waitMillis * (float)1000);
 
    delayMicroseconds(waitMicros);
 
    digitalWrite(GATE, HIGH);
    delayMicroseconds(GATE_DELAY);
    digitalWrite(GATE, LOW);

    delayMicroseconds(8330 - GATE_DELAY);
 
    digitalWrite(GATE, HIGH);

    delayMicroseconds(GATE_DELAY);
    digitalWrite(GATE, LOW);
  
    skip = 1;
  
  } else {

    skip = 0;

  }
  
}


Comments

Popular posts from this blog

LEDs control using nodemcu and ir remote.

NODE MCU HOME AUTOMATION.