Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AC FADER
29-11-2015, 01:02 AM, (This post was last modified: 29-11-2016, 03:07 PM by derf158.)
#1
Video  AC FADER
Hello,
 i have been working on fading my AC LED Christmas lights and found a project on instructables. Here is the code from Arduino with a few modifications. Please note in the code for different led light sets i had to change the i value to eliminate a quick flash during the fading.
Code:
/*

AC Voltage dimmer with Zero cross detection
Author: Charith Fernanado <a href="http://www.inmojo.com"> http://www.inmojo.com
</a>
Adapted by DIY_bloke
License: Creative Commons Attribution Share-Alike 3.0 License.
Attach the Zero cross pin of the module to Arduino External Interrupt pin
Select the correct Interrupt # from the below table
(the Pin numbers are digital pins, NOT physical pins:
digital pin 2 [INT0]=physical pin 4 and digital pin 3 [INT1]= physical pin 5)
check: <a href="http://arduino.cc/en/Reference/attachInterrupt"> http://www.inmojo.com
</a>

Pin    |  Interrrupt # | Arduino Platform
---------------------------------------
2      |  0            |  All -But it is INT1 on the Leonardo
3      |  1            |  All -But it is INT0 on the Leonardo
18     |  5            |  Arduino Mega Only
19     |  4            |  Arduino Mega Only
20     |  3            |  Arduino Mega Only
21     |  2            |  Arduino Mega Only
0      |  0            |  Leonardo
1      |  3            |  Leonardo
7      |  4            |  Leonardo
The Arduino Due has no standard interrupt pins as an iterrupt can be attached to almosty any pin.


*/

int dimtime;
int AC_LOAD = 11;    // Output to Opto Triac pin
int dimming = 128;  // Dimming level (0-128)  0 = ON, 128 = OFF
void zero_crosss_int()  //function to be fired at the zero crossing to dim the light
{
 // Firing angle calculation : 1 full 50Hz wave =1/50=20ms
 // Every zerocrossing thus: (50Hz)-> 10ms (1/2 Cycle)
 // For 60Hz => 8.33ms (10.000/120)
 // 10ms=10000us
 // (10000us - 10us) / 128 = 75 (Approx) For 60Hz =>65

 int dimtime = (65*dimming);    // For 60Hz =>65    
 delayMicroseconds(dimtime);    // Wait till firing the TRIAC
 digitalWrite(AC_LOAD, HIGH);   // Fire the TRIAC
 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
}

void setup()
{

 pinMode(AC_LOAD, OUTPUT);// Set AC Load pin as output
//OnChangePin1( zero_crosss_int, INT_RISING_EDGE);  // Choose the zero cross interrupt # from the table above
OnChangePin1( zero_crosss_int, INT_FALLING_EDGE);
}


void loop()  {
int i;

   for ( i= 25; i <= 128; i++){ // SETTING FOR i LED 100 SET =10
   dimming=i;                   // SETTING FOR i LED 150 SET =25
 
   delay(10);
  }
   
for ( i=128; i >= 25; i--)
{
dimming=i;
delay(10);
 
 
   

}
}




Attached Files
.pdf   FADER CIRCUIT.pdf (Size: 34.56 KB / Downloads: 6)
.pde   AC FADER.pde (Size: 2.41 KB / Downloads: 2)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)