Arduino Projects

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

Engr Fahad Send an email May 30, 2019
14,878

## Description:

“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

DISCLAIMER:

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.

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 programming..pin 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…

this is the BTA16 triac lets have a look at its datasheet..as 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.

    int zeroc = 2 ;
    int  triac = 3 ;
    int vresistor = A0; // variable resistor
    int brightness;
    int vrpower = 7;

    void setup()
    {
      Serial.begin(9600);
    pinMode(triac, OUTPUT);
    pinMode(vresistor, INPUT);
    pinMode(vrpower, OUTPUT);
    digitalWrite(vrpower, HIGH);
    attachInterrupt(0, angle, RISING);
    }

    void loop(){}

    void angle(){
      brightness = analogRead(vresistor);
      brightness = map(brightness,0,1023,0,10000);
      Serial.println(brightness);
      delayMicroseconds(brightness);
      digitalWrite(triac, HIGH);
      delayMicroseconds(50);
      digitalWrite(triac, LOW);
    }

### Watch full Video Tutorial:

Tags
220v ac bulb dimming ac light dimmer using arduino and moc3021 Arduino arduino ac bulb dimming arduino code arduino developer arduino internet Arduino programming arduino project arduino projects arduino triac Arduino uno arduino uno programming arduino uno projects arduino zero crossing detector basic arduino projects bta16 easy arduino projects easy Arduino uno programming el817 el817 arduino elec electr electronic clinic electronics electronics projects moc3021 arduino moc3021 with arduino simple arduino projects www.electroniclinic.com
Engr Fahad Send an email May 30, 2019
14,874
Share
Facebook Twitter LinkedIn Pinterest Reddit Skype Messenger Messenger WhatsApp Line Share via Email Print

### 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...

- Website
- Facebook
- LinkedIn
- YouTube

### 3 Comments

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!

   Reply

2. it doesn’t appear that zero crossing pin #2 is defined in the void setup — pinMode(zeroc, OUTPUT); ?????

   Reply

3. 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.

   Reply

### Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Comment *

Name *

Email *

Website

Save my name, email, and website in this browser for the next time I comment.

Δ

Facebook Twitter WhatsApp Line
Back to top button
Close
Search for:

- Facebook
- Twitter
- YouTube
- Instagram

Close