Introduction: How to Control AC Fan Speed Using Arduino Generated PWM

About: Lisleapex Blog mainly shares knowledge and the latest information about electronic components. Please support me a lot. Thank you.

In this project we will demonstrate AC fan speed control with Arduino using TRIAC. Here the phase control method of AC signal is used to control the speed of AC fan using PWM signal generated by Arduino. In the previous tutorial, we used PWM to control the speed of a DC fan.

Supplies

  • Arduino UNO
  • 4N25 (zero-crossing detector)
  • 10k potentiometer
  • MOC3021 0pto coupler
  • (0-9)V, 500 mA step-down transformer
  • BT136 thyristor
  • 230 VAC Axial AC Fan
  • Connecting line
  • Resistor
  • AC fan control using Arduino

Step 1: Zero Crossing Detector

The AC power in our home is 220v AC RMS, 50 HZ. This AC signal is alternating in nature and periodically changes its polarity. During the first half of each cycle, it flows in one direction, reaches a peak voltage, and then drops to zero. Then in the next half cycle it flows in an alternating direction (negative) to the peak voltage and then goes to zero again. In order to control the speed of the AC Fan, the peak voltage of both half cycles needs to be chopped or controlled. To do this we have to detect the zero point of the signal to be controlled/chopped. The point on the voltage curve where the voltage changes direction is called the zero-crossing voltage.


The circuit shown in the figure below is a zero-crossing detector circuit used to obtain the zero-crossing point. First, use a step down transformer to step down the 220V AC voltage to 9V AC and then feed it into a 4N25 optocoupler at its pins 1 and 2. The 4N25 optocoupler has a built-in LED with pin 1 as the anode and pin 2 as the cathode. So according to the circuit below, when the AC wave approaches the zero crossing point, the built-in LED of the 4N25 will turn off and therefore, the output transistor of the 4N25 will also turn off and the output pulse pin will be pulled to 5V. Likewise, when the signal gradually increases to a peak point, then the LED turns on, the transistor will also turn on, and the ground pin is connected to the output pin, which makes that pin 0V. Using this pulse, zero crossings can be detected using an Arduino.

Step 2: Phase Angle Control Circuit

Having detected the zero crossing, now we have to control the amount of time the power is on and off. This PWM signal will determine the amount of voltage output to the AC motor, thereby controlling the speed of the motor. Here BT136 TRIAC is used which controls AC voltage as it is a power electronic switch used to control AC voltage signal.


A TRIAC is a three-terminal AC switch that can be triggered by a low-energy signal at its gate terminal. In SCR it conducts in only one direction but in case of TRIAC the power can be controlled in both directions. To learn more about TRIAC and SCR, read our previous article.


As shown in the figure above, the TRIAC is triggered at a firing angle of 90 degrees by applying a small gate pulse signal to the TRIAC. Time "t1" is the delay time given according to the dimming requirements. For example, in this case, the firing angle is 90%, so the power output will also be halved, so the light will also shine at half the intensity.


We know that the frequency of the AC signal here is 50 Hz. So the time period will be 1/f, which is 20ms. For a half cycle, this would be 10 milliseconds or 10,000 microseconds. So, to control the power of an AC lamp, the range of "t1" can be varied between 0-10000 microseconds.

Step 3: Potentiometer to Control Fan Speed

A potentiometer is used here to change the speed of the AC fan. We know that a potentiometer is a three-terminal device that acts as a voltage divider and provides a variable voltage output. This variable analog output voltage is given at the Arduino analog input and is used to set the speed value of the AC fan.

Step 4: PWM Signal Generation Unit

In the final step, PWM pulses are provided to the TRIAC based on the speed requirement, thereby changing the ON/OFF timing of the AC signal and providing a variable output to control the fan speed. Here Arduino is used to generate PWM pulses which takes the input from the potentiometer and outputs the PWM signal to the TRIAC and optocoupler circuit which further drives the AC fan at the desired speed.

Step 5: Circuit Schematic

The circuit diagram of this Arduino based 230v fan speed control circuit is shown below:

Step 6: Coding

This code implements controlling the speed of an AC fan using Arduino and PWM. It starts by declaring the necessary variables, including the pin connected to the BT136 TRIAC (pin 6) and the variable speed_val to store the speed step value. In the setup() function, the TRIAC pin is declared as an output, and an interrupt is configured to detect zero crossings. In the infinite loop(), the analog value from a potentiometer connected to A0 is read and mapped to a value range of (10-40), and the result is stored in speed_val. Finally, the interrupt driver function zero_crossing() is configured to calculate the dimming time based on the speed step value and trigger the TRIAC accordingly.

int TRIAC = 6;

int speed_val = 0;


void setup() {

  pinMode(TRIAC, OUTPUT);

  attachInterrupt(digitalPinToInterrupt(3), zero_crossing, CHANGE);

}


void zero_crossing() {

  int chop_time = (200 * speed_val);

  delayMicroseconds(chop_time);

  digitalWrite(TRIAC, HIGH);

  delayMicroseconds(10);

  digitalWrite(TRIAC, LOW);

}


void loop() {

  int pot = analogRead(A0);

  int data1 = map(pot, 0, 1023, 10, 40);

  speed_val = data1;

}