Ola
o que estou a fazer mal?? :-)
Estou a tentar controlar 2 lampadas com dimmer, tenho um opto 4N25 para fazer a detecção por zero e um MOC3021 a fazer o disparo do Triac (TIC246M). Assim com uma lampada funciona perfeitamente, quando duplico o MOC3021 e outro TRIAC (a deteção por Zero mantive o mesmo, penso k basta 1) nao consigo controlar a segunda lampada, ela tem o comportamento da primeira lampada.
Este é o codigo para 1 lampada e k funciona bem.
/*
AC Light Dimmer - Inmojo
AC Voltage dimmer with Zero cross detection
Author: Charith Fernanado http://www.inmojo.com charith@inmojo.com
License: Released under the Creative Commons Attribution Share-Alike 3.0 License.
http://creativecommons.org/licenses/by-sa/3.0
Target: Arduino
Attach the Zero cross pin of the module to Arduino External Interrupt pin
Select the correct Interrupt # from the below table
Pin | Interrrupt # | Arduino Platform
---------------------------------------
2 | 0 | All
3 | 1 | All
18 | 5 | Arduino Mega Only
19 | 4 | Arduino Mega Only
20 | 3 | Arduino Mega Only
21 | 2 | Arduino Mega Only
*/
int AC_LOAD = 5; // Output to Opto Triac pin
int dimming = 128; // Dimming level (0-128) 0 = ON, 128 = OFF
void setup()
{
pinMode(AC_LOAD, OUTPUT); // Set the AC Load as output
attachInterrupt(0, 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
{
// Firing angle calculation :: 50Hz-> 10ms (1/2 Cycle)
// (10000us - 10us) / 128 = 75 (Approx)
int dimtime = (75*dimming);
delayMicroseconds(dimtime); // Off cycle
digitalWrite(AC_LOAD, HIGH); // triac firing
delayMicroseconds(10); // triac On propogation delay
digitalWrite(AC_LOAD, LOW); // triac Off
}
void loop()
{
dimming = 100;
delay(1000);
dimming = 75;
delay(1000);
}
Este é o codigo k fiz para a segunda lampada e k nao funciona
/*
AC Light Dimmer - Inmojo
AC Voltage dimmer with Zero cross detection
Author: Charith Fernanado http://www.inmojo.com charith@inmojo.com
License: Released under the Creative Commons Attribution Share-Alike 3.0 License.
http://creativecommons.org/licenses/by-sa/3.0
Target: Arduino
Attach the Zero cross pin of the module to Arduino External Interrupt pin
Select the correct Interrupt # from the below table
Pin | Interrrupt # | Arduino Platform
---------------------------------------
2 | 0 | All
3 | 1 | All
18 | 5 | Arduino Mega Only
19 | 4 | Arduino Mega Only
20 | 3 | Arduino Mega Only
21 | 2 | Arduino Mega Only
*/
int AC_LOAD = 5; // Output to Opto Triac pin
int AC_LOAD2 =6;
int dimming = 128;// Dimming level (0-128) 0 = ON, 128 = OFF
int dimming2 = 128;
void setup()
{
pinMode(AC_LOAD, OUTPUT); // Set the AC Load as output
pinMode(AC_LOAD2, OUTPUT);
attachInterrupt(0, 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
{
// Firing angle calculation :: 50Hz-> 10ms (1/2 Cycle)
// (10000us - 10us) / 128 = 75 (Approx)
int dimtime = (75*dimming);
delayMicroseconds(dimtime); // Off cycle
digitalWrite(AC_LOAD, HIGH); // triac firing
delayMicroseconds(10); // triac On propogation delay
digitalWrite(AC_LOAD, LOW); // triac Off
int dimtime2 = (75*dimming2);
digitalWrite(AC_LOAD2, HIGH);
delayMicroseconds(10); // triac On propogation delay
digitalWrite(AC_LOAD2, LOW);
}
void loop()
{
dimming = 100;
dimming2 = 75;
delay(1000);
dimming = 75;
dimming2 = 100;
delay(1000);
}
Agradeço desde já qualquer ajuda.
Abraços