Controlling power using triac


I am using this module to control speed of an AC fan along with arduino mega and using the following code
/*

AC Voltage dimmer with Zero cross detection
Author: Charith Fernanado 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: interrupts

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.

In the program pin 2 is chosen
*/
int AC_LOAD = 3; // Output to Opto Triac pin
int dimming = 128; // Dimming level (0-128) 0 = ON, 128 = OFF

void setup()
{
pinMode(AC_LOAD, OUTPUT);// Set AC Load pin as output
attachInterrupt(0, zero_crosss_int, RISING); // Choose the zero cross interrupt # from the table above
}

//the interrupt function must take no parameters and return nothing
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 = (75*dimming); // For 60Hz =>65
delayMicroseconds(dimtime); // Wait till firing the TRIAC
digitalWrite(AC_LOAD, HIGH); // Fire the TRIAC
delayMicroseconds(10); // triac On propogation delay
// (for 60Hz use 8.33) Some Triacs need a longer period
digitalWrite(AC_LOAD, LOW); // No longer trigger the TRIAC (the next zero crossing will swith it off) TRIAC
}

void loop() {
for (int i=5; i <= 128; i=i++){
dimming=i;
delay(10);
}
}

the problem I facing with this code is that at i=0 the fan should be on and at i=128 the fan should be completely off but instead the fan does not turn on at i = 0, there is slight movement at this point, and by increasing the value upto 250, the fan operatesat full speed, and then by further increasing the value of i, the speed decreases,
can you please guide me about this problem.

Because in my project I want to control the power of an AC heater, I want to know exactly the delay parameters to calculate the AC power of heat.
Thankyou

Your project is ONLY controlling the voltage, NOT the power which will vary as the resistance of your heater varies.

kindly please explain why the fan is exhibiting such behavior, at i=0, the fan should have maximum rpms

Read the forum guidelines on posting code. Nice schematic but not complete. Please post the full schematic and links to technical information on the hardware items or a generac part number like MOC3031.

The dwg/sch is a bit JPG'd, but U1 is MOC3021.

The optotransistor is like they all are.

image

But what's the voltage at "V???" ?
The voltage at the opto's collector (ZC det) needs to be going 0/5V.

I think this variable is used in an interrupt routine and the main code. (Hard to be sure until you post your code correctly. Please use Auto Format before you post your code again.) If I am correct, this variable should be declared "volatile".

For your test, replace the fan with an incandescent light bulb. If I recall correctly, not all AC motor rpm responds well to this kind of phase cutting.

You should be "dimming" the heating element and not the fan speed. I agree that you should test with a regular light bulb first.

It seems like it's basally working but the timing is wrong.

This might be a clue:

// (for 60Hz use 8.33) Some Triacs need a longer period

When a TRIAC is turned-on it latches on and it can't turn-off until current drops to zero, which is the next zero-crossing.

If the TRIAC is triggered just-after the zero-crossing it stays on for the full half-cycle and you get full-power (and a light will be full-brightness). If you trigger just-before the zero crossing it's only on for the last part of the half-cycle and you get low power (and a dim light bulb).

If you trigger too late, you're into the beginning of the next half-cycle and it suddenly jumps from full-dim to full-bright.

How Dimmers Work

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.