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;
}
}