
In Depth Look at AC Power Control with Arduino
Tweet
Watch the related YouTube Video
In the above video and the code below we take an in depth look at the hardware for using Arduino interrupts to control AC power through a triac. Using a zero-crossing detector Arduino will detect the pulse then calculate a delay to control the power output to a load. The complete circuit schematic.
- For related material see:
- Hardware Interrupts Demo and Tutorial for ATMEGA168/Arduino
- Basic Triacs and SCRs
- Solid State AC Relays with Triacs
For more on basic AC voltage see my video Basic Electronic Power Supplies

Fig. 2
Fig. 2 shows the 5-volt power supply for Arduino but includes blocking diode D2. On the cathode side we have filtered DC which is regulated to 5-volts through U2. On the Anode side we have unfiltered raw 120 Hz DC going to the LED in the 4N25 opto-coupler. The output from the photo-transistor collector goes to digital pin 2 of Arduino to interrupt 0. Potentiometer R3 goes analog pin 0 and is used to calculate the time delay for the half-cycle triac firing pulses.
The figure above shows the relationship of the zero-crossing pulse with the AC sine wave. By detecting the pulse and programming a delay one can control the power output level to a AC load.

Fig. 3
Fig 3 shows the triac firing circuit. The MOC3011 opto-coupler uses a photo triac as opposed to a transistor. Pulses synchronized to the AC sinewave half-cycle are output from Arduino digital pin 5 to the LED in the MOC3011, which also serves to isolate the high voltage AC from the low-voltage components.
Pressing the power switch will enable trigger pulses to the MOC3011 while the LED on digital pin 12 is a power on indicator. C1 and R6 form a snubber circuit for inductive loads. Without a snubber switching noise from inductive loads will cause miss-firing of the triac.
Note that on 60Hz power lines a half cycle is 8.35mSec. while a 50Hz system is 10mSec. Adjust the half-cycle time-delay for 50Hz.
/* Purpose: to detect zero crossing pulse at INT0 digital pin 2, which after delay switches on a triac. Power output to triac activated by external switch. */ #define triacPulse 5 #define SW 4 #define aconLed 12 int val; void setup() { pinMode(2, INPUT); digitalWrite(2, HIGH); // pull up pinMode(triacPulse, OUTPUT); pinMode(SW, INPUT); digitalWrite(SW, HIGH); pinMode(aconLed, OUTPUT); digitalWrite(aconLed, LOW); } void loop() { // check for SW closed if (!digitalRead(SW)) { // enable power attachInterrupt(0, acon, FALLING); // HV indicator on digitalWrite(aconLed, HIGH); } // end if else if (digitalRead(SW)) { detachInterrupt(0); // disable power // HV indicator off digitalWrite(aconLed, LOW); } // else } // end loop // begin AC interrupt routine // delay() will not work! void acon() { delayMicroseconds((analogRead(0) * 6) + 1000); // read AD1 digitalWrite(triacPulse, HIGH); delayMicroseconds(200); // delay 200 uSec on output pulse to turn on triac digitalWrite(triacPulse, LOW); }
- Hardware Interrupts Tutorial for Arduino
- Basic Triacs and SCRs
- Solid State AC Relays with Triacs
- Light Activated Silicon Controlled Rectifier (LASCR)
- Arduino AC Power Control Using Interrupts
- In Depth Look at AC Power Control with Arduino
For earlier Arduino Projects see Arduino Projects Hobby Projects Tutorials
- Arduino Stepper Motor Coil Winder
- Arduino Projects Revisited Revised
- Schematic for Following Projects PDF
- Programming ADS1115 4-Channel I2C ADC with Arduino
- Arduino uses ADS1115 with TMP37 to Measure Temperature
- Connect Arduino to I2C Liquid Crystal Display
- Arduino Reads Temperature Sensor Displays Temperature on LCD Display
- Arduino with MCP4725 12-bit Digital-to-Analog Converter Demo
- Videos
- Arduino with ADS1115 4-Channel 16-bit Analog-to-Digital Converter
- Arduino with MCP4725 12-Bit DAC
- Connect-Program Arduino and a MM5451 LED Display Driver
- Arduino and a MM5451 LED Display Driver YouTube
- Programming Arduino and the 74HC595 Serial Shift Register
- Programming Arduino and the 74HC595 Serial Shift Register YouTube
- Arduino Analog to Digital Conversion Voltmeter
- Arduino ADC Voltmeter YouTube video
- Arduino Pulse-Width Modulation Digital to Analog Conversion
- Arduino PWM to ADC YouTube video
- Zero-Crossing Detectors Circuits and Applications
- Zero-Crossing Detectors YouTube video
- Comparator Theory Circuits Tutorial
- Analog Solar Panel Battery Charge Controller
- Better Arduino Rotary Encoder Sensor
- Simple 3-Wire MAX6675 Thermocouple ADC Arduino Interface
See How I got into Electronics
- Comparator Theory Circuits Tutorial
- Constant Current Circuits with the LM334
- LM334 CCS Circuits with Thermistors, Photocells
- LM317 Constant Current Source Circuits
- TA8050P H-Bridge Motor Control
- All NPN Transistor H-Bridge Motor Control
- Basic Triacs and SCRs
- Constant Current Circuits with the LM334
- LM334 Constant Current Source with Resistive Sensors
- LM317 Constant Current Source Circuits
- Introduction Hall Effect Switches, Sensors, and Circuits
- Using Ratiometric Hall Effect Sensors
- Pulse Width Modulation Power Control for Microcontrollers
- Introduction to PIC12F683 Programming
- Basic Transistor Driver Circuits for Micro-Controllers
- Opto-Isolated Transistor Drivers for Micro-Controllers
- Added Nov. 16, 2014
- ULN2003A Darlington Transistor Array with Circuit Examples
- Tutorial Using TIP120 and TIP125 Power Darlington Transistors
- Driving 2N3055-MJ2955 Power Transistors with Darlington Transistors
- Understanding Bipolar Transistor Switches
- N-Channel Power MOSFET Switching Tutorial
- P-Channel Power MOSFET Switch Tutorial
- H-Bridge Motor Control with Power MOSFETS
- More Power MOSFET H-Bridge Circuit Examples
- Build a High Power Transistor H-Bridge Motor Control