ming huang
Published © GPL3+

Universal Power Variator

This project is a continuous variator of supplied power for power tools, lights or heating. Works universally for AC or DC power supplies.

BeginnerFull instructions provided20 hours4,264
Universal Power Variator

Things used in this project

Hardware components

male main power plug
×1
female main power plug
×1
600V CoolMos C7 Gold
×2
Arduino UNO
Arduino UNO
×1

Story

Read more

Schematics

How to switch DC ON

Principle for switching DC ON

coolMos pinout

The pin-out is referenced in electronics schematics

schematics of power variator

overall schematics of the project

How to switch AC ON - positive half-cycle

principle of conduction during AC positive half-cycle

How to switch AC ON - negative half-cycle

principle of conduction during AC negative half-cycle

zero crossing detection

principle of zero crossing detection on AC

Code

Varying DC power supply

Arduino
This code periodically and endlessly increase then decrease the supplied DC power. When used on AC power, only half of the cycle is passed, consequently the max power is only half of the max of supplied power.
int G1 = 9;           // the PWM pin connected to gate of CoolMos-1
int G2 = 6;           // the PWM pin connected to gate of CoolMos-2
int S = 7;            // the digital out of '0' connected to the Driver Source of both CoolMos-1,2
int brightness = 0;   // how much power on the load (e.g. lamp)
int increase = 5;     // how many points to increase the power by

// the setup routine runs once when you press reset:
void setup() {
  // declare pin 9/6/7 to be an output:
  pinMode(G1, OUTPUT);
  pinMode(G2, OUTPUT);
  pinMode(S, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  G2 = 0;
  S=0;
  
  // set the brightness of pin 9:
  analogWrite(G1, brightness);

  // change the brightness for next time through the loop:
  brightness = brightness + increase;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness <= 0 || brightness >= 255) {
    increase = -increase;
  }
  // wait for 30 milliseconds to see the dimming effect
  delay(30);
}

Varying AC power supply

Arduino
This code cycles the supplied power between minimum and maximum with one incrementation or decrementation per second
int G1 = 9;           // the PWM pin D9 connected to gate of CoolMos-1
int G2 = 6;           // the PWM pin D6 connected to gate of CoolMos-2
int S = 7;            // D7 with '0'level is connected to the Driver Source of both CoolMos-1,2
int LINE = 0; // Analog input A0 is used to sense zero crossing
int brightness = 0;   // how much power on the load (e.g. lamp)
int increase = 5;     // how many points to increase the power by
int ac = 0;           // 0: negative half-cycle;  1: positive half-cycle
float v=0;
int cmd = 1;          // current command to turn on or off the power. 1: turn-on; 0: turn-off.
int newcmd = 1;       // new command to turn on or off the power. 1: turn-on; 0: turn-off.

// the setup routine runs once when you press reset:
void setup() {
  // declare pin 9/6/7 to be an output:
  pinMode(G1, OUTPUT);
  pinMode(G2, OUTPUT);
  pinMode(S, OUTPUT);
  pinMode(LINE, INPUT);

  G1 = 0;
  G2 = 0;
  S=0;

}

void turnOff() {
    G1 = 0;
    G2 = 0;
    S=0;  
}

void turnOnNextCycle() {
  // wait for zerocrossing
  if (ac=0) { // currently in negative cycle
    while (v<0.5) {
      v = analogRead(LINE)*5.0/1024.0;
      if (v<0.5) continue;  // no crossing
      delay(1); // 1ms
      v = analogRead(LINE)*5.0/1024.0;
      if (v<0.5) continue;  // no crossing
      break; 
    }
    ac = 1; // zero crossed, now in positive cycle
  } else { // currently in positive cycle
    while (v>=0.5) {
      v = analogRead(LINE)*5.0/1024.0;
      if (v>=0.5) continue;  // no crossing
      delay(1); // 1ms
      v = analogRead(LINE)*5.0/1024.0;
      if (v>=0.5) continue;  // no crossing
      break; 
    }    
    ac = 0; // zero crossed, now in negative cycle
  }

  if (ac == 1) {
    // pulse on G1
    analogWrite(G1, brightness);
    G2 = 0;
  } else {
    // pulse on G2
    analogWrite(G2, brightness);
    G1 = 0;    
  }
}
// the loop routine runs over and over again forever:
void loop() {
  int cntAcCycles = 0;
  if (newcmd != cmd) { // command has changed. Initialization.
    G1 = 0;
    G2 = 0;
    S=0;
    ac = 0;           // 0: negative half-cycle;  1: positive half-cycle
    v=0;
  }
  if (cmd == 1) {
    turnOnNextCycle();
    // change the brightness every second: 50 cycles per second for 50Hz
    if (++cntAcCycles > 50) {
      cntAcCycles = 0;
      brightness = brightness + increase;
      // reverse the direction of the fading at the ends of the fade:
      if (brightness <= 0 || brightness >= 255) {
        increase = -increase;
      }  
    }
  } else if (cmd == 0) {
    turnOff();
  } 

}

Credits

ming huang

ming huang

7 projects • 7 followers
IOT dev

Comments