HERE POWER TO THE BULB IS CONTROLLED.MCT2E OPTO-COUPLER USED TO GET THE ZERO CROSSING. MOC3021 OPTO-COUPLER TRIAC IS USED TO FIRE THE TRIAC BT136. THIS PROJECT IS SIMILIAR TO FADING EXAMPLE OF LED IN ARDUINO WHICH IS AN DC VOLTAGE ,BUT HERE FADING IS DONE AC VOLTAGE
OUTPUT WAVEFORM AT ZERO CROSSING OPTO COUPLER (YELLOW) AND INPUT SINE WAVE
CIRCUIT
PROGRAM
int a,i;
void setup()
{
pinMode(4,INPUT);
pinMode(10,OUTPUT);
}
void loop()
{
for(i=0;i<10;i++)
{
for(int j=0;j<10;j++)
{
waitfornextzerocrossing ();delay(i); digitalWrite(10, HIGH); delayMicroseconds(200); digitalWrite(10, LOW);
}
}
for(i=9;i>0;i–)
{
for(int j=0;j<10;j++)
{
waitfornextzerocrossing ();delay(i); digitalWrite(10, HIGH); delayMicroseconds(200); digitalWrite(10, LOW);
}
}
}
void waitfornextzerocrossing (void)
{
do
{
a =digitalRead(4);
}
while(!a);
}