IOT

220V AC Light/Fan Dimmer using TRIAC & Arduino

The majority of our household gadgets, such as lights, televisions, and fans, are powered by an AC source. By putting together a Home automation setup with Arduino and Relays, we can turn them on/off digitally if necessary. But what if we need to control the power of such devices, such as dimming the AC lamp or controlling the fan speed? In that scenario, we must adjust the phase of the AC supply voltage using phase control techniques and static switches such as TRIAC.

In this article, we’ll use Arduino to create a 220V AC Light Dimmer or AC Fan Speed Controller using a TRIAC and an optocoupler.

Controlling an AC load, on the other hand, is more difficult than controlling a DC load. Both of these applications have different electronic circuits. The frequency of the AC mains with a sinusoidal wave is 50Hz. The zero-crossing points (the locations where the wave changes polarity) are crucial when building an AC dimmer. To identify these points, we must first construct a zero-crossing detector. Similarly, we must control the waveform’s phase and cycle. Because every component cannot withstand 220V AC, we must use another component to isolate the circuit from 220V AC. The entire procedure is detailed here.

Hardware Required

  • Arduino Nano
  • Optocoupler IC-EL817/PC817
  • Optoisolator-MOC3020
  • TRIAC-BTA16
  • Diode-1N4007
  • Potentiometer-10K
  • Resistors-47K,1K,100ohm,220ohm
  • 100W Tungsten Bulb

Circuit: 220V AC Light/Fan Dimmer using TRIAC & Arduino

The circuit diagram for a 220V AC Light Dimmer/Fan Speed Controller using TRIAC and Arduino is shown below. EasyEDA, an online PCB design programme, was used to create the schematic.

Arduino AC Dimmer Circuit

The circuit is divided into 4 parts:

  • Zero Cross Detector Circuit
  • Phase/Angle Control Using Triac
  • Potentiometer Part to Control the Dimming
  • The Arduino Code for changing delay in mS

1. Zero Cross Detector Circuit

The peak to peak AC voltage from the household supply is roughly 310 volts, or 220 volts RMS. The frequency ranges between 50 and 60 hertz. There will be a zero-crossing because we have a positive and a negative portion. Since our pulse must be in phase with the AC voltage, we must detect that zero-cross.

Zero Cross Detector Circuit

As a result, we must detect when the voltage changes from positive to negative or negative to positive, and synchronize our pulse with it so that it fires at the same time every time. We’ll use a complete bridge rectifier for this. Both the positive and negative curves of the AC wave will be output.

Zero Cross Detector waveform

The current is limited by two 47 kilo-ohm resistors. An EL817 optocoupler will be used to separate the high voltage and low voltage sides. As a result, there is no direct connection between the Arduino’s 5V and the 220V high power.

2. Phase/Angle Control Using Triac

We’ll use a TRIAC component to manage the amount of time this power is on and off. But first, we must comprehend the operation of TRIAC.

The diode is something we’re aware of. A half-wave rectifier is created by connecting a single diode to an AC signal. The positive part of the AC waveform is preserved while the negative part is chopped when only one diode is used.

So we want to be able to activate or deactivate the diode. So a THYRISTOR, which is essentially a controlled diode that is triggered when the gate receives a current trigger and continues to conduct while the voltage across the device is not reversed, can be used to do this.

So now we’ve got our AC signal. If we use a diode, the negative part will not pass, and if we don’t switch the THYRISTOR, the positive part will not pass as well. Assume we need to activate the THYRISTOR’s gate with a pulse in the middle position while allowing the remaining positive side of the AC wave to pass through. As a result, we get a rectified output of the sole positive part. However, we need to utilize two THYRISTORS in an antiparallel configuration if we wish to achieve this with both positive and negative sides. However, we already have a component that can perform this function, which is known as TRIAC. Until it receives a pulse at its gate, the TRIAC will stay dormant. It will remain active once it has been received until the primary input changes polarity. To control AC voltage, we’ll utilize the BTA16 TRIAC.

