I was using this blog to control AC signal with Arduino .
[I'll give some time for you guys to read and understand what this guy was doing]
Now I'm stuck as I want Arduino to control separately at-least 5 outlets at the same time . By control I mean different behaviors. Say one is blinking and another is stagnant and another is blinking slowly.
Now knowing all the limitations of Interrupt service routines.
My current condition:
I’ve 5 such circuits.
All of them are connected to an interrupt pin of Arduino Leonardo to detect zero crossing.
All of them are connected to a Digital Pin of Arduino Leonardo to control the Triac.
Have 5 separate service routines with 5 variables which I can control in loop (without using delay — just millis () to do some blinking and other stuff so that they can run parallely).
The intent is to control 5 such circuits(i.e run 5 service routines) at the same time with one Arduino, so that I can have desired effects for each Load(Bulb.)..
Trying with 3 AC LOADS, this is my code:
Also
I tried using only one ISR(which is kind of a pseudo PWM) and controlling other outputs within that function. But that way I’ve only one variable and all the 5 bulbs have same behaviour. If I use just one Interrupt Pin and one ISR then Can I control different outputs at the same same time differently? Within ISR I can not do Arduino multitasking as it doesn't allow
millis();
and
micros();
If this can be done, then we don’t need to run separate ISRs in parallel(which I’m not sure we can).
This is what I was doing
int AC_LOAD = 10; // Output to Opto Triac pin
int AC_LOAD_TWO = 6;
int AC_LOAD_THREE = 4;
int AC_LOAD_FOUR = 5;
int AC_LOAD_FIVE = 8;
volatile int dimming = 128; // Dimming level (0-128) 0 = ON, 128 = OFF
void setup()
{
pinMode(AC_LOAD, OUTPUT);// Set AC Load pin as output
pinMode(AC_LOAD_TWO, OUTPUT);
pinMode(AC_LOAD_THREE, OUTPUT);
pinMode(AC_LOAD_FOUR, OUTPUT);
pinMode(AC_LOAD_FIVE, OUTPUT);
attachInterrupt(4, zero_crosss_int, RISING); // Choose the zero cross interrupt # from the table above
}
void zero_crosss_int() //function to be fired at the zero crossing to dim the light
{
int dimtime = (65 * dimming); // For 60Hz =>65
delayMicroseconds(dimtime); // Wait till firing the TRIAC
digitalWrite(AC_LOAD, HIGH); // Fire the TRIAC
digitalWrite(AC_LOAD_TWO, HIGH);
digitalWrite(AC_LOAD_THREE, HIGH);
digitalWrite(AC_LOAD_FOUR, HIGH);
digitalWrite(AC_LOAD_FIVE, HIGH);
delayMicroseconds(8.33); // triac On propogation delay (for 60Hz use 8.33)
digitalWrite(AC_LOAD, LOW); // No longer trigger the TRIAC (the next zero crossing will swith it off) TRIAC
digitalWrite(AC_LOAD_TWO, LOW);
digitalWrite(AC_LOAD_THREE, LOW);
digitalWrite(AC_LOAD_FOUR, LOW);
digitalWrite(AC_LOAD_FIVE, LOW);
}
void loop() {
dimming = 50;
delay(1000);
dimming = 128;
delay(1000);
}
I know a lot of people don't work with AC and interrupts and all .. This is not a very popular problem.. But I'm stuck so helps are heart-fully appreciated..