Arduino B.Tech/Diploma Beginner

220V AC Light/Fan Dimmer using TRIAC & Arduino

Circuit using BTA16 TRIAC & MOC3020 optocoupler to make a 220V AC Light Dimmer or AC Fan Speed Controller with Arduino Code & Potentiometer

  • Suitable forB.Tech/Diploma Arduino students
  • Build time1-2 weeks
  • LevelBeginner
  • Available atAjvika Labs, Kakinada

About this project

In this tutorial we will design a circuit using TRIAC and optocoupler to make a 220V AC Light Dimmer or AC Fan Speed Controller using Arduino.
WARNING:
This circuit is connected directly to the mains AC voltage. You must care about all safety precautions before using the device. If you are a beginner and without having the idea of using electronics appliances. Please avoid!
Overview
We have AC loads everywhere around us. And most of the home appliances are supplied with the AC mains power. There is plenty of situations that we want to have full control over an AC load such as a dimming of a lamp, speed control of AC motor/Fan, Vacuum Cleaner Control and so many other applications. The proper way to control dimming
230v AC
is through phase control with a
Triac
: the Triac then is fully opened, but only during a part of the sinus AC wave.
But controlling an AC load is not as easy as controlling a DC load. The electronics circuit for both these applications is different. The AC mains with a sinusoidal wave has a
frequency of 50Hz
. To build an
AC dimmer
, the
zero-crossing points
(the points where the wave changes its polarity) are important. To detect these points, we have to build a zero-crossing detector first. Similarly, we have to control the phase and cycle of the waveform. Since every component can’t tolerate
220V AC
, so we need to isolate the circuit from 220V AC using some other component. The whole process is explained below.
Before moving ahead you can check our previous project:
Wireless AC Dimmer
or an
IoT AC Dimmer
. And also check simple
PWM Lamp Dimmer
project.
Bill of Materials
Following are the components required to make the AC Dimmer Project. All the components can be easily purchased from Amazon.
S.N.
Components Name
Quantity
Purchase Links

Arduino Nano Board

Amazon
AliExpress

Optocoupler IC EL817/PC817

Amazon
AliExpress

Optoisolator MOC3020

Amazon
AliExpress

TRIAC BTA16

Amazon
AliExpress

Diode 1N4007

Amazon
AliExpress

Potentiometer 10K

Amazon
AliExpress

Resistors 47K

Amazon
AliExpress

Resistor 1K

Amazon
AliExpress

Resistor 100-ohm

Amazon
AliExpress

Resistor 220-ohm

Amazon
AliExpress

Bulb

Circuit: 220V AC Light/Fan Dimmer using TRIAC & Arduino
Here is a
circuit diagram for 220V AC Light Dimmer/Fan Speed Controller using TRIAC & Arduino
. The schematic has been designed using EasyEDA online PCB Designing tool.
The circuit is divided into 4 parts:
1. Zero Cross Detector Circuit
2. Phase/Angle Control Using Triac
3. Potentiometer Part to Control the Dimming
4. The Arduino Code for changing delay in mS
1. Zero Cross Detector Circuit
The
AC voltage
that we get from home supply is around 310 volts peak to peak or 220V RMS. The frequency is usually between
50 – 60 HZ
. We have a positive part and a negative one so there will be a
zero-crossing
. So we will have to detect that zero-cross since our pulse needs to be in phase with the AC voltage
So, we have to detect when the voltage passes from positive to negative or from negative to positive and synchronize our pulse with that so it will fire always in the same spot. For that, we will use a
full bridge rectifier
. This will give the output both the positive and negative curves of the AC wave.
There are two 47 kilo-ohms resistors to limit the current. And to separate the high voltage side from the low voltage side, we will use an
EL817 optocoupler
. In this way, there is no direct connection between 220V high voltage and 5V of the Arduino.
2. Phase/Angle Control Using Triac
Using a component called
TRIAC
, we will control the amount of time that this power is ON and OFF. But before that, we need to understand the working of TRIAC.
We are aware of the diode. When we put a single diode to an AC signal, we get a half-wave rectifier. With just one diode, the positive part of AC waveform remains & the negative part is chopped.
So we want to control the diode by activating it or deactivating it. So this can be done by using a
THYRISTOR
, which basically is a controlled diode that will be activated when the gate receives a current trigger and continuing to conduct while the voltage across the device is not reversed.
So here we have our
AC signal
. The negative part won’t pass if we use a diode and on the positive part, if we don’t switch the THYRISTOR there won’t be the positive part either. Suppose if we have to activate the gate of the
THYRISTOR
with a pulse in the middle position and let the remaining part of the positive side of the AC wave. So we get the only positive part as a rectified output. But if we want to do this with both positive and negative sides, we should use two THYRISTORS in an antiparallel configuration. But we already have that component which can do this work, that’s called
TRIAC
. The TRIAC will remain deactivated until it receives a pulse at its gate. Once received, it will remain activated until the main input will change its polarity. So we will use
BTA16 TRIAC to control AC voltage
First we have to detect the
zero-cross
since the pulse needs to be in phase with the
AC voltage
. So, we have to detect when the voltage passes from positive to negative or from negative to positive and synchronize our pulse with that so it will fire always in the same spot. For this
full-bridge rectifier
is used which will give the output both the positive and negative curves of the AC wave.
3. Potentiometer Part to Control the Dimming
In order to control power, all we have to do is to control the time between the zero-cross and when we fire the pulse at the
TRIAC gate
. So we will use a potentiometer to change the delay timing. The Arduino code will read the value of a potentiometer and map that value to a delay between
1 and 10 milliseconds
Source Code/Program
The Arduino Program to
Control the AC Dimmer with Potentiometer
is given below with comments to understand the AC Dimmer working. Simply upload this code to your Arduino board.

int
mydelay
=

;
int
myvalue
=

;
int
last_CH1_state
=

;
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
|=
(

<<
PCIE0
)
;
//enable PCMSK0 scan
PCMSK0
|=
(

<<
PCINT0
)
;
//Set pin D8 trigger an interrupt on state change. Input from optocoupler
pinMode
(

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
)

1024
7200

)
;
if
(
mydelay
)
{
delayMicroseconds
(
myvalue
)
;
//This delay controls the power
digitalWrite
(

HIGH
)
;
delayMicroseconds
(

)
;
digitalWrite
(

LOW
)
;
mydelay
=

;
}
}
//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
==

)
{
//If the last state was 0, then we have a state change...
mydelay
=

;
//We haev detected a state change!
}
}
else
if
(
last_CH1_state
==

)
{
//If pin 8 is LOW and the last state was HIGH then we have a state change
mydelay
=

;
//We haev detected a state change!
last_CH1_state
=

;
//Store the current state in

Technologies used

ArduinoBLEPWM

Hardware components

  • Arduino

Software & tools

  • EasyEDA

What you get

  • Working project / hardware kit, tested before delivery
  • Complete source code with explanation
  • Project demo and guidance for your viva
  • Project report, PPT and IEEE paper support (on request)
Delivery & Payment
Delivery takes a minimum of two weeks from the date your inquiry is confirmed. Payment is in two parts: • 50% advance to start the project • Remaining 50% before delivery Note: • Documentation and PPT are not included by default • If you need documentation/PPT, it can be arranged for extra time and cost We'll confirm the exact timeline and cost with you after reviewing your requirements.