TRIAC BTA16

Since the pulse must be in phase with the AC voltage, we must first detect the zero-cross. As a result, we must detect when the voltage changes from positive to negative or negative to positive, and synchronize our pulse with it so that it fires at the same time every time. A full-bridge rectifier is employed for this, which outputs both the positive and negative AC wave curves.

3. Potentiometer Part to Control the Dimming

All we have to do to regulate power is control the time between the zero-cross and when the pulse is fired at the TRIAC gate. To modify the delay timing, we’ll use a potentiometer. The Arduino code will read a potentiometer’s value and convert it to a delay of 1 to 10 milliseconds.

Source Code/Program

The Arduino programme for controlling an AC dimmer with a potentiometer is provided below, along with comments to help you understand how an AC dimmer works. This code should be uploaded to your Arduino board.

int mydelay = 0;
int myvalue=0;
int last_CH1_state = 0;

void setup() {
/*
* Port registers allow for lower-level and faster manipulation of the i/o pins of the microcontroller on an Arduino board.
* The chips used on the Arduino board (the ATmega8 and ATmega168) have three ports:
-B (digital pin 8 to 13)
-C (analog input pins)
-D (digital pins 0 to 7)
//All Arduino (Atmega) digital pins are inputs when you begin…
*/

PCICR |= (1 << PCIE0); //enable PCMSK0 scan
PCMSK0 |= (1 << PCINT0); //Set pin D8 trigger an interrupt on state change. Input from optocoupler
pinMode(3,OUTPUT); //Define D3 as output for the DIAC pulse

}

void loop() {
//Read the value of the pot and map it from 10 to 10.000 us. AC frequency is 50Hz, so the period is 20ms. We want to control the power
//of each half period, so the maximum is 10ms or 10.000us. In my case, I’ve mapped it up to 7.200us since 10.000 was too much

myvalue = map(analogRead(A0),0,1024,7200,10);
if (mydelay)
{
delayMicroseconds(myvalue); //This delay controls the power
digitalWrite(3,HIGH);
delayMicroseconds(100);
digitalWrite(3,LOW);
mydelay=0;
}
}




//This is the interruption routine
//———————————————-

ISR(PCINT0_vect){
///////////////////////////////////// //Input from optocoupler
if(PINB & B00000001){ //We make an AND with the pin state register, We verify if pin 8 is HIGH???
if(last_CH1_state == 0){ //If the last state was 0, then we have a state change…
mydelay=1; //We haev detected a state change!
}
}
else if(last_CH1_state == 1){ //If pin 8 is LOW and the last state was HIGH then we have a state change
mydelay=1; //We haev detected a state change!
last_CH1_state = 0; //Store the current state into the last state for the next loop
}
}

PCB Designing for AC Dimmer with TRIAC & Arduino

EasyEDA, an online PCB design program, was used to create the PCB for the AC Dimmer. Below are the front view and Back View of the PCB generated from the Gerber Viewer of NextPCB.

PCB AC Dimmer

The PCB’s Gerber file may be seen below. NextPCB allows you to download the Gerber file and order the PCB online.

Download: Gerber File AC Dimmer

PCB Ordering, Soldering & Mounting

Now you can visit https://www.nextpcb.com/ and order the PCB. NextPCB is one of China’s largest PCB manufacturing companies. They provide high-quality PCB at an affordable price.

NextPCB
AC Dimmer TRIAC Arduino PCB

After that, solder all of the necessary components according to the circuit schematic and finish the final product.

AC Dimmer

You can now turn on the circuit and begin evaluating its functionality by twisting the potentiometer clockwise and anticlockwise. To conduct the tests, you can use a CFL bulb or a Tungsten bulb. I achieved the result by varying the brightness from zero to full.

Conclusion

I hope all of you understand how to control 220V AC Light/Fan Dimmer using TRIAC & Arduino. We MATHA ELECTRONICS will be back soon with more informative blogs.

Leave a Reply

Your email address will not be published.