
Basic schematic.
Arduino Hardware Interrupts Control AC Power
Tweet
The purpose of this project is to demonstrate the use of a hardware interrupt to control AC power levels to a load such as a lamp or small AC motor. Note the "power on" switch must be pushed for the circuit to operate.

Full wave pulsating DC.
In the main circuit diagram above transformer T1, D1, and D3 produce a positive going pulsating DC with a peak voltage of about 18 volts and a frequency of 120 Hertz. Diode D2 blocks the filtering effect of capacitor C2, which with U2 supplies positive five volts for the microcontroller. See Basic AC Rectification and Filtering

Zero crossing pulse from 4N25 in relation to AC sine wave.
The 4N25 opto-coupler provides a narrow 120 Hertz pulse at zero and 180 degrees of the sine wave. This pulse is fed to digital pin 2 (Dp2) of the controller to trigger an interrupt when the sine wave passes zero and 180 degrees. (There's 360 degrees in a sine wave.) See 4N25 Opto-Coupler (PDF file)

This illustrates to process with full-wave unfiltered D.C. but the process is identical with A.C.
By programming a delay of between .1 and 8.2 milliseconds (.1 and 9.9 on 50Hz systems) based on the voltage value on pin AD0 we control the firing point of a triac, transistor, or silicon controlled rectifier to control power output.
For this experiment one can use 24 volts A.C. and a 24 volt lamp. If the circuit is wired properly when the
control is adjusted the circuit should act as a lamp dimmer or speed control for a motor.
If the lamp dims as the control is adjusted clock-wise reverse the two outer connections on R3.
- 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

Sample circuit for photocell or thermistor
connection to ADC (analog to digital converter) sensor pin.
Uses
LM334 CCS Circuits with Thermistors, Photocells YouTube
LM334 CCS Circuits with Thermistors, Photocells
A circuit such as this can do far more than a $3 lamp dimmer. By connecting a thermistor to measure temperature (or an appropriate thermocouple circuit) to one of the analog inputs we have a proportional heat controller saving energy costs. We could control a heating element or the speed of a blower fan proportional to temperature.
By connecting a photocell we could control light intensity of lamps in proportion to natural light, saving energy costs with say sky lights. I use a version of this on my water heater to control a narrow temperature range.
In a proportional controller for heat as an example as the desired temperature is reached, power input is reduced automatically (delaying the firing point on the triac) and enough energy is added to maintain temperature. In a cheap mechanical thermostat power is all on or all off producing overshoot and undershoot. This is unacceptable in many industrial applications.
For an application of this circuit see Hatching Chicken Eggs with Arduino
See Controlling Low-Voltage Driveway Lights with the ATMEGA168/Arduino In that circuit we use a CdS photocell instead of a thermistor, but the circuit is identical.
/* 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 int routine // delay() will not work! void acon() { // 10K potentiometer connected to AN0 delayMicroseconds((analogRead(0) * 7) + 200); // read AD0 // change 7 to 9 if 50Hz. digitalWrite(triacPulse, HIGH); delayMicroseconds(200); // delay 200 uSec on output pulse to turn on triac digitalWrite(triacPulse, LOW); }
- Arduino Projects Revisited Revised
- Schematic for Following Projects
- 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
- Testing the Keyes IR Sensor Module with Arduino
- Arduino with Serially Interfaced MAX7219 Operates 8X8 LED Matrix
- Arduino RTC Clock with MAX7219 8-Digit LED Display
- BCD Conversion with Arduino Displayed on MAX7219
- Connecting the ATMEGA168/Arduino to MCP23016 and LCD Display
- Display Time-Date with Arduino, LCD Display, and DS1307 RTC
- Controlling Low-Voltage Driveway Lights with the Arduino
- Hatching Chicken Eggs with ATMEGA168/Arduino
- TSL230R Light to Frequency Converter and Arduino
- Interfacing Arduino to the MCP23016 I/O Expander
- Arduino with a DS1307 Real Time Clock
- Using a Unipolar Stepper Motor with a Arduino
- Arduino with the TA8050 Motor Controller
- Arduino with a 24LC08 Serial EEPROM
- Hardware Interrupts Demo and Tutorial for Arduino
- Micro-controller AC Power Control Using Interrupts