Close Menu
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
Facebook X (Twitter) Instagram
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
How To Electronics
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
How To Electronics
Home » 220V AC Light/Fan Dimmer using TRIAC & Arduino
Arduino Projects

220V AC Light/Fan Dimmer using TRIAC & Arduino

Mamtaz AlamBy Mamtaz AlamUpdated:February 2, 20257 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
AC Dimmer TRIAC Arduino
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

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.

AC TRIAC Waveform



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 NameQuantityPurchase Links
1Arduino Nano Board1Amazon | AliExpress
2Optocoupler IC EL817/PC8171Amazon | AliExpress
3Optoisolator MOC30201Amazon | AliExpress
4TRIAC BTA161Amazon | AliExpress
5Diode 1N40074Amazon | AliExpress
6Potentiometer 10K1Amazon | AliExpress
7 Resistors 47K2Amazon | AliExpress
8 Resistor 1K1Amazon | AliExpress
9 Resistor 100-ohm1Amazon | AliExpress
10 Resistor 220-ohm1Amazon | AliExpress
11Bulb1-

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.

Arduino AC Dimmer Circuit

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

Zero Cross Detector Circuit

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.

Zero Cross Detector waveform

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.

Thyristor

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.

TRIAC BTA16

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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, Gerber File & PCB Ordering Online

The PCB for AC Dimmer has been designed in EasyEDA online PCB making tool. Below is the front view and Back View of the PCB.

PCB AC Dimmer

The Gerber File for the PCB is given below. A quick way to prototype this PCB project is to use ALLPCB. This company has this limited-time sale offering 5 pieces of PCB for only 1$. You can simply download the Gerber File and upload it in ALLPCB.

Download Gerber File: Gerber File AC Dimmer

You can use this Gerber file to order high-quality PCBs for this project. To do that visit the ALLPCB official website by clicking here: https://www.allpcb.com/.

You can now upload the Gerber File by choosing the Quote Now option. You can choose the Material Type, Dimensions, Quantity, Thickness, Solder Mask Color, and other required parameters from these options.

After filling all details, select your country and shipping method. Finally you can place the order.

So after almost 5 days, I got the PCB from ALLPCB.

The PCB quality from ALLPCB is superb with very high quality.

AC Dimmer TRIAC Arduino PCB

I have been using ALLPCB for my project for two years now. They have been very consistent on quality and I never had any unsatisfactory board with them.

After that you can solder all the necessary components as per circuit diagram and make the final product ready.

AC Dimmer

Now you can power ON the circuit and start testing the working by rotating the potentiometer in clockwise and anticlockwise direction. You can use CFL Bulb or simply Filament Lamp to do the testing. I got the result from zero brightness to full brightness.

AC Dimmer using Arduino

You can go through this post if you want to make Wireless AC Dimmer: Wireless AC Light Dimmer with Android Bluetooth & Arduino

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleRS-485 Full-Duplex Communication with MAX485 & Arduino
Next Article Wireless AC Light Dimmer with Bluetooth & Arduino

Related Posts

DC Energy Meter using Arduino

Build a DC Energy Meter using Arduino – 32V/5A

Updated:August 26, 20252K
Interfacing ADXL375 Accelerometer with Arduino

Interfacing ADXL375 Accelerometer with Arduino (±200g)

Updated:June 28, 2025
PZEM-004T Arduino Energy Meter

DIY AC Energy Meter using PZEM-004T & Arduino

Updated:March 6, 20258K
Interfacing BMI160 Accelerometer & Gyroscope with Arduino

Interfacing BMI160 Accelerometer & Gyroscope with Arduino

Updated:February 2, 20259K
Password Based Door Lock Security System Using Arduino & Keypad

Password Based Door Lock Security System Using Arduino & Keypad

Updated:February 2, 20252436K
Earthquake Detector Alarm with with Accelerometer & Arduino

Earthquake Detector Alarm with Accelerometer & Arduino

Updated:February 2, 2025661K
Add A Comment

CommentsCancel reply

Latest Posts
ESP32 Fingerprint Attendance System with Live Web Dashboard

ESP32 Fingerprint Attendance System with Live Web Dashboard

June 21, 2026
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

June 14, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

May 10, 2026
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

May 2, 2026
A Guide to Sourcing Obsolete ICs for Vintage Projects

Beyond AliExpress: A Guide to Sourcing Obsolete ICs for Vintage Projects

April 21, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

April 27, 2026
Building a Smart Sensor Node with a BLE Microcontroller

Building a Smart Sensor Node with a BLE Microcontroller

February 26, 2026
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

April 27, 2026
Top Posts & Pages
  • ESP32 Fingerprint Attendance System with Live Web Dashboard
    ESP32 Fingerprint Attendance System with Live Web Dashboard
  • ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
    ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
  • LD2410 Sensor with ESP32 - Human Presence Detection
    LD2410 Sensor with ESP32 - Human Presence Detection
  • IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
    IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • IoT Based Patient Health Monitoring on ESP32 Web Server
    IoT Based Patient Health Monitoring on ESP32 Web Server
  • Silicon Controlled Rectifier (SCR): Construction, Working & Applications
    Silicon Controlled Rectifier (SCR): Construction, Working & Applications
  • Buck Converter: Basics, Working, Design & Application
    Buck Converter: Basics, Working, Design & Application
Categories
  • Arduino Projects (197)
  • Articles (60)
    • Learn Electronics (19)
    • Product Review (15)
    • Tech Articles (28)
  • Electronics Circuits (46)
    • 555 Timer Projects (21)
    • Op-Amp Circuits (7)
    • Power Electronics (13)
  • IoT Projects (205)
    • ESP32 MicroPython (7)
    • ESP32 Projects (82)
    • ESP32-CAM Projects (15)
    • ESP8266 Projects (76)
    • LoRa/LoRaWAN Projects (22)
  • Microcontrollers (38)
    • AMB82-Mini IoT AI Camera (4)
    • BLE Projects (18)
    • STM32 Projects (19)
  • Raspberry Pi (93)
    • Raspberry Pi Pico Projects (57)
    • Raspberry Pi Pico W Projects (12)
    • Raspberry Pi Projects (24)
Follow Us
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
About Us

“‘How to Electronics’ is a vibrant community for electronics enthusiasts and professionals. We deliver latest insights in areas such as Embedded Systems, Power Electronics, AI, IoT, and Robotics. Our goal is to stimulate innovation and provide practical solutions for students, organizations, and industries. Join us to transform learning into a joyful journey of discovery and innovation.

Copyright © How To Electronics. All rights reserved.
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Looks like you're using an ad blocker. Please allow ads on our site. We rely on advertising to help fund our site.