I'm just learning how to use the Arduino Uno and I'm trying to control the speed of an AC fan. I made a sketch of this project on proteus but the triac seems not to be responding. I guess there's a problem with the attachInterrupt part of the code. Here's the code:
#define triacPulse 5 #define interruptPin 2
//button event #define button1 6
void setup() { // put your setup code here, to run once: pinMode(button1, INPUT);
}
void loop() { // put your main code here, to run repeatedly: if(button1==HIGH){ attachInterrupt(0, triacControl, FALLING); } }
void triacControl() { delay(5); //delay for 5 milliseconds digitalWrite(triacPulse, HIGH); delay(5);
digitalWrite(triacPulse, LOW);
}
#define triacPulse 5
#define interruptPin 2
//button event
#define button1 6
void setup() {
// put your setup code here, to run once:
pinMode(button1, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if(button1==HIGH){
attachInterrupt(0, triacControl, FALLING);
}
}
void triacControl()
{
delay(5); //delay for 5 milliseconds
digitalWrite(triacPulse, HIGH);
delay(5);
digitalWrite(triacPulse, LOW);
}
Thanks for the answer in advance