User Tools

Site Tools


Regulating AC 230V

Triac regulator

Triac regulation is often used for ventilator regulation and in general for regulation of single-phase induction motors (e.g. drilling-machine speed regulator). Basic principle of this type of regulation can be seen on picture. Triac turns on after a certain time when sinusoidal voltage cross the zero point. So the voltage is “cut off”. That reasoned by lowering wattage. One disadvantage is that triac is source of electronic disturbance.

source of picture and another information.

For detection of moment when voltage crossing the zero point serves special family of integrated circuits. One of that family is H11AA1 (datasheet) in next schema:

Code and schema

Wiring is combination of circuit for zero point detection with H11AA1 and circuit for triak switching (like in switching topic) but with one important exception: instead of using otptotriac MOC3041 the optotriac MOC3021 is used. Because MOC3041 differs by switching in zero which means that this triac switch on just in moment when the voltage is zero (on switching side). Circuit will not work proprietly with MOC3041!!!

Code completely taken from arduino playground (here). You can find better explained this code on that side.

// AC Control V1.1
// This arduino sketch is for use with the heater 
// control circuit board which includes a zero 
// crossing detect fucntion and an opto-isolated triac.
// AC Phase control is accomplished using the internal 
// hardware timer1 in the arduino
// Timing Sequence
// * timer is set up but disabled
// * zero crossing detected on pin 2
// * timer starts counting from zero
// * comparator set to "delay to on" value
// * counter reaches comparator value
// * comparator ISR turns on triac gate
// * counter set to overflow - pulse width
// * counter reaches overflow
// * overflow ISR truns off triac gate
// * triac stops conducting at next zero cross
// The hardware timer runs at 16MHz. Using a
// divide by 256 on the counter each count is 
// 16 microseconds.  1/2 wave of a 60Hz AC signal
// is about 520 counts (8,333 microseconds).
#include <avr/io.h>
#include <avr/interrupt.h>
#define DETECT 2  //zero cross detect
#define GATE 9    //triac gate
#define PULSE 4   //trigger pulse width (counts)
int i=483;
void setup(){
  // set up pins
  pinMode(DETECT, INPUT);     //zero cross detect
  digitalWrite(DETECT, HIGH); //enable pull-up resistor
  pinMode(GATE, OUTPUT);      //triac gate control
  // set up Timer1 
  //(see ATMEGA 328 data sheet pg 134 for more details)
  OCR1A = 100;      //initialize the comparator
  TIMSK1 = 0x03;    //enable comparator A and overflow interrupts
  TCCR1A = 0x00;    //timer control registers set for
  TCCR1B = 0x00;    //normal operation, timer disabled
  // set up zero crossing interrupt
  attachInterrupt(0,zeroCrossingInterrupt, RISING);    
    //IRQ0 is pin 2. Call zeroCrossingInterrupt 
    //on rising signal
//Interrupt Service Routines
void zeroCrossingInterrupt(){ //zero cross detect   
  TCCR1B=0x04; //start timer with divide by 256 input
  TCNT1 = 0;   //reset timer - count from zero
ISR(TIMER1_COMPA_vect){ //comparator match
  digitalWrite(GATE,HIGH);  //set triac gate to high
  TCNT1 = 65536-PULSE;      //trigger pulse width
ISR(TIMER1_OVF_vect){ //timer1 overflow
  digitalWrite(GATE,LOW); //turn off triac gate
  TCCR1B = 0x00;          //disable timer stopd unintended triggers
void loop(){ // sample code to exercise the circuit
OCR1A = i;     //set the compare register brightness desired.
if (i<65){i=483;}                      

Regulation of DC

DC can be regulated with PWM (Pulse Wave Modulation).

en/regulation.txt · Last modified: 2018/01/29 10:12 (external edit)