Sunday, June 1, 2014

Switching AC Line Power with a Thyristor (TRIAC)

In this video we look at how to use a Thyristor (TRIAC) as an AC line power switch. Great tool to use in home automation projects for turning on or off a light or building your own thermostat.


Thyristor Example Circuit


//This sketch is used to control Thyristor that is used as a switch to turn on and off an AC line powered light. //This code is free for all to use
int8_t dig = 1; //default is high for light off

void setup() {
  //for controlling Thyristor
  pinMode(3, OUTPUT); //set pin to output so it can sink current from optoisolator
  digitalWrite(3, HIGH); //when high the thyristor is off or open
}

void loop() {
  delay(2000); //light turns on / off every 2 seconds
  togLight(); //call function to turn light on / off using digital pin
}

void togLight() {
  if(dig) { 
     digitalWrite(3, HIGH); //turn off light
     dig = 0; //toggle dig value
  }
  else {  
     digitalWrite(3, LOW); //turn light on
     dig = 1; 
   }
}