MOC3021 light dimmer, Triac BTA16, Zero Crossing detector & Arduino

(Last Updated On: February 5, 2022)


MOC3021 light dimmer

“MOC3021 light dimmer” In this Tutorial, you will learn how to make an Arduino-based 110/220vac Bulb dimming Control system using MOC3021, BTA16 Triac, and a zero-crossing detector circuit based on the EL817 optocoupler. The brightness can be controlled using the potentiometer. The Zero crossing detector circuit is designed in such a way that it provides complete isolation between the ac side and the controller side. So if any fault or short circuit happens on the ac side will have no effect on the controller side. In this tutorial, we will cover

  1. Zero crossing detector circuit explanation
  2. Light dimming circuit explanation
  3. Arduino programming and finally 4
  4. Testing

Amazon Links:

12v Adaptor:

Arduino Uno

Arduino Nano

Mega 2560:

MOC3021 optoisolator Triac Driver:

BTA16 Triac:

5×7 cm vero board:

EL817 Optocoupler:

Other Tools and Components:

Top Arduino Sensors:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines


Please Note: these are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!


Zero Crossing Detector Circuit:

This schematic is designed in cadsoft eagle 9.1.0 version. if you want to learn how to make a schematic and PCB then watch my tutorial given below.

The zero crossing detector circuit is very simple, let’s start with the 12v step-down transformer. You can use a 220/110  to 12v transformer. The secondary side of the transformer is connected with the ac input legs of the Bridge rectifier…this is the bridge rectifier as you can see it has 4 legs, two legs are labeled with the ac signs and two legs are labeled with the plus and minus signs.

The purpose of the bridge rectifier is to convert the ac into dc. Three 10k resistors are connected in series which makes the voltage divider circuit. With the help of these resistors, the voltage is reduced to 4volts. A 330-ohm resistor is connected in series with the IR led of the el817 Optocoupler….this is the el817 Optocoupler as you can see it has a total of four legs.

Leg number1 is the anode and leg number2 is the cathode. Leg number3 is the emitter while leg number 4 is the collector… This is a current limiting resistor. while the cathode of the ir led is connected with the ground of the bridge rectifier. On the right side of the el817, a 10k resistor is connected with the collector while the other side of the 10k resistor is connected with the Arduino’s 5v.

while the emitter of the el817 is connected with the Arduino’s ground.  Pin number 4 which is the collector is also connected with the Arduino’s pin number 2. As you can see clearly the Arduino side has no physical connection with the transformer side. So if anything happens on this side will have no effect on the other side. Now let’s have a look at the dimming circuit….

Dimming Circuit based on the MOC3021:

The ac bulb dimming circuit is based on the MOC3021opto-isolator Triac Driver and BTA16 triac. The moc3021 has actually total of 6 pins but pin number 3 and pin number 5 are not used.

Pin number 1 is the anode and pin number 2 is the cathode as per the datasheet…A 330 resistor is connected in series with the anode of the IR led. This is a current limiting resistor and will be connected with the Arduino. this pin will be defined in the number 4 and pin number 6 are the main terminals as per the datasheet… 330-ohm resistors are connected with pin number 4 and pin number 6 of the moc3021…

MOC3021 light dimmer

this is the BTA16 triac lets have a look at its you can see it has three legs

First leg is the main terminal 1

2nd leg is the main terminal 2 while

3rd leg is the Gate.

The BTA16 triac can handle load upto 16A at 25C. for higher load large heat sink should be used…

The other side of the R2 resistor is connected with the main terminal1 of the triac and is also connected with the ac load, while the other side of the ac load is connected with the neutral…

The other side of the R3 resistor is connected with the main terminal2 and is also connected with the 220vac….

Pin number 4 of the moc3021 is also directly connected with the gate of the BTA16 triac…

A variable resistor is connected with the analog pin A0 of the Arduino. this variable resistor will be used to control the light intensity of the ac bulb. While the other two legs of the variable resistor are connected with the Arduino’s 5v and ground.

MOC3021 light dimmer Programming:

For the step-by-step program explanation, watch the video Tutorial given at the end.

MOC3021 light dimmer Watch full Video Tutorial:

Recommended For You

About the Author: Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...


  1. its agreat project! but the point is i want to use this system in an adjustable firing control circuit in a thyrister! can you guide me through to the code and the ckt? please!

  2. it appears that zero crossing pin is not defined in viod setup section , how should i define in setup zero crossing as a output or INPUT.

Leave a Reply

%d bloggers like this: